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?

Colin M
  • 13,010
  • 3
  • 38
  • 58
  • Doesn't make any sense to me; try turning on TRACE level logging. – Gary Russell Jan 26 '14 at 14:32
  • @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. – Colin M Jan 26 '14 at 14:40
  • Yes, of course; you need to call `afterPropertiesSet()`. – Gary Russell Jan 26 '14 at 14:55

1 Answers1

21

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.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • 2
    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). – Colin M Jan 26 '14 at 15:53