Class EsbConnectionManager
java.lang.Object
com.kingsrook.qqq.esb.connection.EsbConnectionManager
Long-lived JMS connections to ESB providers (brokers): one connection per
provider, shared by every session opened on it.
A provider's connection is made, from the provider's meta-data in the
QContext's instance, on the first openSession for that provider, and is kept
until closeAll. Each openSession call opens a new session on it; callers
close the sessions they open. Publishing uses a separate bounded pool of
exclusive transacted leases, invalidated whenever the connection is lost.
Connecting waits at most EsbConnectionFactoryBuilder.CONNECT_TIMEOUT_MS
(5 s). When a connection can't be made, or is lost (reported to the JMS
ExceptionListener), the manager reconnects in the background with backoff
(1 s, doubling up to 30 s), then fires the provider's connection listeners,
so the owners of sessions and consumers (which died with the old connection)
can open new ones. While it is reconnecting, openSession fails at once
rather than waiting - so a broker that is down holds up only the first
attempt (by at most the connect timeout), not every one after it.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOne exclusive publication. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnectionListener(String providerName, Runnable onReconnect) Add a listener to run each time the manager (re)connects to the provider in the background - after a lost connection, or after a first connect that failed.borrowPublishingSession(String providerName) Exclusively borrow a transacted publishing session.voidcloseAll()Close every provider's connection (and so every session on them), stop any background reconnecting, and remove all connection listeners - a full reset.static EsbConnectionManagerGet the singleton instance.booleanisConnected(String providerName) Whether the provider has a live connection (false if it was never connected, or is reconnecting).jakarta.jms.SessionopenSession(String providerName, boolean transacted) Open a new session on a provider's connection - connecting first, if this is the provider's first session.jakarta.jms.Destinationresolve(jakarta.jms.Session session, QEsbDestinationMetaData destination) The JMS Queue or Topic for an ESB destination, on a session from openSession for the destination's provider.jakarta.jms.QueueresolveQueue(jakarta.jms.Session session, String providerName, String brokerQueueName) The JMS Queue for a broker-side queue name (e.g., a dead-letter queue), on a session from openSession for the provider.
-
Method Details
-
getInstance
Get the singleton instance. -
openSession
Open a new session on a provider's connection - connecting first, if this is the provider's first session. A transacted session sends and receives when it commits; a non-transacted one auto-acknowledges. Throws QException if the provider is unknown, its broker client isn't on the classpath, or it can't be connected to (then the manager keeps trying in the background - see the class comment).- Throws:
QException
-
borrowPublishingSession
public EsbConnectionManager.PublishingSessionLease borrowPublishingSession(String providerName) throws QException Exclusively borrow a transacted publishing session. Capacity is bounded per provider; healthy saturation waits interruptibly for a returned lease. Close the producer before committing the lease. Closing an uncommitted lease rolls back and discards it. Consumer openSession ownership is separate.- Throws:
QException
-
resolve
public jakarta.jms.Destination resolve(jakarta.jms.Session session, QEsbDestinationMetaData destination) throws jakarta.jms.JMSException The JMS Queue or Topic for an ESB destination, on a session from openSession for the destination's provider.- Throws:
jakarta.jms.JMSException
-
resolveQueue
-
isConnected
Whether the provider has a live connection (false if it was never connected, or is reconnecting). -
addConnectionListener
Add a listener to run each time the manager (re)connects to the provider in the background - after a lost connection, or after a first connect that failed. Listeners run on the reconnecting thread (which has no QContext); one that throws is logged, and doesn't stop the others. -
closeAll
public void closeAll()Close every provider's connection (and so every session on them), stop any background reconnecting, and remove all connection listeners - a full reset. The next openSession connects anew.
-