0

any example reference of RabbitMQ Outbound Gateway to post messages to rabbitmq cluster, I am looking for Java configuration with Spring Boot

  • Wait, if you new here on StackOverflow, that doesn't mean you should skip reading Docs. This is already not your first question where the answer is really fall into the Reference Manual with the clear sample. Please, be careful in the future since we indeed have some work to do, plus it is not good to ask for the Docs on SO and, of course, it is not good to answer for the docs links here as well. – Artem Bilan Aug 27 '18 at 21:12

1 Answers1

1

See the reference manual. There are xml, Java and Java DSL examples there.

@Bean
@ServiceActivator(inputChannel = "amqpOutboundChannel")
public AmqpOutboundEndpoint amqpOutbound(AmqpTemplate amqpTemplate) {
    AmqpOutboundEndpoint outbound = new AmqpOutboundEndpoint(amqpTemplate);
    outbound.setExpectReply(true);
    outbound.setRoutingKey("foo"); // default exchange - route to queue 'foo'
    return outbound;
}

or

@Bean
public IntegrationFlow amqpOutbound(AmqpTemplate amqpTemplate) {
    return IntegrationFlows.from(amqpOutboundChannel())
            .handle(Amqp.outboundGateway(amqpTemplate)
                    .routingKey("foo")) // default exchange - route to queue 'foo'
            .get();
}

Gateways are for request/reply processing not just "post" ing; you need a channel adapter if you are just sending.

@Bean
@ServiceActivator(inputChannel = "amqpOutboundChannel")
public AmqpOutboundEndpoint amqpOutbound(AmqpTemplate amqpTemplate) {
    AmqpOutboundEndpoint outbound = new AmqpOutboundEndpoint(amqpTemplate);
    outbound.setRoutingKey("foo"); // default exchange - route to queue 'foo'
    return outbound;
}

or

@Bean
public IntegrationFlow amqpOutbound(AmqpTemplate amqpTemplate) {
    return IntegrationFlows.from(amqpOutboundChannel())
            .handle(Amqp.outboundAdapter(amqpTemplate)
                        .routingKey("foo")) // default exchange - route to queue 'foo'
            .get();
}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179