I have my application that should communicate with two external systems A and B. So I am creating actually 2 containers like this:
private DefaultMessageListenerContainer createContainer(Conf conf) {
DefaultMessageListenerContainer jmsCnr= new DefaultMessageListenerContainer();
jmsCnr.setConnectionFactory(connectionFactoryAdapter);
jmsCnr.setDestinationResolver(destinationResolver);
jmsCnr.setDestinationName(destinationName);
jmsCnr.setMessageListener(MyClass);
jmsCnr.initialize();
return jmsCnr;
}
And creation of connection factory goes like this:
private ConnectionFactory createConnectionFactory(Conf conf) {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
JndiTemplate jndiTemplate = getJNDITemplate(conf);
String connectionFactoryJndiName = conf.getConnectionFactoryJndi();
jndiObjectFactoryBean.setJndiTemplate(jndiTemplate);
jndiObjectFactoryBean.setJndiName(connectionFactoryJndiName);
jndiObjectFactoryBean.setProxyInterface(ConnectionFactory.class);
jndiObjectFactoryBean.setLookupOnStartup(false);
try {
jndiObjectFactoryBean.afterPropertiesSet();
} catch (NamingException e) {
e.printStackTrace();
}
return (ConnectionFactory) jndiObjectFactoryBean.getObject();
}
After that containers are created, I am looping over them and call start(). Everything is working fine My listener is receiving message in case if message is sent to external system A.
However if I configuring my startup class to create two containers for external system A and for B, I am not receiving messages from queues of system A, and from system B messages are received.
Again, I am using spring implementations without spring context, everything is programmatic.
My question is, where I am missing something? Seems creation of second DefaultMessageListenerContainer instance for external system B is overriding the previous.