I have a web application that connects to multiple jms servers (one at the time) and monitors queues. While this is simple for one jms server I do not know how to configure it for multiple servers. I want user to be able to choose the server at logging in and only then I want JmsListener to monitor queues. User also must be able to change the server while he's already logged in. The problem is how to create and change configuration of these beans at runtime. At the moment my solution is hard-coded like this:
JmsConfig.class
@Bean
public TibjmsConnectionFactory receiverTibjmsConnectionFactory() {
TibjmsConnectionFactory factory=new TibjmsConnectionFactory("myip");
factory.setUserName("username");
factory.setUserPassword("password");
return factory;
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory=new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(receiverTibjmsConnectionFactory());
factory.setPubSubDomain(true);
return factory;
}
EmsListener.class
@Component
public class JmsListener {
@org.springframework.jms.annotation.JmsListener(destination="$sys.monitor.Q.r.>")
public void receive(Message message) throws JMSException {
System.out.println("MY MESSAGE IS : "+message.getJMSTimestamp());
}
}