edwin
edwin

Reputation: 8081

Spring Integration With JMS Not Working Properly

Hi I was trying to build a Spring boot application , with spring integration

Application 1 : Publisher

Jms Message -> Broker ->queue1

Application 2: Subscriber & Publisher

Broker->queue1->Transform->HTTP CALL->HTTP Response->JMS Message->Broker->queue2

Publisher Flow

@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);
}

Subscriber & Publisher Flow

@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();
        }

}

When i run the application, I'm getting error

Caused by: org.springframework.integration.MessageTimeoutException: failed to receive JMS response within timeout of: 5000ms at org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:762) ~[spring-integration-jms-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109) ~[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:158) ~[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]

Can someone tell me what I'm doing wrong,

Upvotes: 1

Views: 815

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

Your problem that your consumer is not a request-reply. You receive message from the amq.outbound1 and send to the amq.outbound2. That's all: nothing more happens. You have there a one-way flow.

At the same time your producer is a request-reply - handle(Jms.outboundGateway(connectionFactory). That Outbound Gateway really expects a reply in the ReplyTo header according default options for JMS request-reply scenarios.

So, you have to determine for yourself: or you need send reply back to the producer or you just need send-and-forget from that producer. See Jms.outboundAdapter() if that.

In case of request-reply you don't need a Jms.outboundAdapter() on the consumer side: you must use a Jms.inboundGateway() instead of the Jms.messageDrivenChannelAdapter().

Upvotes: 1

Related Questions