入站和出站网关AMQP注释

时间:2014-07-10 10:15:59

标签: java rabbitmq spring-integration amqp spring-boot

我有一个使用xml配置的弹簧集成+ rabbitmq应用程序。现在,我将它们转换为java配置注释。对于某些主要的amqp对象,例如QueueTopicExchangeBinding,有可用的类和java注释。但是,我无法在将inbound-gatewayoutbound-gateway转换为java注释或类实现时找到任何参考。

这是我的实施: // 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"/>

是否可以将它们转换为java注释或类实现(bean等)?

其他:我目前正在使用spring boot + spring integration

1 个答案:

答案 0 :(得分:5)

如果你看一下Spring Integration Java DSL,那就太棒了。

它提供了一些流利的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();
}

从注释的角度来看,你应该直接使用Spring Integration中的类来配置这样的东西:

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