DefaultMessageListenerContainer not receiving messages
Asked Answered
T

1

7

I have a DefaultMessageListenerContainer configured as follows:

DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConcurrentConsumers(4);
container.setConnectionFactory(connectionFactory);
container.setDestinationName(String.format("Consumer.%s.VirtualTopic.%s", group, topic));
container.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
container.setSessionTransacted(true);
container.setMessageListener(new DelegatingMessageListener(listener, messageMapper, event));

container.start();

The message container never receives messages, and my message listener is never invoked. Leaving all else the same, if I just switch DefaultMessageListenerContainer to SimpleMessageListenerContainer, it works - but SimpleMessageListenerContainer doesn't recover after a connection loss

There are no errors in the logs, and hardly any relevant messages. Does anyone have any reasons for why this may be happening?

Thermobarometer answered 26/1, 2014 at 6:38 Comment(3)
Doesn't make any sense to me; try turning on TRACE level logging.Cuthburt
@GaryRussell I have enabled trace. ActiveMQ itself doesn't even seem to log anything, indicating that the subscription is never actually happening (which I suspected). Looking into the source for Spring, I see that SimpleMessageListenerContainer has an overridden doStart method that actually creates the listeners. I don't see that corresponding code in DefaultMessageListenerContainer, which is interesting. Maybe I'm missing something.Thermobarometer
Yes, of course; you need to call afterPropertiesSet().Cuthburt
C
22

When constructing the container in Java (outside a Spring application context), you need to invoke afterPropertiesSet() before start().

The context does that automatically for Spring beans.

Cuthburt answered 26/1, 2014 at 14:54 Comment(1)
Thank you! This worked perfectly. Now I feel stupid. I would have just registered everything through the context, but I have this code in a shared library that each service depends on, and the services subscribe to an abstraction above the Spring JMS layer (so they don't know anything about the existence of JMS - they just send and react to events from somewhere).Thermobarometer

© 2022 - 2024 — McMap. All rights reserved.