【发布时间】:2014-06-29 00:16:44
【问题描述】:
我正在为我正在处理的一些代码抽象出任何类型的消息传递框架。基本上,我使用 Spring AOP 和 Spring Integration 的组合来生成消息,而 Java 代码并不了解 RabbitMQ、JMS 甚至 Spring Integration。也就是说,我用来生成消息的内容包含在它自己的 .jar 中,并且它被应用程序的其他几个区域重复使用。我目前设置了消息传递系统,通过在消息头中指定通道名称和如果通道不存在,则使用标头值路由器创建通道。我的问题出现在这些通道的端点上——当前结构的目的是允许 Spring 在需求指定或更改时更改为任何消息传递结构。我知道如何获取静态通道并使用出站通道转换器/网关将其发送到预先指定的 RabbitMQ/JMS 队列并从那里处理;我正在努力解决的是如何告诉 Spring 我需要路由器创建的 每个 通道来拥有一个基于通道动态生成的 RabbitMQ(或任何其他消息系统实现)出站通道适配器名称,因为我们事先不知道频道名称。
这可能吗?如果没有,您是否介意提供意见,说明什么可能是更好的方法?
提前谢谢!
这是我的配置文件的基本模板 - 我有一个初始通道(“messageChannel”),它根据消息头之一发送到发布-订阅通道和排队通道,并从那里路由.
<!--Header value based channel configurations-->
<int:channel id="messageChannel" />
<int:channel id="queue" />
<int:publish-subscribe-channel id="topic" />
<!--Header-based router to route to queue or topic channels-->
<int:header-value-router input-channel="messageChannel"
header-name="#{ T(some.class.with.StringConstants).CHANNEL_TYPE}" />
<!--Re-routes messages according to their destination and messaging type-->
<int:header-value-router input-channel="queue"
header-name="#{ T(some.class.with.StringConstants).MESSAGE_DESTINATION}" />
<int:header-value-router input-channel="topic"
header-name="#{ T(some.class.with.StringConstants).MESSAGE_DESTINATION}" />
<!--AOP configuration - picks up on any invocation of some.class.which.generates.Messages.generateMessage()
from a Spring-managed context.-->
<aop:config>
<aop:pointcut id="eventPointcut"
expression="execution(* some.class.which.generates.Messages.generateMessage(..))" />
<aop:advisor advice-ref="interceptor" pointcut-ref="eventPointcut"/>
</aop:config>
<int:publishing-interceptor id="interceptor" default-channel="messageChannel">
<int:method pattern="generateMessage" payload="#return" channel="messageChannel" />
</int:publishing-interceptor>
【问题讨论】:
标签: jms rabbitmq router spring-integration spring-aop