2

I'm trying to use Spring JMS messaging with @JmsListener in a scalable way, but I'm not seeing it happening. I have a ConnectionFactory bean that returns a factory that connects to an Oracle Advanced Queue through JMS and a database DataSource pool.

The problem starts as every @JmsListener receiver connects again to JMS (and hence to the database pool). My understand is that I can have many @JmsListener methods, one for each service, but in this way it's doing I'm very limited.

The shared connection is turned on, but since each @JmsListener creates a different DefaultMessageListenerContainer, each one have a database connection.

If I also want the services to handle messages concurrently and set container.setConcurrency("3-5"), then it opens 3 * numberOfListeners connections.

If I use container.setCacheLevel(DefaultMessageListenerContainer.CACHE_NONE) then from each second every listener container connects and disconnects from the JMS/database.

I want something that connects one time (or more, if there is concurrent jobs to process) to JMS/database, not to connect count-of-listener times nor to connect-disconnect at each second for every listener.

1 Answers1

0

You can use a SingleConnectionFactory to wrap the vendor factory and all containers will use the same connection.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Even with it, since many DefaultMessageListenerContainer are created, each one tries to createSession from the connection, and then it session is a Oracle database connection. It seems I need to share the sessions too, not only the connection. The problems happens with the default and with `container.setCacheLevel(DefaultMessageListenerContainer.CACHE_SESSION)` too. – Adriano dos Santos Fernandes Jul 03 '18 at 17:52
  • Then this is the way how Oracle AQ works and this is already out of Spring control. Try consult with Oracle support. We would appreciate if you would share with us their answer. – Artem Bilan Jul 03 '18 at 17:55
  • But to listen for messages, why spring needs to create many sessions? Can't it use just many consumers? – Adriano dos Santos Fernandes Jul 03 '18 at 18:03