如何对 Spring JMS 监听器进行线程池
我正在设置一个 JMS 订阅者侦听器,目标是实现一个由 5 个线程组成的池来侦听 topATopic,但是,我在运行时看到的是多个消费者处理同一条记录 (recordCount*#of Consumers)。
考虑到我是春天的新手,我假设我做错了什么。
<bean id="messageListener" class="com.abc.app.mdp.Receiver">
<property name="bean" ref="bean" />
</bean>
<jms:listener-container container-type="default"
connection-factory="connectionFactory" acknowledge="auto" concurrency="5" destination-type="topic" prefetch="1" cache="none" >
<jms:listener destination="topCli_Service" ref="messageListener"
method="onMessage" subscription="AProjectSubscriber" />
</jms:listener-container>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryB ean">
<property name="jndiName" value="jms/jms-top-notx" />
</bean>
有人可以指出我实现目标的方向吗?
I am setting up a JMS subscriber listener as follows with the goal of achieving a pool of 5 threads listening to topATopic, however, what I see at runtime is multiple consumers processing the same record (recordCount*#of consumers).
I am assuming I am doing something wrong considering I am new to spring.
<bean id="messageListener" class="com.abc.app.mdp.Receiver">
<property name="bean" ref="bean" />
</bean>
<jms:listener-container container-type="default"
connection-factory="connectionFactory" acknowledge="auto" concurrency="5" destination-type="topic" prefetch="1" cache="none" >
<jms:listener destination="topCli_Service" ref="messageListener"
method="onMessage" subscription="AProjectSubscriber" />
</jms:listener-container>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryB ean">
<property name="jndiName" value="jms/jms-top-notx" />
</bean>
Can somebody please point me in a direction to achieve my goal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看侦听器容器配置上的并发设置。 Spring JMS 文档 建议将并发设置为1 为主题听众。见下文。
这篇文章 与您问题的其余部分类似。
如果您需要多个线程来跟上消息量,您的消息侦听器可以委托给 Spring TaskExecutor 异步处理消息。 TaskExecutors 可以由包括线程池在内的许多实现支持。
Take a look at the concurrency setting on your listener container configuration. The Spring JMS doc suggests that concurrency should be set to 1 for topic listeners. See below.
This post is similar to the rest of your question.
If you need multiple threads to keep up with message volume, your message listener could delegate to a Spring TaskExecutor to process the messages asynchronously. TaskExecutors can be backed by a number of implementations including Thread Pool.
如果您希望给定的消息仅由一个消费者使用,则应该使用队列而不是主题。主题消息被广播给所有可用的消费者。
If you want a given message to be consumed by one and only one consumer, you should use a Queue instead of a Topic. A Topic message is broadcast to all available consumers.