I am using a DLQ listener to be invoked every minute via Spring scheduling as follows.
@Scheduled(fixedDelay=60000)
public void retryQueue() {
ConnectionFactory cf =
new ActiveMQConnectionFactory(uname, pwd, brokerName);
Connection cn = cf.createConnection();
cn.start();
Session sess = cn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination queue = sess.createQueue(retryQueue);
MessageConsumer messageConsumer = session.createConsumer(queue);
//further message processing here
}
Now my question is that every minute a new connection gets made and destroyed. How can I let Spring handle that connection management so that it does not create a connection every time.