Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inbound and Outbound Gateway AMQP annotation

I have a working spring integration + rabbitmq application using xml config. Now, i am converting them to java config annotation. There are available classes and java annotation for some main amqp objects like Queue , TopicExchange , and Binding. However, I cant find any reference in converting inbound-gateway and outbound-gateway to java annotation or class implementation.

Here's my implementation: // gateway.xml

<int-amqp:outbound-gateway request-channel="requestChannel" reply-channel="responseChannel" exchange-name="${exchange}" routing-key-expression="${routing}"/>


<int-amqp:inbound-gateway request-channel="inboundRequest"
    queue-names="${queue}" connection-factory="rabbitConnectionFactory"
    reply-channel="inboundResponse" message-converter="compositeMessageConverter"/>

Is it possible to convert them to java annotation or class implementation(bean, etc..)?

ADDITIONAL: I am currently using spring boot + spring integration.

like image 207
Orvyl Avatar asked Jul 10 '14 10:07

Orvyl


1 Answers

Would be great, if you take a look into Spring Integration Java DSL.

It provides some fluent for AMQP:

@Bean
public IntegrationFlow amqpFlow() {
     return IntegrationFlows.from(Amqp.inboundGateway(this.rabbitConnectionFactory, queue()))
           .transform("hello "::concat)
           .transform(String.class, String::toUpperCase)
           .get();
}

@Bean
public IntegrationFlow amqpOutboundFlow() {
       return IntegrationFlows.from(Amqp.channel("amqpOutboundInput", this.rabbitConnectionFactory))
               .handle(Amqp.outboundAdapter(this.amqpTemplate).routingKeyExpression("headers.routingKey"))
               .get();
}

From annotation perspective you should configure something like this using classes from Spring Integration directly:

@Bean
public AmqpInboundGateway amqpInbound() {
    AmqpInboundGateway gateway = new AmqpInboundGateway(new SimpleMessageListenerContainer(this.rabbitConnectionFactory));
    gateway.setRequestChannel(inboundChanne());
    return gateway;
}

@Bean
@ServiceActivator(inputChannel = "amqpOutboundChannel")
public AmqpOutboundEndpoint amqpOutbound() {
    AmqpOutboundEndpoint handler = new AmqpOutboundEndpoint(this.rabbitTemplate);
    handler.setOutputChannel(amqpReplyChannel());
    return handler;
}
like image 61
Artem Bilan Avatar answered Oct 16 '22 18:10

Artem Bilan