Class AbstractMessageListenerContainer
- All Implemented Interfaces:
Aware, BeanNameAware, DisposableBean, InitializingBean, Lifecycle, Phased, SmartLifecycle, MessageListenerContainer
- Direct Known Subclasses:
AbstractPollingMessageListenerContainer, SimpleMessageListenerContainer
MessageListener or Spring's
SessionAwareMessageListener for actual message processing.
Usually holds a single JMS Connection that all listeners are supposed
to be registered on, which is the standard JMS way of managing listener sessions.
Can alternatively also be used with a fresh Connection per listener, for Jakarta EE
style XA-aware JMS messaging. The actual registration process is up to concrete
subclasses.
NOTE: The default behavior of this message listener container is to
never propagate an exception thrown by a message listener up to the JMS
provider. Instead, it will log any such exception at WARN level.
This means that from the perspective of the attendant JMS provider no such
listener will ever fail. However, if error handling is necessary, then
an implementation of the ErrorHandler strategy may be provided to
the setErrorHandler(ErrorHandler) method. Note that JMSExceptions
will be passed to the ErrorHandler in addition to (but after)
being passed to an ExceptionListener, if one has been provided.
The listener container offers the following message acknowledgment options:
- "sessionAcknowledgeMode" set to "AUTO_ACKNOWLEDGE" (default):
This mode is container-dependent: for
DefaultMessageListenerContainer, it means automatic message acknowledgment before listener execution, with no redelivery in case of an exception and no redelivery in case of other listener execution interruptions either. forSimpleMessageListenerContainer, it means automatic message acknowledgment after listener execution, with no redelivery in case of a user exception thrown but potential redelivery in case of the JVM dying during listener execution. In order to consistently arrange for redelivery with any container variant, consider "CLIENT_ACKNOWLEDGE" mode or - preferably - setting "sessionTransacted" to "true" instead. - "sessionAcknowledgeMode" set to "DUPS_OK_ACKNOWLEDGE":
Lazy message acknowledgment during (
DefaultMessageListenerContainer) or shortly after (SimpleMessageListenerContainer) listener execution; no redelivery in case of a user exception thrown but potential redelivery in case of the JVM dying during listener execution. In order to consistently arrange for redelivery with any container variant, consider "CLIENT_ACKNOWLEDGE" mode or - preferably - setting "sessionTransacted" to "true" instead. - "sessionAcknowledgeMode" set to "CLIENT_ACKNOWLEDGE": Automatic message acknowledgment after successful listener execution; best-effort redelivery in case of a user exception thrown as well as in case of other listener execution interruptions (such as the JVM dying).
- "sessionTransacted" set to "true": Transactional acknowledgment after successful listener execution; guaranteed redelivery in case of a user exception thrown as well as in case of other listener execution interruptions (such as the JVM dying).
There are two solutions to the duplicate message processing problem:
- Either add duplicate message detection to your listener, in the form of a business entity existence check or a protocol table check. This usually just needs to be done in case of the JMSRedelivered flag being set on the incoming message (otherwise just process straightforwardly). Note that with "sessionTransacted" set to "true", duplicate messages will only appear in case of the JVM dying at the most unfortunate point possible (i.e. after your business logic executed but before the JMS part got committed), so duplicate message detection is just there to cover a corner case.
- Or wrap your entire processing with an XA transaction, covering the
receipt of the JMS message as well as the execution of the business logic in
your message listener (including database operations etc). This is only
supported by
DefaultMessageListenerContainer, through specifying an external "transactionManager" (typically aJtaTransactionManager, with a corresponding XA-aware JMSConnectionfactorypassed in as "connectionfactory").
Recommendations:
- The general recommendation is to set "sessionTransacted" to "true", typically in combination with local database transactions triggered by the listener implementation, through Spring's standard transaction facilities. This will work nicely in Tomcat or in a standalone environment, often combined with custom duplicate message detection (if it is unacceptable to ever process the same message twice).
- Alternatively, specify a
JtaTransactionManageras "transactionManager" for a fully XA-aware JMS provider - typically when running on a Jakarta EE server, but also for other environments with a JTA transaction manager present. This will give full "exactly-once" guarantees without custom duplicate message checks, at the price of additional runtime processing overhead.
Note that the "sessionTransacted" flag is strongly recommended over
JmsTransactionManager, provided
that transactions do not need to be managed externally. As a consequence,
set the transaction manager only if you are using JTA or if you need to
synchronize with custom external transaction arrangements.
- Since:
- 2.0
- Author:
- Juergen Hoeller, Stephane Nicoll, Brian Clozel
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractJmsListeningContainer
AbstractJmsListeningContainer.SharedConnectionNotInitializedException -
field Summary
fields inherited from class AbstractJmsListeningContainer
lifecycleCondition, lifecycleLock, sharedConnectionLockfields inherited from class JmsDestinationAccessor
RECEIVE_TIMEOUT_INDEfINITE_WAIT, RECEIVE_TIMEOUT_NO_WAITfields inherited from class JmsAccessor
loggerfields inherited from interface SmartLifecycle
DEfAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckMessageListener(@Nullable Object messageListener) Check the given message listener, throwing an exception if it does not correspond to a supported listener type.protected voidcommitIfNecessary(jakarta.jms.Session session, @Nullable jakarta.jms.Message message) Perform a commit or message acknowledgement, as appropriate.protected jakarta.jms.MessageConsumercreateConsumer(jakarta.jms.Session session, jakarta.jms.Destination destination) Create a JMS MessageConsumer for the given Session and Destination.protected io.micrometer.observation.ObservationcreateObservation(jakarta.jms.Message message) Create, but do not start anObservationfor JMS message processing.protected voiddoExecuteListener(jakarta.jms.Session session, jakarta.jms.Message message) Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).protected voiddoInvokeListener(jakarta.jms.MessageListener listener, jakarta.jms.Message message) Invoke the specified listener as standard JMSMessageListener.protected voiddoInvokeListener(SessionAwareMessageListener listener, jakarta.jms.Session session, jakarta.jms.Message message) Invoke the specified listener as Spring SessionAwareMessageListener, exposing a new JMS Session (potentially with its own transaction) to the listener if demanded.protected voidexecuteListener(jakarta.jms.Session session, jakarta.jms.Message message) Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).protected StringgetDefaultSubscriptionName(Object messageListener) Determine the default subscription name for the given message listener.@Nullable jakarta.jms.DestinationReturn the destination to receive messages from.protected StringReturn a descriptive String for this container's JMS destination (nevernull).Return the name of the destination to receive messages from.Return the name of a durable subscription to create, if any.Return theErrorHandlerto be invoked in case of any uncaught exceptions thrown while processing aMessage.@Nullable jakarta.jms.ExceptionListenerReturn the JMS ExceptionListener to notify in case of a JMSException thrown by the registered message listener or the invocation infrastructure, if any.Return theMessageConverterthat can be used to convertMessage, if any.Return the message listener object to register.Return the JMS message selector expression (ornullif none).@Nullable io.micrometer.observation.ObservationRegistryReturn theObservationRegistryused for recordingJMS message processing observations.Return theQosSettingsto use when sending a reply, ornullif the broker's defaults should be used.Return the name of a subscription to create, if any.protected voidHandle the given exception that arose during listener execution.protected voidInvoke the registeredErrorHandlerif any.protected voidinvokeExceptionListener(jakarta.jms.JMSException ex) Invoke the registered JMS ExceptionListener, if any.protected voidinvokeListener(jakarta.jms.Session session, jakarta.jms.Message message) Invoke the specified listener: either as standard JMS MessageListener or (preferably) as Spring SessionAwareMessageListener.booleanReturn whether to accept received messages while the listener container in the process of stopping.booleanDetermine whether the listener container should automatically acknowledge each JMS Message after the message listener returned.booleanReturn whether to expose the listener JMSSessionto a registeredSessionAwareMessageListener.booleanReturn whether to inhibit the delivery of messages published by its own connection.booleanReturn whether the Publish/Subscribe domain (Topics) is used for replies.protected booleanisSessionLocallyTransacted(jakarta.jms.Session session) Check whether the given Session is locally transacted, that is, whether its transaction is managed by this listener container's Session handling and not by an external transaction coordinator.booleanReturn whether to make the subscription durable.booleanReturn whether to make the subscription shared.protected voidrollbackIfNecessary(jakarta.jms.Session session) Perform a rollback, if appropriate.protected voidrollbackOnExceptionIfNecessary(jakarta.jms.Session session, Throwable ex) Perform a rollback, handling rollback exceptions properly.voidsetAcceptMessagesWhileStopping(boolean acceptMessagesWhileStopping) Set whether to accept received messages while the listener container in the process of stopping.voidsetAcknowledgeAfterListener(boolean acknowledgeAfterListener) Specify whether the listener container should automatically acknowledge each JMS Message after the message listener returned.abstract voidsetConcurrency(String concurrency) Specify concurrency limits.voidsetDestination(@Nullable jakarta.jms.Destination destination) Set the destination to receive messages from.voidsetDestinationName(@Nullable String destinationName) Set the name of the destination to receive messages from.voidsetDurableSubscriptionName(@Nullable String durableSubscriptionName) Set the name of a durable subscription to create.voidsetErrorHandler(@Nullable ErrorHandler errorHandler) Set theErrorHandlerto be invoked in case of any uncaught exceptions thrown while processing aMessage.voidsetExceptionListener(@Nullable jakarta.jms.ExceptionListener exceptionListener) Set the JMS ExceptionListener to notify in case of a JMSException thrown by the registered message listener or the invocation infrastructure.voidsetExposeListenerSession(boolean exposeListenerSession) Set whether to expose the listener JMS Session to a registeredSessionAwareMessageListeneras well as toJmsTemplatecalls.voidsetMessageConverter(@Nullable MessageConverter messageConverter) Set theMessageConverterstrategy for converting JMS Messages.voidsetMessageListener(@Nullable Object messageListener) Set the message listener implementation to register.voidsetMessageSelector(@Nullable String messageSelector) Set the JMS message selector expression (ornullif none).voidsetObservationRegistry(@Nullable io.micrometer.observation.ObservationRegistry observationRegistry) Set theObservationRegistryto be used for recordingJMS message processing observations.voidsetPubSubNoLocal(boolean pubSubNoLocal) Set whether to inhibit the delivery of messages published by its own connection.voidsetReplyPubSubDomain(boolean replyPubSubDomain) Configure the reply destination type.voidsetReplyQosSettings(@Nullable QosSettings replyQosSettings) Configure theQosSettingsto use when sending a reply.voidsetSubscriptionDurable(boolean subscriptionDurable) Set whether to make the subscription durable.voidsetSubscriptionName(@Nullable String subscriptionName) Set the name of a subscription to create.voidsetSubscriptionShared(boolean subscriptionShared) Set whether to make the subscription shared.voidsetupMessageListener(Object messageListener) Set up the message listener to use.protected voidValidate the configuration of this container.Methods inherited from class AbstractJmsListeningContainer
afterPropertiesSet, createSharedConnection, destroy, doInitialize, doRescheduleTask, doShutdown, doStart, doStop, establishSharedConnection, getBeanName, getClientId, getPausedTaskCount, getPhase, getSharedConnection, initialize, isActive, isAutoStartup, isRunning, logRejectedTask, prepareSharedConnection, refreshSharedConnection, releaseSharedConnection, rescheduleTaskIfNecessary, resumePausedTasks, runningAllowed, setAutoStartup, setBeanName, setClientId, setPhase, sharedConnectionEnabled, shutdown, start, startSharedConnection, stop, stopSharedConnectionMethods inherited from class JmsDestinationAccessor
getDestinationResolver, isPubSubDomain, receivefromConsumer, resolveDestinationName, setDestinationResolver, setPubSubDomainMethods inherited from class JmsAccessor
convertJmsAccessException, createConnection, createSession, getConnectionfactory, getSessionAcknowledgeMode, isClientAcknowledge, isSessionTransacted, obtainConnectionfactory, setConnectionfactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransactedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MessageListenerContainer
getDestinationResolver, isPubSubDomainMethods inherited from interface SmartLifecycle
getPhase, isAutoStartup, isPauseable, stop
-
Constructor Details
-
AbstractMessageListenerContainer
public AbstractMessageListenerContainer()
-
-
Method Details
-
setConcurrency
Specify concurrency limits. -
setDestination
Set the destination to receive messages from.Alternatively, specify a "destinationName", to be dynamically resolved via the
DestinationResolver.Note: The destination may be replaced at runtime, with the listener container picking up the new destination immediately (works, for example, with DefaultMessageListenerContainer, as long as the cache level is less than CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
- See Also:
-
getDestination
Return the destination to receive messages from. Will benullif the configured destination is not an actualDestinationtype; c.f.when the destination is a String. -
setDestinationName
Set the name of the destination to receive messages from.The specified name will be dynamically resolved via the configured
destination resolver.Alternatively, specify a JMS
Destinationobject as "destination".Note: The destination may be replaced at runtime, with the listener container picking up the new destination immediately (works, for example, with DefaultMessageListenerContainer, as long as the cache level is less than CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
- See Also:
-
getDestinationName
Return the name of the destination to receive messages from. Will benullif the configured destination is not aStringtype; c.f.when it is an actual Destination. -
getDestinationDescription
Return a descriptive String for this container's JMS destination (nevernull). -
setMessageSelector
Set the JMS message selector expression (ornullif none). Default is none.See the JMS specification for a detailed definition of selector expressions.
Note: The message selector may be replaced at runtime, with the listener container picking up the new selector value immediately (works, for example, with DefaultMessageListenerContainer, as long as the cache level is less than CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
-
getMessageSelector
-
setMessageListener
Set the message listener implementation to register. This can be either a standard JMSMessageListenerobject or a SpringSessionAwareMessageListenerobject.Note: The message listener may be replaced at runtime, with the listener container picking up the new listener object immediately (works, for example, with DefaultMessageListenerContainer, as long as the cache level is less than CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
- Throws:
IllegalArgumentException- if the supplied listener is not aMessageListeneror aSessionAwareMessageListener- See Also:
-
getMessageListener
-
checkMessageListener
Check the given message listener, throwing an exception if it does not correspond to a supported listener type.By default, only a standard JMS
MessageListenerobject or a SpringSessionAwareMessageListenerobject will be accepted.- Parameters:
messageListener- the message listener object to check- Throws:
IllegalArgumentException- if the supplied listener is not aMessageListeneror aSessionAwareMessageListener- See Also:
-
getDefaultSubscriptionName
-
setSubscriptionDurable
public void setSubscriptionDurable(boolean subscriptionDurable) Set whether to make the subscription durable. The durable subscription name to be used can be specified through the "subscriptionName" property.Default is "false". Set this to "true" to register a durable subscription, typically in combination with a "subscriptionName" value (unless your message listener class name is good enough as subscription name).
Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the "pubSubDomain" flag as well.
- See Also:
-
isSubscriptionDurable
public boolean isSubscriptionDurable()Return whether to make the subscription durable. -
setSubscriptionName
Set the name of a subscription to create. To be applied in case of a topic (pub-sub domain) with a shared or durable subscription.The subscription name needs to be unique within this client's JMS client id. Default is the class name of the specified message listener.
Note: Only 1 concurrent consumer (which is the default of this message listener container) is allowed for each subscription, except for a shared subscription (which requires JMS 2.0).
- Since:
- 4.1
- See Also:
-
getSubscriptionName
-
setDurableSubscriptionName
Set the name of a durable subscription to create. This method switches to pub-sub domain mode and activates subscription durability as well.The durable subscription name needs to be unique within this client's JMS client id. Default is the class name of the specified message listener.
Note: Only 1 concurrent consumer (which is the default of this message listener container) is allowed for each durable subscription, except for a shared durable subscription (which requires JMS 2.0).
- See Also:
-
getDurableSubscriptionName
-
setPubSubNoLocal
public void setPubSubNoLocal(boolean pubSubNoLocal) Set whether to inhibit the delivery of messages published by its own connection. Default is "false".- Since:
- 4.1
- See Also:
-
isPubSubNoLocal
public boolean isPubSubNoLocal()Return whether to inhibit the delivery of messages published by its own connection.- Since:
- 4.1
-
setReplyPubSubDomain
public void setReplyPubSubDomain(boolean replyPubSubDomain) Configure the reply destination type. By default, the configuredpubSubDomainvalue is used (seeJmsDestinationAccessor.isPubSubDomain()).This setting primarily indicates what type of destination to resolve if dynamic destinations are enabled.
- Parameters:
replyPubSubDomain- "true" for the Publish/Subscribe domain (Topics), "false" for the Point-to-Point domain (Queues)- Since:
- 4.2
- See Also:
-
isReplyPubSubDomain
public boolean isReplyPubSubDomain()Return whether the Publish/Subscribe domain (Topics) is used for replies. Otherwise, the Point-to-Point domain (Queues) is used.- Specified by:
isReplyPubSubDomainin interfaceMessageListenerContainer- Since:
- 4.2
-
setReplyQosSettings
Configure theQosSettingsto use when sending a reply. Can be set tonullto indicate that the broker's defaults should be used.- Parameters:
replyQosSettings- the QoS settings to use when sending a reply, ornullto use the default value- Since:
- 5.0
-
getReplyQosSettings
Description copied from interface:MessageListenerContainerReturn theQosSettingsto use when sending a reply, ornullif the broker's defaults should be used.- Specified by:
getReplyQosSettingsin interfaceMessageListenerContainer
-
setMessageConverter
Set theMessageConverterstrategy for converting JMS Messages.- Since:
- 4.1
-
getMessageConverter
Description copied from interface:MessageListenerContainerReturn theMessageConverterthat can be used to convertMessage, if any.- Specified by:
getMessageConverterin interfaceMessageListenerContainer
-
setExceptionListener
Set the JMS ExceptionListener to notify in case of a JMSException thrown by the registered message listener or the invocation infrastructure. -
getExceptionListener
Return the JMS ExceptionListener to notify in case of a JMSException thrown by the registered message listener or the invocation infrastructure, if any. -
setErrorHandler
Set theErrorHandlerto be invoked in case of any uncaught exceptions thrown while processing aMessage.By default, there will be no ErrorHandler so that error-level logging is the only result.
-
getErrorHandler
Return theErrorHandlerto be invoked in case of any uncaught exceptions thrown while processing aMessage.- Since:
- 4.1
-
setObservationRegistry
public void setObservationRegistry(@Nullable io.micrometer.observation.ObservationRegistry observationRegistry) Set theObservationRegistryto be used for recordingJMS message processing observations. Defaults to no-op observations if the registry is not set.- Since:
- 6.1
-
getObservationRegistry
Return theObservationRegistryused for recordingJMS message processing observations.- Since:
- 6.1
-
setAcknowledgeAfterListener
public void setAcknowledgeAfterListener(boolean acknowledgeAfterListener) Specify whether the listener container should automatically acknowledge each JMS Message after the message listener returned. This applies in case of client acknowledge modes, including vendor-specific modes but not in case of auto-acknowledge or a transacted JMS Session.As of 6.2, the default is
true: The listener container will acknowledge each JMS Message even in case of a vendor-specific mode, assuming client-acknowledge style processing for custom vendor modes.If the provided listener prefers to manually acknowledge each message in the listener itself, in combination with an "individual acknowledge" mode, switch this flag to {code false} along with the vendor-specific mode.
- Since:
- 6.2.6
- See Also:
-
isAcknowledgeAfterListener
public boolean isAcknowledgeAfterListener()Determine whether the listener container should automatically acknowledge each JMS Message after the message listener returned.- Since:
- 6.2.6
- See Also:
-
setExposeListenerSession
public void setExposeListenerSession(boolean exposeListenerSession) Set whether to expose the listener JMS Session to a registeredSessionAwareMessageListeneras well as toJmsTemplatecalls.Default is "true", reusing the listener's
Session. Turn this off to expose a fresh JMS Session fetched from the same underlying JMSConnectioninstead, which might be necessary on some JMS providers.Note that Sessions managed by an external transaction manager will always get exposed to
JmsTemplatecalls. So in terms of JmsTemplate exposure, this setting only affects locally transacted Sessions.- See Also:
-
isExposeListenerSession
public boolean isExposeListenerSession()Return whether to expose the listener JMSSessionto a registeredSessionAwareMessageListener. -
setAcceptMessagesWhileStopping
public void setAcceptMessagesWhileStopping(boolean acceptMessagesWhileStopping) Set whether to accept received messages while the listener container in the process of stopping.Default is "false", rejecting such messages through aborting the receive attempt. Switch this flag on to fully process such messages even in the stopping phase, with the drawback that even newly sent messages might still get processed (if coming in before all receive timeouts have expired).
NOTE: Aborting receive attempts for such incoming messages might lead to the provider's retry count decreasing for the affected messages. If you have a high number of concurrent consumers, make sure that the number of retries is higher than the number of consumers, to be on the safe side for all potential stopping scenarios.
-
isAcceptMessagesWhileStopping
public boolean isAcceptMessagesWhileStopping()Return whether to accept received messages while the listener container in the process of stopping. -
validateConfiguration
protected void validateConfiguration()Description copied from class:AbstractJmsListeningContainerValidate the configuration of this container.The default implementation is empty. To be overridden in subclasses.
- Overrides:
validateConfigurationin classAbstractJmsListeningContainer
-
setupMessageListener
Description copied from interface:MessageListenerContainerSet up the message listener to use. Throws anIllegalArgumentExceptionif that message listener type is not supported.- Specified by:
setupMessageListenerin interfaceMessageListenerContainer
-
executeListener
protected void executeListener(jakarta.jms.Session session, jakarta.jms.Message message) Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).- Parameters:
session- the JMS Session to operate onmessage- the received JMSMessage- See Also:
-
createObservation
protected io.micrometer.observation.Observation createObservation(jakarta.jms.Message message) Create, but do not start anObservationfor JMS message processing.This will return a "no-op" observation if Micrometer Jakarta instrumentation is not available or if no Observation Registry has been configured.
- Parameters:
message- the message to be observed- Since:
- 6.1
-
doExecuteListener
protected void doExecuteListener(jakarta.jms.Session session, jakarta.jms.Message message) throws jakarta.jms.JMSException Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).- Parameters:
session- the JMS Session to operate onmessage- the received JMSMessage- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-
invokeListener
protected void invokeListener(jakarta.jms.Session session, jakarta.jms.Message message) throws jakarta.jms.JMSException Invoke the specified listener: either as standard JMS MessageListener or (preferably) as Spring SessionAwareMessageListener.- Parameters:
session- the JMS Session to operate onmessage- the received JMSMessage- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-
doInvokeListener
protected void doInvokeListener(SessionAwareMessageListener listener, jakarta.jms.Session session, jakarta.jms.Message message) throws jakarta.jms.JMSException Invoke the specified listener as Spring SessionAwareMessageListener, exposing a new JMS Session (potentially with its own transaction) to the listener if demanded.- Parameters:
listener- the Spring SessionAwareMessageListener to invokesession- the JMS Session to operate onmessage- the received JMSMessage- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-
doInvokeListener
protected void doInvokeListener(jakarta.jms.MessageListener listener, jakarta.jms.Message message) throws jakarta.jms.JMSException Invoke the specified listener as standard JMSMessageListener.Default implementation performs a plain invocation of the
onMessagemethod.- Parameters:
listener- the JMSMessageListenerto invokemessage- the received JMSMessage- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-
commitIfNecessary
protected void commitIfNecessary(jakarta.jms.Session session, @Nullable jakarta.jms.Message message) throws jakarta.jms.JMSException Perform a commit or message acknowledgement, as appropriate.- Parameters:
session- the JMSSessionto commitmessage- theMessageto acknowledge- Throws:
jakarta.jms.JMSException- in case of commit failure
-
rollbackIfNecessary
protected void rollbackIfNecessary(jakarta.jms.Session session) throws jakarta.jms.JMSException Perform a rollback, if appropriate.- Parameters:
session- the JMS Session to rollback- Throws:
jakarta.jms.JMSException- in case of a rollback error
-
rollbackOnExceptionIfNecessary
protected void rollbackOnExceptionIfNecessary(jakarta.jms.Session session, Throwable ex) throws jakarta.jms.JMSException Perform a rollback, handling rollback exceptions properly.- Parameters:
session- the JMS Session to rollbackex- the thrown application exception or error- Throws:
jakarta.jms.JMSException- in case of a rollback error
-
isSessionLocallyTransacted
protected boolean isSessionLocallyTransacted(jakarta.jms.Session session) Check whether the given Session is locally transacted, that is, whether its transaction is managed by this listener container's Session handling and not by an external transaction coordinator.Note: The Session's own transacted flag will already have been checked before. This method is about finding out whether the Session's transaction is local or externally coordinated.
- Parameters:
session- the Session to check- Returns:
- whether the given Session is locally transacted
- See Also:
-
createConsumer
protected jakarta.jms.MessageConsumer createConsumer(jakarta.jms.Session session, jakarta.jms.Destination destination) throws jakarta.jms.JMSException Create a JMS MessageConsumer for the given Session and Destination.This implementation uses JMS 1.1 API.
- Parameters:
session- the JMS Session to create a MessageConsumer fordestination- the JMS Destination to create a MessageConsumer for- Returns:
- the new JMS MessageConsumer
- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods
-
handleListenerException
Handle the given exception that arose during listener execution.The default implementation logs the exception at
WARNlevel, not propagating it to the JMS provider — assuming that all handling of acknowledgement and/or transactions is done by this listener container. This can be overridden in subclasses.- Parameters:
ex- the exception to handle
-
invokeExceptionListener
protected void invokeExceptionListener(jakarta.jms.JMSException ex) Invoke the registered JMS ExceptionListener, if any.- Parameters:
ex- the exception that arose during JMS processing- See Also:
-
invokeErrorHandler
Invoke the registeredErrorHandlerif any. Log atWARNlevel otherwise.- Parameters:
ex- the uncaught error that arose during JMS processing- See Also:
-