Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » jms » listener » [javadoc | source]
org.springframework.jms.listener
abstract public class: AbstractMessageListenerContainer [javadoc | source]
java.lang.Object
   org.springframework.jms.support.JmsAccessor
      org.springframework.jms.support.destination.JmsDestinationAccessor
         org.springframework.jms.listener.AbstractJmsListeningContainer
            org.springframework.jms.listener.AbstractMessageListenerContainer

All Implemented Interfaces:
    DisposableBean, BeanNameAware, Lifecycle, InitializingBean

Direct Known Subclasses:
    ServerSessionMessageListenerContainer, SimpleMessageListenerContainer, AbstractPollingMessageListenerContainer, DefaultMessageListenerContainer, DefaultMessageListenerContainer102, ServerSessionMessageListenerContainer102, SimpleMessageListenerContainer102

Abstract base class for message listener containers. Can either host a standard JMS javax.jms.MessageListener or a Spring-specific SessionAwareMessageListener .

Usually holds a single JMS Connection that all listeners are supposed to be registered on, which is the standard JMS way of managing listeners. Can alternatively also be used with a fresh Connection per listener, for J2EE-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.

The listener container offers the following message acknowledgment options:

The exact behavior might vary according to the concrete listener container and JMS provider used. 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 and rollback the active transaction if there is one. This means that from the perspective of the attendant JMS provider no listener will ever fail.

There are two solutions to the duplicate processing problem:

Note that XA transaction coordination adds significant runtime overhead, so it might be feasible to avoid it unless absolutely necessary.

Recommendations:

Note that it is also possible to specify a org.springframework.jms.connection.JmsTransactionManager as external "transactionManager", providing fully synchronized Spring transactions based on local JMS transactions. The effect is similar to "sessionTransacted" set to "true", the difference being that this external transaction management will also affect independent JMS access code within the service layer (e.g. based on org.springframework.jms.core.JmsTemplate or org.springframework.jms.connection.TransactionAwareConnectionFactoryProxy ), not just direct JMS Session usage in a SessionAwareMessageListener .

Fields inherited from org.springframework.jms.listener.AbstractJmsListeningContainer:
sharedConnectionMonitor,  lifecycleMonitor
Fields inherited from org.springframework.jms.support.JmsAccessor:
logger
Method from org.springframework.jms.listener.AbstractMessageListenerContainer Summary:
checkMessageListener,   commitIfNecessary,   doExecuteListener,   doInvokeListener,   doInvokeListener,   executeListener,   getDestination,   getDestinationName,   getDurableSubscriptionName,   getExceptionListener,   getMessageListener,   getMessageSelector,   handleListenerException,   invokeExceptionListener,   invokeListener,   isAcceptMessagesWhileStopping,   isExposeListenerSession,   isSessionLocallyTransacted,   isSubscriptionDurable,   rollbackIfNecessary,   rollbackOnExceptionIfNecessary,   setAcceptMessagesWhileStopping,   setDestination,   setDestinationName,   setDurableSubscriptionName,   setExceptionListener,   setExposeListenerSession,   setMessageListener,   setMessageSelector,   setSubscriptionDurable,   validateConfiguration
Methods from org.springframework.jms.listener.AbstractJmsListeningContainer:
afterPropertiesSet,   createSharedConnection,   destroy,   doInitialize,   doRescheduleTask,   doShutdown,   doStart,   doStop,   establishSharedConnection,   getBeanName,   getClientId,   getPausedTaskCount,   getSharedConnection,   initialize,   isActive,   isRunning,   logRejectedTask,   prepareSharedConnection,   refreshSharedConnection,   rescheduleTaskIfNecessary,   resumePausedTasks,   runningAllowed,   setAutoStartup,   setBeanName,   setClientId,   sharedConnectionEnabled,   shutdown,   start,   startSharedConnection,   stop,   stopSharedConnection,   validateConfiguration,   waitWhileNotRunning
Methods from org.springframework.jms.support.destination.JmsDestinationAccessor:
getDestinationResolver,   isPubSubDomain,   resolveDestinationName,   setDestinationResolver,   setPubSubDomain
Methods from org.springframework.jms.support.JmsAccessor:
afterPropertiesSet,   convertJmsAccessException,   createConnection,   createSession,   getConnectionFactory,   getSessionAcknowledgeMode,   isClientAcknowledge,   isSessionTransacted,   setConnectionFactory,   setSessionAcknowledgeMode,   setSessionAcknowledgeModeName,   setSessionTransacted
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.jms.listener.AbstractMessageListenerContainer Detail:
 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 Spring SessionAwareMessageListener object will be accepted.

 protected  void commitIfNecessary(Session session,
    Message message) throws JMSException 
    Perform a commit or message acknowledgement, as appropriate.
 protected  void doExecuteListener(Session session,
    Message message) throws JMSException 
    Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).
 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.

 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.
 protected  void executeListener(Session session,
    Message message) 
    Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).
 public Destination getDestination() 
 public String getDestinationName() 
 public String getDurableSubscriptionName() 
    Return the name of a durable subscription to create, if any.
 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.
 public Object getMessageListener() 
    Return the message listener object to register.
 public String getMessageSelector() 
    Return the JMS message selector expression (or null if none).
 protected  void handleListenerException(Throwable ex) 
    Handle the given exception that arose during listener execution.

    The default implementation logs the exception at error 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.

 protected  void invokeExceptionListener(JMSException ex) 
    Invoke the registered JMS ExceptionListener, if any.
 protected  void invokeListener(Session session,
    Message message) throws JMSException 
    Invoke the specified listener: either as standard JMS MessageListener or (preferably) as Spring SessionAwareMessageListener.
 public boolean isAcceptMessagesWhileStopping() 
    Return whether to accept received messages while the listener container in the process of stopping.
 public boolean isExposeListenerSession() 
 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.

 public boolean isSubscriptionDurable() 
    Return whether to make the subscription durable.
 protected  void rollbackIfNecessary(Session session) throws JMSException 
    Perform a rollback, if appropriate.
 protected  void rollbackOnExceptionIfNecessary(Session session,
    Throwable ex) throws JMSException 
    Perform a rollback, handling rollback exceptions properly.
 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.

 public  void setDestination(Destination destination) 
    Set the destination to receive messages from.

    Alternatively, specify a "destinationName", to be dynamically resolved via the org.springframework.jms.support.destination.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!

 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!

 public  void setDurableSubscriptionName(String durableSubscriptionName) 
    Set the name of a durable subscription to create. To be applied in case of a topic (pub-sub domain) with subscription durability activated.

    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.

 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.
 public  void setExposeListenerSession(boolean exposeListenerSession) 
 public  void setMessageListener(Object messageListener) 
    Set the message listener implementation to register. This can be either a standard JMS MessageListener object or a Spring SessionAwareMessageListener 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!

 public  void setMessageSelector(String messageSelector) 
    Set the JMS message selector expression (or null 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!

 public  void setSubscriptionDurable(boolean subscriptionDurable) 
    Set whether to make the subscription durable. The durable subscription name to be used can be specified through the "durableSubscriptionName" property.

    Default is "false". Set this to "true" to register a durable subscription, typically in combination with a "durableSubscriptionName" value (unless your message listener class name is good enough as subscription name).

    Only makes sense when listening to a topic (pub-sub domain).

 protected  void validateConfiguration()