嗨,我正在尝试构建具有Spring集成的Spring Boot应用程序
应用程序1:发布者
Jms Message -> Broker ->queue1
应用程序2:订阅者和发布者
Broker->queue1->Transform->HTTP CALL->HTTP Response->JMS Message->Broker->queue2
发布商流
@Configuration
public class EchoFlowOutBound {
@Autowired
private ConnectionFactory connectionFactory;
@Bean
public IntegrationFlow toOutboundQueueFlow() {
return IntegrationFlows.from("requestChannel")
.handle(Jms.outboundGateway(connectionFactory)
.requestDestination("amq.outbound1")).get();
}
}
//Gateway
@MessagingGateway
public interface EchoGateway {
@Gateway(requestChannel = "requestChannel")
String echo(String message);
}
订阅者和发布者流
@Configuration
public class MainOrchestrationFlow {
@Autowired
private ConnectionFactory connectionFactory;
@Autowired
private QueueChannel jmsOutChannel;
@Bean
public IntegrationFlow orchestrationFlow() {
return IntegrationFlows.from(
Jms.messageDrivenChannelAdapter(connectionFactory)
.destination("amq.outbound1")
.outputChannel(jmsOutChannel))
.<String, String>transform(s -> {
return s.toLowerCase();
})
// HTTP part goes here
.<String, HttpEntity>transform(HttpEntity::new)
.handle(
Http.outboundChannelAdapter("http://localhost:8080/uppercase")
.httpMethod(HttpMethod.POST)
.extractPayload(true)
.expectedResponseType(String.class)
)
// and here HTTP part ends
.handle(
Jms.outboundAdapter(connectionFactory)
.destination("amq.outbound2")
)
.get();
}
}
我运行该应用程序时遇到错误
由以下原因引起:org.springframework.integration.MessageTimeoutException: 在以下时间超时内未能收到JMS响应:5000ms org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:762) 〜[spring-integration-jms-5.0.6.RELEASE.jar:5.0.6.RELEASE]在 org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109) 〜[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]在 org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:158) 〜[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]在 org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) 〜[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
有人可以告诉我我做错了吗,
答案 0 :(得分:1)
您的消费者不是request-reply
的问题。您收到来自amq.outbound1
的消息并发送给amq.outbound2
。仅此而已:什么都没有发生。您有one-way
流程。
同时,您的生产者是request-reply
-handle(Jms.outboundGateway(connectionFactory)
。该出站网关确实希望根据JMS请求-答复方案的默认选项在ReplyTo
标头中进行答复。
因此,您必须自己确定:或者您需要将答复发送回生产者,或者只需要该生产者的发送和接收即可。参见Jms.outboundAdapter()
。
在请求答复的情况下,消费者方不需要Jms.outboundAdapter()
:必须使用Jms.inboundGateway()
而不是Jms.messageDrivenChannelAdapter()
。