我必须从生产者向 RabbitMQ Exchange 发送消息。此消息将包含特定属性,例如队列名称,基于此属性,我必须动态决定发送此消息的队列。[从交换绑定的队列,发送此特定消息]。
有什么方法可以拦截到达 RabbitMQ Exchange 的消息,使用 spring 集成,目前,我有以下 spring 集成配置文件。
我不知道如何创建一个 bean 来获取 Exchange 消息并将消息路由到 smsQueue、emailQueue 等队列。
感谢您的建议和回复。
http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit- 1.0.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration/amqp
http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.rabbit"></context:component-scan>
<rabbit:connection-factory id="connectionFactory"
host="localhost" username="guest" password="guest" />
<rabbit:admin connection-factory="connectionFactory" />
<rabbit:template id="exchnageTemplate"
connection-factory="connectionFactory" exchange="COMMUNICATION-EXCHANGE" />
<rabbit:queue id="smsQueue" auto-delete="true" durable="false" />
<rabbit:queue id="emailQueue" auto-delete="true" durable="false" />
<rabbit:queue id="dvbQueue" auto-delete="true" durable="false" />
<rabbit:queue id="pbxQueue" auto-delete="true" durable="false" />
<rabbit:queue id="medsensorQueue" auto-delete="true"
durable="false" />
<int:gateway id="gateway" service-interface="com.rabbit.mq.ProducerGatewayInterface"
default-request-channel="producerChannel" />
<int:channel id="producerChannel" />
<int:channel id="errorChannel" />
<bean id="communicationInterface" class="com.rabbit.mq.CommunicationInterface" />
<amqp:outbound-channel-adapter channel="producerChannel"
amqp-template="exchnageTemplate" exchange-name="COMMUNICATION-EXCHANGE">
<int:service-activator input-channel="input"
ref="communicationInterface" method="optimalRoutingOfMessage" />
</amqp:outbound-channel-adapter>