我有一个使用 xml 配置的工作 spring 集成 + rabbitmq 应用程序。现在,我将它们转换为 java 配置注释。一些主要的 amqp 对象有可用的类和 java 注释,例如 Queue
、TopicExchange
和 Binding
。但是,我找不到将 inbound-gateway
和 outbound-gateway
转换为 java 注释或类实现的任何引用。
这是我的实现: //网关.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
。
最佳答案
如果你看看 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;
}
关于java - 入站和出站网关 AMQP 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24673960/