I’m using a DefaultMessageListenerContainer to consume messages from a topic (Broker is ActiveMQ). Because the consumers are created at runtime i’m doing the following:
1) I have a Conainer Template configured in spring
<bean id="topiccontainertemplate" class="org.springframework.jms.listener.DefaultMessageListenerContainer" scope="prototype" destroy-method="stop">
<property name="connectionFactory" ref="connectionfactory" />
<property name="pubSubDomain" value="true" />
<property name="cacheLevelName" value="CACHE_CONSUMER" />
<property name="destinationName" value="default" />
</bean>
2) When a new consumer is required i get a new one from the application conext and reconfigure the destinationName.
DefaultMessageListenerContainer container = context.getBean("topiccontainertemplate", DefaultMessageListenerContainer.class);
container.setDestinationName(localEntity.getId().getDestination());
container.setMessageListener(getListener());
container.start();
Unfortunately the container misses some messages on the topic.
Does anybody know what i’m doing wrong?
after some more tests we found a race condition during consumer creation. the messages weren’t lost, they weren’t distributed properly in our code.