🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
Getting Connection object when using JMSListener
Hi,
Is there any way to get the handle of Connection object when using @jmslistener?
@Bean(name = "FeeBillConnectionFactory")
public JmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory cachingConnectionFactory){
DefaultJmsListenerContainerFactory jmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();
jmsListenerContainerFactory.setConnectionFactory(cachingConnectionFactory);
jmsListenerContainerFactory.setConcurrency("2-10");
jmsListenerContainerFactory.setSessionTransacted(true);
jmsListenerContainerFactory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
return jmsListenerContainerFactory;
}
@JmsListener(destination = "security", containerFactory="FeeBillConnectionFactory") //, concurrency = "15-20") public void handle(Message message, Session session) throws InterruptedException, JMSException { System.out.println("handle()"+message.getJMSMessageID()); if (message instanceof TextMessage) { TextMessage tm = (TextMessage) message; try { TestFunction tf=new TestFunction(message, session); Thread t = new Thread(tf); t.setDaemon(true); t.start(); } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("In Spring Reciever"+message.toString()); }
Comments
-
Hi @vshivk99,
Tbh I'm not sure off the top of my head as I don't see an obvious way, but I would be curious what you'd want to do with theConnection
object? Usually the connections are managed by theConnectionFactory
itself in a Spring JMS App and from a dev perspective you can access the ConnectionFactory or the Session object (as you've shown in your code above)0 -
Hi @marc ,
We are trying to create SolaceConnector common library. As part of it for sending , i wanted to create a new session in sender so that we do not get the issue of Commit issue. For creating new session need Connection object.
final Session sessionn = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);The approach I am taking is, as soon as message comes I will create a new thread and with the thread i will process all the request and complete the operation and if it is R/R then will also send the reply back. For sending the reply back, I will use the Sender code.
Thanks and Regards,
Shiva0 -
Hi @vshivk99,
Unless I'm missing something I would take a closer look at using the Spring JMS DefaultMessageListenerContainer and see if it meets your needs before creating your own library to do this. They have a pretty good write-up at the top of that page. Using that DMLC Spring will already allow you to specify an exact number of concurrent consumers using
setConcurrentConsumers
or event a range usingconcurrency
and each consumer will process messages in its own thread.0