【发布时间】:2020-07-27 10:16:41
【问题描述】:
我想使用 Spring Integration 公开一个简单的 Web 服务,将传入消息推送到 ActiveMQ 并立即响应。我的首选解决方案是使用 IntegrationFlow 连接到 Jms.outboundAdapter 的 MarshallingWebServiceInboundGateway。在 Gateway 和 IntegrationFlow sn-ps 下方。问题是适配器不提供网关期望的响应(duh)。我从服务返回的响应是空的 202,延迟大约 1500 毫秒。这是由我在 TRACE 日志中看到的回复超时引起的:
"2020-04-14 17:17:50.101 TRACE 26524 --- [nio-8080-exec-6] o.s.integration.core.MessagingTemplate : Failed to receive message from channel 'org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@518ffd27' within timeout: 1000"
任何地方都没有硬异常。另一个问题是我自己无法生成响应。在使用适配器的 .handle 之后,我无法向 IntegrationFlow 添加任何内容。
- 我可以通过其他方式尝试实现该场景吗?
- 如果可能的话,我如何在没有更好方法的情况下生成并返回响应?
最有可能正确的方法是在两端使用网关,但这是不可能的。在队列中的消息被消费和处理之前,我无法等待响应。
'''
@Bean
public MarshallingWebServiceInboundGateway greetingWebServiceInboundGateway() {
MarshallingWebServiceInboundGateway inboundGateway = new MarshallingWebServiceInboundGateway(
jaxb2Marshaller()
);
inboundGateway.setRequestChannelName("greetingAsync.input");
inboundGateway.setLoggingEnabled(true);
return inboundGateway;
}
@Bean
public IntegrationFlow greetingAsync() {
return f -> f
.log(LoggingHandler.Level.INFO)
.handle(Jms.outboundAdapter(this.jmsConnectionFactory)
.configureJmsTemplate(c -> {
c.jmsMessageConverter(new MarshallingMessageConverter(jaxb2Marshaller()));
})
.destination(JmsConfig.HELLO_WORLD_QUEUE));
}
'''
【问题讨论】:
标签: java spring spring-integration spring-jms