0

ActiveMQ purpose two ways of consumption :

  1. Consuming asynchronously by calling MessageListener
  2. Consuming synchronously by enqueueing and let the client calling receive()

First I was using @JmsListener. This annotation makes Spring create an asynchronous consumer, i.e. it makes a receive() on the queue.

I tried to use MessageListener but Spring goes on to create an synchronous consumer.

So I looked Spring JMS and ActiveMQ code.

The only way to create an asynchronous consumer is to call ActiveMQSession.createConsumer with a MessageListener:

public MessageConsumer createConsumer(Destination destination, MessageListener messageListener) throws JMSException {
    return createConsumer(destination, null, messageListener);
}

Then I looked for calls like that one on Spring JMS and I've found nothing.

For the moment, I think that Spring JMS is not able to create a consumer with a MessageListener, i.e. to create a synchronous consumer (as the first consumption way above).

Am I right?

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
Erwann
  • 31
  • 4
  • Did my answer address your question? If so, please mark it as correct to help other users who have this same question in the future. If not, please elaborate as to why. Thanks! – Justin Bertram Nov 07 '19 at 18:27

2 Answers2

0

Spring JMS (as the name indicates) uses the JMS API. It doesn't call any ActiveMQ code directly so ActiveMQ implementation details are irrelevant here. The createConsumer method from ActiveMQSession which you refer to is not part of the JMS API so there's no reason why Spring JMS would invoke it.

You should look in the Spring JMS code for uses of javax.jms.MessageConsumer.setMessageListener(MessageListener listener) as this is the way to set the MessageListener via the JMS API.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
0

The setMessageListener method is called from Spring JMS in the SimpleMessageListenerContainer (not in the default one) :

/**
 * Message listener container that uses the plain JMS client API's
 * {@code MessageConsumer.setMessageListener()} 
 * [...]
 */
 public class SimpleMessageListenerContainer

The documentation says that this simple container does not support XA transactions : see here

Unfortunately, I need it.

Erwann
  • 31
  • 4