Reputation: 914
I am connecting to JMS queue using t3 protocol using DefaultMessageListenerContainer and it is working fine if the t3 protocol is UP. But If the t3 URL is down, then the Listener cannot re-register the Bean once the t3 URL is UP. I have override the Listener to make a call but not able to re-register the Bean after application started.
@Bean
public QueueConnectionFactory queueConnectionFactory() {
Context m_context = getInitialContext();
QueueConnectionFactory queueConnectionFactory = new JMSConnectionFactory();
try {
System.out.println("Connection Factory");
queueConnectionFactory = (QueueConnectionFactory) m_context
.lookup("myconnectionfactory");
} catch (Exception e) {
System.err.println("Exception Connection Factory goes down");
}
return queueConnectionFactory;
}
@Bean
public Context getInitialContext() {
try {
Properties h = new Properties();
System.out.println("getInitialContext ");
h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://100.21.101.12:7001");
return new InitialContext(h);
} catch (Exception e) {
System.error.println("Error at getInitialContext");
}
return null;
}
@Bean
public Queue jmsQueue() {
Context m_context = getInitialContext();
Queue jmsQueue = new MQQueue();
try {
System.out.println("jmsQueue ");
jmsQueue = (Queue) m_context.lookup("myqueue");
} catch (Exception e) {
System.error.println("Error at JMS");
}
return jmsQueue;
}
@Bean
public DefaultMessageListenerContainer messageListener() {
DefaultMessageListenerContainer listener = new DefaultMessageListenerContainer();
try {
System.out.println("messageListener ");
listener.setConcurrentConsumers("4");
listener.setConnectionFactory((ConnectionFactory) queueConnectionFactory());
listener.setDestination((Destination) jmsQueue());
listener.setMessageListener(queueListener());
} catch (Exception e) {
System.out.println("Exception >>"+e);
}
return listener;
}
2022-08-05 15:16:24.615 ERROR 56480 --- [ssageListener-5] .b.e.s.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination from DefaultMessageListener'queue:///' - retrying using FixedBackOff{interval=5000, currentAttempts=52, maxAttempts=unlimited}. Cause: null
Is there any way to do this bean to get register using the Listener.
Upvotes: 0
Views: 1148
Reputation: 174759
That is an error from the listener container, not the registration of the connection factory bean.
You should be able to set the containers to not start automatically, using
spring.jms.listener.auto-startup=false
Then you can start them manually (in a try block) via the JmsListenerEndpointRegistry
bean.
Upvotes: 0