Single queue: concurrent message processing with multiple consumers

后端 未结 3 1580
庸人自扰
庸人自扰 2021-01-22 01:12

I am new to jms. The goal is to process messages concurrently from a queue in an asynchronous listener\'s onMessage method by attaching a listener instance to multiple consume

相关标签:
3条回答
  • 2021-01-22 01:41
    1. Yes absolutely
    2. I only took a brief look and I noticed that you pass the wrong consumer to your second thread:

      Thread newThread2 = new Thread(consumer1); // has to pass consumer2
      

      beside of this, some variables such as ConnectionFactory are static and initialized multiple times/overriden. You only need one connection that could create multiple sessions and/or consumers.

    0 讨论(0)
  • 2021-01-22 01:43

    Related to the code example you provided, It is not recommanded by Oracle to create low-level threads on a deployed application. Example for Weblogic : Using Threads in WebLogic Server

    0 讨论(0)
  • 2021-01-22 02:01

    Instead in the applicationcontext.xml, where you have made the bean of mail container, you can add concurrent consumer property which would be a better approach.

    <bean id="jmsMailContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="concurrentConsumers">
        <value>100</value>
    </property>
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="destination" ref="mailDestination"/>
    <property name="messageListener" ref="jmsMailConsumer"/>
    

    0 讨论(0)
提交回复
热议问题