I create a message handler this way:
@JmsListeners(
JmsListener(destination = "queue1"),
JmsListener(destination = "queue2"),
JmsListener(destination = "queue3"),
JmsListener(destination = "queue4")
)
fun handleMessage(message: String) {
// handle a message
}
When I check my message broker, I see that my app has established 4 connections. Unfortunately, I have limitations on amount of connections from MQ admins, so I would like message handler to use only 1 connection.
After checking Spring Jms internals, I found out that DefaultMessageListenerContainer
has an ability to use a shared connection. But the problem is that Spring's DefaultMessageListenerContainerFactory
creates a separate DefaultMessageListenerContainer
for each @JmsListener
.
At the same time, JMS API allows creating multiple JMSConsumer
s from a single JMSContext
, e.g.
val jmsContext = connectionFactory.createContext(Session.SESSION_TRANSACTED)
val consumer1 = jmsContext.createConsumer(jmsContext.createQueue("queue1"))
val consumer2 = jmsContext.createConsumer(jmsContext.createQueue("queue2"))
How can I set up JmsListener
s to share a common connection? And if this isn't possible, does Spring has a sensible reason for it?