【问题标题】:Spring Integration With JMS Not Working ProperlySpring 与 JMS 的集成无法正常工作
【发布时间】:2019-01-04 12:25:36
【问题描述】:

您好,我正在尝试使用 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 响应:5000 毫秒 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]

谁能告诉我我做错了什么,

【问题讨论】:

  • @Gimby 感谢您的指点,不用担心 url,我只是把它当作 dummy 放在那里,我得到的错误不是 http
  • 如果 HTTP 调用已完成,但该 HTTP 调用未完成但超时时间比您的 JMS 消息处理程序长,那么您会遇到此问题。
  • @Gimby 我也尝试过不使用 http 部分,这与我遇到的错误相同

标签: java spring-boot spring-integration spring-integration-dsl


【解决方案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()

【讨论】:

  • 感谢您的帮助。它解决了这个问题。在形成您自己的答案之前,我已阅读此信息并错过了它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-29
  • 2017-04-29
  • 1970-01-01
  • 2012-06-14
  • 1970-01-01
相关资源
最近更新 更多