Spring JMS listener receives empty messages causing CPU consumption

1k Views Asked by At

I'm working on an application that uses a couple of jms queues to send/receive updates to/from an external system. In order to test my application I'm using Mockrunner and specifically the jms module. I'm facing a strange behavior: when I start my application I can see the CPU skyrocketing at 100% and, by analyzing thread dumps, I can see that the main reason is related to the jms listeners I have that looks like receiving empty messages this causing messages like:

Consumer ... did not receive a message

Now I'm trying to understand if the issue is related to a bad interaction of my app and mockrunner or is a configuration error.

The relevant parts of the configuration are:

<bean id="destinationManager" factory-bean="mockRunnerJMSObjectFactory" factory-method="getDestinationManager" />

<bean id="mockJmsConnectionFactory" factory-bean="mockRunnerJMSObjectFactory" factory-method="createMockConnectionFactory" lazy-init="true"/>

and the listener that cause the CPU to spin indefinitely are:

<jms:listener-container concurrency="5" connection-factory="mockJmsConnectionFactory" destination-type="queue" message-converter="myMessageConverter" acknowledge="transacted" >
    <jms:listener 
        id="myListener" 
        destination="myQueue" 
        ref="myConsumer" 
        method="consume"
    />
</jms:listener-container>

<bean id="myConsumer"... />

UPDATE I opened an issue on Mockrunner project, you can see it here.

1

There are 1 best solutions below

0
On BEST ANSWER

After some investigation I found out that the problem lies in a bad interaction with Spring DefaultMessageListenerContainer. That Listener has a polling-based implementation and, given that the mocked infrastructure is very fast when answering requests, cause the CPU to overload. I patched mock runner by adding an ugly thread sleep in the response method, maybe this is going to be fixed sooner or later.