Below is the code in which I am trying to create a dynamic Listenercontainer instance after the application has been deployed. Without the message selector(the commented code), I am able to see my messages being consumed. Once I am adding the setMessageSelector the message is not getting consumed. I configured the producers to produce messages with two different message selectors, say color='RED' and another one color='BLUE'. I have wired the 'RED' one using the Spring XML configuration. And this configuration works without any issues. I am able to see the message being consumed by consumers. But when I am trying to create a dynamic bean with color='BLUE' it does not work. The same will work without any issues if I add it in spring XML
'''
DefaultMessageListenerContainer defaultMessageListenerContainer=new DefaultMessageListenerContainer();
defaultMessageListenerContainer.setAutoStartup(Boolean.FALSE);
defaultMessageListenerContainer.setMessageListener(this.getMessageListener());
//defaultMessageListenerContainer.setMessageSelector(this.getMessageSelector());
defaultMessageListenerContainer.setBeanName(this.getBeanName());
defaultMessageListenerContainer.setConnectionFactory(this.getConnectionFactory());
defaultMessageListenerContainer.setDestination((Destination) this.getApplicationContext().getBean("customDestination"));
defaultMessageListenerContainer.setSessionTransacted(Boolean.TRUE);
defaultMessageListenerContainer.setConcurrentConsumers(1);
defaultMessageListenerContainer.setMaxConcurrentConsumers(5);
defaultMessageListenerContainer.initialize();
defaultMessageListenerContainer.afterPropertiesSet();
defaultMessageListenerContainer.start();
System.out.println(defaultMessageListenerContainer.isRunning());
System.out.println(defaultMessageListenerContainer.isAcceptMessagesWhileStopping());
System.out.println(defaultMessageListenerContainer.isRegisteredWithDestination());
ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
beanFactory.registerSingleton("jmsRequestListenerContainer", defaultMessageListenerContainer);
<bean id="jmsRequestListenerContainerdefault" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="concurrentConsumers" value="1" />
<property name="maxConcurrentConsumers" value="5" />
<property name="cacheLevel" value="0"/>
<property name="connectionFactory" ref="queueConnectionFactory" />
<property name="destination" ref="customeDestination"/>
<property name="sessionTransacted" value="true"/>
<property name="messageListener" ref="jmsRequestListener" />
<property name="messageSelector" value="color='RED'"/>
</bean>
<jee:jndi-lookup id="queueConnectionFactory" jndi-name="java:/JmsXA"/>
'''
Am I missing something in the code while creating it dynamically after the application has launched?
messageSelectorproperties (not allowed) andcacheLevelNamecannot accept numbers, should becacheLevel. - Gary Russell<property name="cacheLevelName" value="0"/>which is not valid. See my answer; I have no problems adding selectors at runtime. - Gary Russell