Spring 集成 - 配置 DefaultMessageListenerContainer 来解析多个目的地
我需要配置 DefaultMessageListenerContainer 来解析多个目标主题。我不想实例化多个容器,我想知道如何配置它,或者即使它是可能的。
谢谢
I have a requirement to configure a DefaultMessageListenerContainer to resolve multiple destination topics. I don't want to instanciate multiple containers and I was wondering how to configure this or even if it is possible.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望使用直接 Spring JMS 侦听来自多个主题的消息,则需要创建此类的多个实例。唯一的问题是,默认情况下每个任务都会创建自己的 TaskExecutor,这有点浪费。要解决这个问题,只需在上下文中定义您自己的
taskExecutor
bean,所有消息侦听器都会自动使用它。这是一个在独立虚拟机中运行良好的任务执行器,还有与不同容器的本机工作管理器/线程池功能集成的替代实现。
或者,使用 Spring Integration,只需创建一个消息通道和多个
- 每个主题一个。下面是一个示例片段:在幕后,Spring Integration 将自动创建一个 MessageListenerContainer。
另一种替代方法是使用 JMS 提供者/MOM 的路由工具来创建路由所有相关消息的单一目标。例如,在 RabbitMQ 中,您可以创建一个绑定到多个交换的主题,因此只有一个 AMQP 目的地可供使用。然而,这是依赖于基础设施的,并且对于任何给定的 JMS 提供者来说都是不可能的。
If you wish to listen for messages from multiple topics using straight Spring JMS, you will need to create multiple instances of this class. The only issue is that by default each will creates its own TaskExecutor, which is a little bit wasteful. To get around this simply define your own
taskExecutor
bean in the context and all the message listeners will automatically use it.Here is a task executor which works well in a standalone VM, there are alternative implementations which integrate with different containers' native work manager / thread pool capabilities.
Alternatively, using Spring Integration, simply create a message channel and multiple
<jms:message-driven-channel-adapter/>
's - one for each topic. Here is a sample snippet:Behind the scenes, Spring Integration will automatically create a MessageListenerContainer.
Yet another alternative would be to use the routing facilities of your JMS provider/MOM to create a single destination where all relevant messages are routed. E.g. in RabbitMQ you can create a topic which is bound to multiple exchanges, and thus only one AMQP destination to consume. This is infrastructure dependent however, and will not be possible with any given JMS provider.