Spring boot 如何将响应发送回网关接口?
我当前收到此错误:Spring boot 如何将响应发送回网关接口?,spring-boot,spring-integration,spring-integration-dsl,Spring Boot,Spring Integration,Spring Integration Dsl,我当前收到此错误: DestinationResolutionException: no output-channel or replyChannel header available . 我有一个注入控制器的文件网关 @MessagingGateway public interface FileGateway { @Gateway(requestChannel = "router.input", replyChannel = "output") FileRe
DestinationResolutionException:
no output-channel or replyChannel header available .
我有一个注入控制器的文件网关
@MessagingGateway
public interface FileGateway {
@Gateway(requestChannel = "router.input", replyChannel = "output")
FileRequestResponse requestFile(FileRequestRequest fileFetchRequest);
}
以及将消息发送到各个信道的路由器
@Bean
IntegrationFlow routeFileRequest() {
return IntegrationFlows.from("router.input")
.<FileRequestRequest, FileType>route(m -> m.getParameters().getFileType(), m -> m
.channelMapping(FileType.CONTRACT, "contract.transform")
.channelMapping(FileType.INVOICE, "invoice.tranform"))
// .channelMapping(FileType.USAGE, "usageChannel"))
.get();
}
变压器:
@Transformer(inputChannel = "contract.transform", outputChannel = "contract.input")
public Message<String> transformContractMessage(Message<FileRequestRequest> request) {
/**
*
* @param request
* @return contractId
*/
FileRequestRequest frr = request.getPayload();
return MessageBuilder.
withPayload(request.
getPayload().getContractId()).
setHeader("fileType", "CONTRACT").build();
}
变压器(inputChannel=“contract.transform”,outputChannel=“contract.input”)
公共消息(消息请求){
/**
*
*@param请求
*@返回收缩
*/
FileRequestFRR=request.getPayload();
返回MessageBuilder。
withPayload(请求)。
getPayload().GetCompactId()。
setHeader(“文件类型”、“合同”).build();
}
下面是将消息发送回router.output的服务激活器,但是我遇到了上面的异常
@ServiceActivator(inputChannel = "contract.input" ,outputChannel = "output")
public FileRequestResponse res(Message<String> message){
log.info(" Retrieving File With Contract ID {} ",message.getPayload());
ContractRsp contractResponse = contractFetchService.retrieveContract(message.getPayload());
log.info(" Contract File Received {} ",contractResponse);
return FileRequestResponse.builder().build();
}
@Bean
public DirectChannel output(){
DirectChannel channel = new DirectChannel();
return channel;
}
@ServiceActivator(inputChannel=“contract.input”,outputChannel=“output”)
公共文件请求响应资源(消息){
info(“正在检索合同ID为{}的文件,message.getPayload());
ContractRsp contractResponse=contractFetchService.retrieveContract(message.getPayload());
log.info(“收到的合同文件{}”,contractResponse);
返回FileRequestResponse.builder().build();
}
@豆子
公共DirectChannel输出(){
DirectChannel=新的DirectChannel();
返回通道;
}
我的目标是在响应后将消息返回到FileGateway接口。网关是一个请求-应答组件,在将消息发送到
请求通道
的过程中,会填充带有临时应答通道
的replyChannel
头,以实现它们之间的关联
这一点在报告中有明确的解释
因此,即使您提供了replyChannel=“output”
并在下游某处使用它,也必须在头中保留replyChannel
您的问题代码在@变压器中:
return MessageBuilder.
withPayload(request.
getPayload().getContractId()).
setHeader("fileType", "CONTRACT").build();
您构建了一条新消息,并且不复制请求头来curry该replyChannel
与许多其他组件(例如@ServiceActivator
)不同,如果转换函数返回消息
实例,则转换器不会将头复制到回复消息中
这样,您需要考虑在上面添加代码:<代码> CopyHealthsServer(请求.GeTeAdServer)(
),您需要从该转换器方法返回一个<代码>有效载荷< />代码或消息,但是复制的请求标头。
return MessageBuilder.
withPayload(request.
getPayload().getContractId()).
setHeader("fileType", "CONTRACT").build();