类 AbstractMessageListenerContainer
- java.lang.Object
- org.springframework.jms.support.JmsAccessor
- org.springframework.jms.support.destination.JmsDestinationAccessor
- org.springframework.jms.listener.AbstractJmsListeningContainer
- org.springframework.jms.listener.AbstractMessageListenerContainer
- 所有已实现的接口:
Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,Lifecycle
,Phased
,SmartLifecycle
,MessageListenerContainer
public abstract class AbstractMessageListenerContainer extends AbstractJmsListeningContainer implements MessageListenerContainer
Abstract base class for Spring message listener container implementations. Can either host a standard JMSMessageListener
or Spring'sSessionAwareMessageListener
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 Java 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 the error 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 any implementation of the
ErrorHandler
strategy may be provided to thesetErrorHandler(ErrorHandler)
method. Note that JMSExceptions will be passed to the ErrorHandler in addition to (but after) being passed to anExceptionListener
, 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 reception 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 JMSConnectionFactory
passed 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
JtaTransactionManager
as "transactionManager" for a fully XA-aware JMS provider - typically when running on a Java 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.- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller, Stephane Nicoll
- 另请参阅:
setMessageListener(java.lang.Object)
,MessageListener
,SessionAwareMessageListener
,handleListenerException(java.lang.Throwable)
,DefaultMessageListenerContainer
,SimpleMessageListenerContainer
,JmsMessageEndpointManager
嵌套类概要
从类继承的嵌套类/接口 org.springframework.jms.listener.AbstractJmsListeningContainer
AbstractJmsListeningContainer.SharedConnectionNotInitializedException
字段概要
从类继承的字段 org.springframework.jms.listener.AbstractJmsListeningContainer
lifecycleMonitor, sharedConnectionMonitor
从类继承的字段 org.springframework.jms.support.destination.JmsDestinationAccessor
RECEIVE_TIMEOUT_INDEFINITE_WAIT, RECEIVE_TIMEOUT_NO_WAIT
从类继承的字段 org.springframework.jms.support.JmsAccessor
logger
构造器概要
构造器 构造器 说明 AbstractMessageListenerContainer()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected void
checkMessageListener(Object messageListener)
Check the given message listener, throwing an exception if it does not correspond to a supported listener type.protected void
commitIfNecessary(Session session, Message message)
Perform a commit or message acknowledgement, as appropriate.protected MessageConsumer
createConsumer(Session session, Destination destination)
Create a JMS MessageConsumer for the given Session and Destination.protected void
doExecuteListener(Session session, Message message)
Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).protected void
doInvokeListener(MessageListener listener, Message message)
Invoke the specified listener as standard JMS MessageListener.protected void
doInvokeListener(SessionAwareMessageListener listener, Session session, 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 void
executeListener(Session session, Message message)
Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).protected String
getDefaultSubscriptionName(Object messageListener)
Determine the default subscription name for the given message listener.Destination
getDestination()
Return the destination to receive messages from.protected String
getDestinationDescription()
Return a descriptive String for this container's JMS destination (nevernull
).String
getDestinationName()
Return the name of the destination to receive messages from.String
getDurableSubscriptionName()
Return the name of a durable subscription to create, if any.ErrorHandler
getErrorHandler()
Return the ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message.ExceptionListener
getExceptionListener()
Return the JMS ExceptionListener to notify in case of a JMSException thrown by the registered message listener or the invocation infrastructure, if any.MessageConverter
getMessageConverter()
Return theMessageConverter
that can be used to convertMessage
, if any.Object
getMessageListener()
Return the message listener object to register.String
getMessageSelector()
Return the JMS message selector expression (ornull
if none).String
getSubscriptionName()
Return the name of a subscription to create, if any.protected void
handleListenerException(Throwable ex)
Handle the given exception that arose during listener execution.protected void
invokeErrorHandler(Throwable ex)
Invoke the registered ErrorHandler, if any.protected void
invokeExceptionListener(JMSException ex)
Invoke the registered JMS ExceptionListener, if any.protected void
invokeListener(Session session, Message message)
Invoke the specified listener: either as standard JMS MessageListener or (preferably) as Spring SessionAwareMessageListener.boolean
isAcceptMessagesWhileStopping()
Return whether to accept received messages while the listener container in the process of stopping.boolean
isExposeListenerSession()
Return whether to expose the listener JMSSession
to a registeredSessionAwareMessageListener
.boolean
isPubSubNoLocal()
Return whether to inhibit the delivery of messages published by its own connection.boolean
isReplyPubSubDomain()
Return whether the Publish/Subscribe domain (Topics
) is used for replies.protected boolean
isSessionLocallyTransacted(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.boolean
isSubscriptionDurable()
Return whether to make the subscription durable.boolean
isSubscriptionShared()
Return whether to make the subscription shared.protected void
rollbackIfNecessary(Session session)
Perform a rollback, if appropriate.protected void
rollbackOnExceptionIfNecessary(Session session, Throwable ex)
Perform a rollback, handling rollback exceptions properly.void
setAcceptMessagesWhileStopping(boolean acceptMessagesWhileStopping)
Set whether to accept received messages while the listener container in the process of stopping.abstract void
setConcurrency(String concurrency)
Specify concurrency limits.void
setDestination(Destination destination)
Set the destination to receive messages from.void
setDestinationName(String destinationName)
Set the name of the destination to receive messages from.void
setDurableSubscriptionName(String durableSubscriptionName)
Set the name of a durable subscription to create.void
setErrorHandler(ErrorHandler errorHandler)
Set the ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message.void
setExceptionListener(ExceptionListener exceptionListener)
Set the JMS ExceptionListener to notify in case of a JMSException thrown by the registered message listener or the invocation infrastructure.void
setExposeListenerSession(boolean exposeListenerSession)
Set whether to expose the listener JMS Session to a registeredSessionAwareMessageListener
as well as toJmsTemplate
calls.void
setMessageConverter(MessageConverter messageConverter)
Set theMessageConverter
strategy for converting JMS Messages.void
setMessageListener(Object messageListener)
Set the message listener implementation to register.void
setMessageSelector(String messageSelector)
Set the JMS message selector expression (ornull
if none).void
setPubSubNoLocal(boolean pubSubNoLocal)
Set whether to inhibit the delivery of messages published by its own connection.void
setReplyPubSubDomain(boolean replyPubSubDomain)
Configure the reply destination type.void
setSubscriptionDurable(boolean subscriptionDurable)
Set whether to make the subscription durable.void
setSubscriptionName(String subscriptionName)
Set the name of a subscription to create.void
setSubscriptionShared(boolean subscriptionShared)
Set whether to make the subscription shared.void
setupMessageListener(Object messageListener)
Setup the message listener to use.protected void
validateConfiguration()
Validate the configuration of this container.从类继承的方法 org.springframework.jms.listener.AbstractJmsListeningContainer
afterPropertiesSet, createSharedConnection, destroy, doInitialize, doRescheduleTask, doShutdown, doStart, doStop, establishSharedConnection, getBeanName, getClientId, getPausedTaskCount, getPhase, getSharedConnection, initialize, isActive, isAutoStartup, isRunning, logRejectedTask, prepareSharedConnection, refreshSharedConnection, rescheduleTaskIfNecessary, resumePausedTasks, runningAllowed, setAutoStartup, setBeanName, setClientId, setPhase, sharedConnectionEnabled, shutdown, start, startSharedConnection, stop, stop, stopSharedConnection
从类继承的方法 org.springframework.jms.support.destination.JmsDestinationAccessor
getDestinationResolver, isPubSubDomain, receiveFromConsumer, resolveDestinationName, setDestinationResolver, setPubSubDomain
从类继承的方法 org.springframework.jms.support.JmsAccessor
convertJmsAccessException, createConnection, createSession, getConnectionFactory, getSessionAcknowledgeMode, isClientAcknowledge, isSessionTransacted, setConnectionFactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransacted
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.jms.listener.MessageListenerContainer
getDestinationResolver, isPubSubDomain
从接口继承的方法 org.springframework.context.SmartLifecycle
isAutoStartup, stop
构造器详细资料
AbstractMessageListenerContainer
public AbstractMessageListenerContainer()
方法详细资料
setConcurrency
public abstract void setConcurrency(String concurrency)
Specify concurrency limits.
setDestination
public void setDestination(Destination destination)
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 e.g. with DefaultMessageListenerContainer, as long as the cache level is less than CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
getDestination
public Destination getDestination()
Return the destination to receive messages from. Will benull
if the configured destination is not an actualDestination
type; c.f.when the destination is a String
.
setDestinationName
public void setDestinationName(String destinationName)
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
Destination
object as "destination".Note: The destination may be replaced at runtime, with the listener container picking up the new destination immediately (works e.g. with DefaultMessageListenerContainer, as long as the cache level is less than CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
getDestinationName
public String getDestinationName()
Return the name of the destination to receive messages from. Will benull
if the configured destination is not aString
type; c.f.when it is an actual Destination
.
getDestinationDescription
protected String getDestinationDescription()
Return a descriptive String for this container's JMS destination (nevernull
).
setMessageSelector
public void setMessageSelector(String messageSelector)
Set the JMS message selector expression (ornull
if 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 e.g. with DefaultMessageListenerContainer, as long as the cache level is less than CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
getMessageSelector
public String getMessageSelector()
Return the JMS message selector expression (ornull
if none).
setMessageListener
public void setMessageListener(Object messageListener)
Set the message listener implementation to register. This can be either a standard JMSMessageListener
object or a SpringSessionAwareMessageListener
object.Note: The message listener may be replaced at runtime, with the listener container picking up the new listener object immediately (works e.g. with DefaultMessageListenerContainer, as long as the cache level is less than CACHE_CONSUMER). However, this is considered advanced usage; use it with care!
- 抛出:
IllegalArgumentException
- if the supplied listener is not aMessageListener
or aSessionAwareMessageListener
- 另请参阅:
MessageListener
,SessionAwareMessageListener
getMessageListener
public Object getMessageListener()
Return the message listener object to register.
checkMessageListener
protected void checkMessageListener(Object messageListener)
Check the given message listener, throwing an exception if it does not correspond to a supported listener type.By default, only a standard JMS
MessageListener
object or a SpringSessionAwareMessageListener
object will be accepted.- 参数:
messageListener
- the message listener object to check- 抛出:
IllegalArgumentException
- if the supplied listener is not aMessageListener
or aSessionAwareMessageListener
- 另请参阅:
MessageListener
,SessionAwareMessageListener
getDefaultSubscriptionName
protected String getDefaultSubscriptionName(Object messageListener)
Determine the default subscription name for the given message listener.- 参数:
messageListener
- the message listener object to check- 返回:
- the default subscription name
- 另请参阅:
SubscriptionNameProvider
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.
isSubscriptionDurable
public boolean isSubscriptionDurable()
Return whether to make the subscription durable.
setSubscriptionShared
public void setSubscriptionShared(boolean subscriptionShared)
Set whether to make the subscription shared. The shared subscription name to be used can be specified through the "subscriptionName" property.Default is "false". Set this to "true" to register a shared subscription, typically in combination with a "subscriptionName" value (unless your message listener class name is good enough as subscription name). Note that shared subscriptions may also be durable, so this flag can (and often will) be combined with "subscriptionDurable" as well.
Only makes sense when listening to a topic (pub-sub domain), therefore this method switches the "pubSubDomain" flag as well.
Requires a JMS 2.0 compatible message broker.
isSubscriptionShared
public boolean isSubscriptionShared()
Return whether to make the subscription shared.- 从以下版本开始:
- 4.1
setSubscriptionName
public void setSubscriptionName(String subscriptionName)
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).
getSubscriptionName
public String getSubscriptionName()
Return the name of a subscription to create, if any.- 从以下版本开始:
- 4.1
setDurableSubscriptionName
public void setDurableSubscriptionName(String durableSubscriptionName)
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).
getDurableSubscriptionName
public String getDurableSubscriptionName()
Return the name of a durable subscription to create, if any.
setPubSubNoLocal
public void setPubSubNoLocal(boolean pubSubNoLocal)
Set whether to inhibit the delivery of messages published by its own connection. Default is "false".- 从以下版本开始:
- 4.1
- 另请参阅:
Session.createConsumer(javax.jms.Destination, String, boolean)
isPubSubNoLocal
public boolean isPubSubNoLocal()
Return whether to inhibit the delivery of messages published by its own connection.- 从以下版本开始:
- 4.1
setReplyPubSubDomain
public void setReplyPubSubDomain(boolean replyPubSubDomain)
Configure the reply destination type. By default, the configuredpubSubDomain
value is used (seeJmsDestinationAccessor.isPubSubDomain()
.This setting primarily indicates what type of destination to resolve if dynamic destinations are enabled.
- 参数:
replyPubSubDomain
- "true" for the Publish/Subscribe domain (Topics
), "false" for the Point-to-Point domain (Queues
)- 从以下版本开始:
- 4.2
- 另请参阅:
JmsDestinationAccessor.setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)
isReplyPubSubDomain
public boolean isReplyPubSubDomain()
Return whether the Publish/Subscribe domain (Topics
) is used for replies. Otherwise, the Point-to-Point domain (Queues
) is used.- 指定者:
isReplyPubSubDomain
在接口中MessageListenerContainer
- 从以下版本开始:
- 4.2
setMessageConverter
public void setMessageConverter(MessageConverter messageConverter)
Set theMessageConverter
strategy for converting JMS Messages.- 从以下版本开始:
- 4.1
getMessageConverter
public MessageConverter getMessageConverter()
从接口复制的说明:MessageListenerContainer
Return theMessageConverter
that can be used to convertMessage
, if any.
setExceptionListener
public void setExceptionListener(ExceptionListener exceptionListener)
Set the JMS ExceptionListener to notify in case of a JMSException thrown by the registered message listener or the invocation infrastructure.
getExceptionListener
public ExceptionListener 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
public void setErrorHandler(ErrorHandler errorHandler)
Set the ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message.By default, there will be no ErrorHandler so that error-level logging is the only result.
getErrorHandler
public ErrorHandler getErrorHandler()
Return the ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message.- 从以下版本开始:
- 4.1
setExposeListenerSession
public void setExposeListenerSession(boolean exposeListenerSession)
Set whether to expose the listener JMS Session to a registeredSessionAwareMessageListener
as well as toJmsTemplate
calls.Default is "true", reusing the listener's
Session
. Turn this off to expose a fresh JMS Session fetched from the same underlying JMSConnection
instead, which might be necessary on some JMS providers.Note that Sessions managed by an external transaction manager will always get exposed to
JmsTemplate
calls. So in terms of JmsTemplate exposure, this setting only affects locally transacted Sessions.
isExposeListenerSession
public boolean isExposeListenerSession()
Return whether to expose the listener JMSSession
to 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()
从类复制的说明:AbstractJmsListeningContainer
Validate the configuration of this container.The default implementation is empty. To be overridden in subclasses.
setupMessageListener
public void setupMessageListener(Object messageListener)
从接口复制的说明:MessageListenerContainer
Setup the message listener to use. Throws anIllegalArgumentException
if that message listener type is not supported.
executeListener
protected void executeListener(Session session, Message message)
Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).- 参数:
session
- the JMS Session to operate onmessage
- the received JMS Message- 另请参阅:
invokeListener(javax.jms.Session, javax.jms.Message)
,commitIfNecessary(javax.jms.Session, javax.jms.Message)
,rollbackOnExceptionIfNecessary(javax.jms.Session, java.lang.Throwable)
,handleListenerException(java.lang.Throwable)
doExecuteListener
protected void doExecuteListener(Session session, Message message) throws JMSException
Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).- 参数:
session
- the JMS Session to operate onmessage
- the received JMS Message- 抛出:
JMSException
- if thrown by JMS API methods- 另请参阅:
invokeListener(javax.jms.Session, javax.jms.Message)
,commitIfNecessary(javax.jms.Session, javax.jms.Message)
,rollbackOnExceptionIfNecessary(javax.jms.Session, java.lang.Throwable)
,JmsAccessor.convertJmsAccessException(javax.jms.JMSException)
invokeListener
protected void invokeListener(Session session, Message message) throws JMSException
Invoke the specified listener: either as standard JMS MessageListener or (preferably) as Spring SessionAwareMessageListener.- 参数:
session
- the JMS Session to operate onmessage
- the received JMS Message- 抛出:
JMSException
- if thrown by JMS API methods- 另请参阅:
setMessageListener(java.lang.Object)
doInvokeListener
protected void doInvokeListener(SessionAwareMessageListener listener, Session session, Message message) throws JMSException
Invoke the specified listener as Spring SessionAwareMessageListener, exposing a new JMS Session (potentially with its own transaction) to the listener if demanded.- 参数:
listener
- the Spring SessionAwareMessageListener to invokesession
- the JMS Session to operate onmessage
- the received JMS Message- 抛出:
JMSException
- if thrown by JMS API methods- 另请参阅:
SessionAwareMessageListener
,setExposeListenerSession(boolean)
doInvokeListener
protected void doInvokeListener(MessageListener listener, Message message) throws JMSException
Invoke the specified listener as standard JMS MessageListener.Default implementation performs a plain invocation of the
onMessage
method.- 参数:
listener
- the JMS MessageListener to invokemessage
- the received JMS Message- 抛出:
JMSException
- if thrown by JMS API methods- 另请参阅:
MessageListener.onMessage(javax.jms.Message)
commitIfNecessary
protected void commitIfNecessary(Session session, Message message) throws JMSException
Perform a commit or message acknowledgement, as appropriate.- 参数:
session
- the JMS Session to commitmessage
- the Message to acknowledge- 抛出:
JMSException
- in case of commit failure
rollbackIfNecessary
protected void rollbackIfNecessary(Session session) throws JMSException
Perform a rollback, if appropriate.- 参数:
session
- the JMS Session to rollback- 抛出:
JMSException
- in case of a rollback error
rollbackOnExceptionIfNecessary
protected void rollbackOnExceptionIfNecessary(Session session, Throwable ex) throws JMSException
Perform a rollback, handling rollback exceptions properly.- 参数:
session
- the JMS Session to rollbackex
- the thrown application exception or error- 抛出:
JMSException
- in case of a rollback error
isSessionLocallyTransacted
protected boolean isSessionLocallyTransacted(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.
- 参数:
session
- the Session to check- 返回:
- whether the given Session is locally transacted
- 另请参阅:
JmsAccessor.isSessionTransacted()
,ConnectionFactoryUtils.isSessionTransactional(javax.jms.Session, javax.jms.ConnectionFactory)
createConsumer
protected MessageConsumer createConsumer(Session session, Destination destination) throws JMSException
Create a JMS MessageConsumer for the given Session and Destination.This implementation uses JMS 1.1 API.
- 参数:
session
- the JMS Session to create a MessageConsumer fordestination
- the JMS Destination to create a MessageConsumer for- 返回:
- the new JMS MessageConsumer
- 抛出:
JMSException
- if thrown by JMS API methods
handleListenerException
protected void handleListenerException(Throwable ex)
Handle the given exception that arose during listener execution.The default implementation logs the exception at warn level, 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.
- 参数:
ex
- the exception to handle
invokeExceptionListener
protected void invokeExceptionListener(JMSException ex)
Invoke the registered JMS ExceptionListener, if any.- 参数:
ex
- the exception that arose during JMS processing- 另请参阅:
setExceptionListener(javax.jms.ExceptionListener)
invokeErrorHandler
protected void invokeErrorHandler(Throwable ex)
Invoke the registered ErrorHandler, if any. Log at warn level otherwise.- 参数:
ex
- the uncaught error that arose during JMS processing.- 另请参阅:
setErrorHandler(org.springframework.util.ErrorHandler)