0
votes

I am working on the integration flow between two RabbitMQ message brokers.

My IntegrationFlow code is:

   @Bean
    public IntegrationFlow messageFlow() {
        return IntegrationFlows.from(stompInboundChannelAdapter())
                .transform(inBoundStompMsgTransformer::transform)
                .headerFilter("stomp_subscription","content-length")
                .handle(Amqp.outboundAdapter(outboundConfiguration.rabbitTemplate()))
                .log()
                .get();
    }

Inbound Adapter code is:

   @Bean
    public MessageChannel stompInputChannel() {
        return new DirectChannel();
    }

    @Bean
    public StompInboundChannelAdapter stompInboundChannelAdapter() {
        StompInboundChannelAdapter adapter = new StompInboundChannelAdapter(stompSessionManager(), "/queue/myQueue");
        adapter.setOutputChannel(stompInputChannel());
        adapter.setPayloadType(ByteString.class);
        return adapter;
    }

I am getting messages. The messages are getting transformed. However, the transformed messages are not reaching the other RabbitMQ

The rabbitTemplate code is:

  @Bean
    Binding binding(Queue queue, DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(routingkey);
    }

    @Bean
    public ConnectionFactory connectionFactory() {
        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(host);
        cachingConnectionFactory.setUsername(username);
        cachingConnectionFactory.setUsername(password);
        return cachingConnectionFactory;
    }

    @Bean
    public AmqpTemplate rabbitTemplate() {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());
        rabbitTemplate.setExchange(exchange);
        rabbitTemplate.setRoutingKey(routingkey);
        return rabbitTemplate;
    }

What is wrong with my IntegrationFlow?

Thanks,

Mahesh

Your code looks like it should work (although you can't use .log after an outbound adapter - there's no reply message); try setting a breakpoint in template.doSend() and check that the exchange and routing key are correct; also check the binding is correct on the admin UI. If you can't figure it out, post your project someplace and I'll take a look.Gary Russell
Do you have a RabbitAdmin bean? Or do you use Spring Boot? Is able to try an ExpressingEvaluatingRequestHandlerAdvice on the outbound AMQP endpoint to be sure what exception you get: docs.spring.io/spring-integration/docs/5.2.2.RELEASE/reference/…?Artem Bilan
@GaryRussell Thanks a lot. Deleted the queue, recreated it with proper binding and it worked.Mahesh
This is my first POC. I would like to build on top it. Is it the ok to start integration flow from an inbound adapter? Most of the examples that i see on internet starts from a channel. Any suggestions or pointers to move in the right direction?Mahesh
Not sure why you have such a question since there is a factory to start the flow from inbound channel adapter. So, even if you haven’t seen samples in the Internet, it doesn’t mean that your solution is wrong.Artem Bilan