入站和出站网关AMQP注释

Orv*_*vyl 6 java amqp spring-integration rabbitmq spring-boot

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

这是我的实现:// 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"/>
Run Code Online (Sandbox Code Playgroud)

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

附加:我目前正在使用spring boot+ spring integration.

Art*_*lan 6

如果你看一下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();
}
Run Code Online (Sandbox Code Playgroud)

从注释角度来看,您应该直接使用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;
}
Run Code Online (Sandbox Code Playgroud)