Spring主题订阅者线程池

发布于 2024-11-05 03:07:30 字数 1471 浏览 3 评论 0原文

这几天我一直在浏览论坛和网站,了解如何对 Spring JMS 订阅者进行线程池,但运气不佳。然而,当使用带有 jms:listener-container 的队列时,有一个并发属性,它声明将并发性保持在 1 的主题。鉴于此,我对主题订阅者进行线程池化的选项有哪些?

我从 MessageListener 路由开始,使用 onMessage 实现:

    <bean id="messageListener" class="com.app.mdp.Receiver"/>
    <jms:listener-container container-type="default"
        connection-factory="connectionFactory" acknowledge="auto" concurrency="1"
        destination-type="topic" prefetch="1">
        <jms:listener destination="topTopic" ref="messageListener"
            method="onMessage" subscription="ASub" />
    </jms:listener-container>

    <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jms/jms-top-notx" />
    </bean>

问题是我一次最多有一个线程从 JMS 接收数据。

然后我尝试使用带有 config:

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
  <property name="corePoolSize" value="10" />
  <property name="maxPoolSize" value="20" />
  <property name="queueCapacity" value="0" />
</bean> 

.. 的任务执行器,但它似乎要求并发性在 jms:listener-container 设置中具有更大的价值(除非我误解)。但我一次只收到一条线索。

我有点茫然,开始认为spring在订阅JMS主题数据时没有支持多线程的功能。如果是这种情况,我的选择似乎是:

  • 实现我自己的线程池。安排订阅者->循环通过jmsTmplate.receive()数据->将每条消息传递到预定义线程
  • 恢复到EJB(我不想做)
  • 我还没有想到的其他事情

任何帮助都会很大赞赏。

I have been skimming forums and websites for a few days now about how to thread-pool a spring JMS subscriber with very little luck. When using a queue with the jms:listener-container there is a concurrency property, however, with a topic it states to keep concurrency at 1. Given that, what are my options for thread-pooling a topic subscriber?

I started out with the MessageListener route with the implementation of onMessage with:

    <bean id="messageListener" class="com.app.mdp.Receiver"/>
    <jms:listener-container container-type="default"
        connection-factory="connectionFactory" acknowledge="auto" concurrency="1"
        destination-type="topic" prefetch="1">
        <jms:listener destination="topTopic" ref="messageListener"
            method="onMessage" subscription="ASub" />
    </jms:listener-container>

    <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jms/jms-top-notx" />
    </bean>

The problem with this is I get at most one thread receiving data from JMS at a time.

I then attempted to use a task executor with config:

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
  <property name="corePoolSize" value="10" />
  <property name="maxPoolSize" value="20" />
  <property name="queueCapacity" value="0" />
</bean> 

..but it seems to require concurrency to be of a greater value in the jms:listener-container setup (unless I am misunderstanding). Still I only received one thread at a time.

I am at a bit of a loss and starting to think that spring does not have functionality to support multiple threads when subscribing to JMS topic data. If that is the case my options seem to be:

  • implement my own thread pool. schedule subscriber->loop through jmsTmplate.receive() data->pass each message to a predefined thread
  • revert back to EJBs (which I don't want to do)
  • something else I have yet to think of

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无风消散 2024-11-12 03:07:30

您是否使用 Websphere 作为 JMS 。如果是,那么 Websphere 中有一个配置,您可以在其中配置一次可以为应用程序建立的连接和会话的数量。
假设如果您有 10 个会话和 10 个连接,那么您将有 100 个连接(通道)打开到 MQ 服务器。参考这个链接:
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/umj_sesspoolset.html

Are you using Websphere for the JMS . If yes then there is a configuration in Websphere where you can configure the number of connection and session's you can make for the application at a time .
Suppose if you have 10 sessions and 10 connections then you will have 100 connection(channels)open to MQ server . refer this link :
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/umj_sesspoolset.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文