The fastest way to handle JMS messages from Spring-JMS

I have a JMS queue with gazillion messages to process. I will have some listeners that I implement using spring-jms to read from this queue.

I get a little lost in the different ListenerContainers and their possible configurations. My requirements:

  • Obviously, asynchronous processing.
  • There is no need for transactions, I can afford to lose some messages if something fails.
  • I need raw speed!
  • I use ActiveMQ as a broker.

Does anyone have a suggestion in ListenerContainer to use the configuration in terms of the number of JMS sessions, threads, etc.

The machine will have 8 cores, a lot of RAM.

+3
source share
2 answers

If you have no specific reason for this, use DefaultMessageListenerContainer. It is the most flexible in terms of performance and configuration. On the contrary, it SimpleMessageListenerContaineris too simple for practical use.

I can not advise you on the number of concurrent users to configure, as this depends entirely on your configuration.

+4
source

I would consider using Spring Integration . This makes it easy to configure JMS applications.

    <bean id="commandQueue" class="org.apache.activemq.command.ActiveMQQueue">
            <constructor-arg value="queue.command"/>
    </bean>

    <jms:message-driven-channel-adapter
    id="jmsin" destination="commandQueue" channel="commandChannel" />

    <int:channel id="commandChannel" />

So, in the XML snippet above, you create a “pipe”, which is the concept of an abstract queue. You define your JMS turn as usual, and then just define the adapter.

    <service-activator input-channel="commandChannel" 
           ref="commandWatcher" method="processCommand">
    <poller task-executor="pool">
        <interval-trigger interval="100"/>
    </poller>
</service-activator>

<bean id="commandWatcher" class="foo.bar.Pojo" scope="prototype"/>

    <bean id="pool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
 <property name="corePoolSize" value="8" />   
     </beans:bean>

, " ", , 100 , . , POJO. , , Serialized, . , , .

JMS , ...

+1

Source: https://habr.com/ru/post/1770317/


All Articles