The Spring Framework

org.springframework.jms.listener
Class SimpleMessageListenerContainer

java.lang.Object
  extended by org.springframework.jms.support.JmsAccessor
      extended by org.springframework.jms.support.destination.JmsDestinationAccessor
          extended by org.springframework.jms.listener.AbstractMessageListenerContainer
              extended by org.springframework.jms.listener.SimpleMessageListenerContainer
All Implemented Interfaces:
DisposableBean, InitializingBean, Lifecycle
Direct Known Subclasses:
SimpleMessageListenerContainer102

public class SimpleMessageListenerContainer
extends AbstractMessageListenerContainer

Message listener container that the plain JMS client API's MessageConsumer.setMessageListener() method to create concurrent MessageConsumers for the specified listeners.

This is the simplest form of a message listener container. It creates a fixed number of JMS Sessions to invoke the listener, not allowing for dynamic adaptation to runtime demands. Its main advantage is its low level of complexity and the minimum requirements on the JMS provider: Not even the ServerSessionPool facility is required.

See the AbstractMessageListenerContainer javadoc for details on acknowledge modes and transaction options.

For a different style of MessageListener handling, through looped MessageConsumer.receive() calls that also allow for transactional reception of messages (registering them with XA transactions), see DefaultMessageListenerContainer. For dynamic adaptation of the active number of Sessions, consider using ServerSessionMessageListenerContainer.

This class requires a JMS 1.1+ provider, because it builds on the domain-independent API. Use the SimpleMessageListenerContainer102 subclass for JMS 1.0.2 providers.

Since:
2.0
Author:
Juergen Hoeller
See Also:
MessageConsumer.setMessageListener(javax.jms.MessageListener), DefaultMessageListenerContainer, ServerSessionMessageListenerContainer, SimpleMessageListenerContainer102

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.jms.listener.AbstractMessageListenerContainer
AbstractMessageListenerContainer.SharedConnectionNotInitializedException
 
Field Summary
 
Fields inherited from class org.springframework.jms.support.JmsAccessor
logger
 
Constructor Summary
SimpleMessageListenerContainer()
           
 
Method Summary
 void afterPropertiesSet()
          Validates this instance's configuration.
protected  MessageConsumer createConsumer(Session session, Destination destination)
          Create a JMS MessageConsumer for the given Session and Destination.
protected  MessageConsumer createListenerConsumer(Session session)
          Create a MessageConsumer for the given JMS Session, registering a MessageListener for the specified listener.
protected  void destroyListener()
          Destroy the registered JMS Sessions and associated MessageConsumers.
protected  boolean isPubSubNoLocal()
          Return whether to inhibit the delivery of messages published by its own connection.
protected  void registerListener()
          Creates the specified number of concurrent consumers, in the form of a JMS Session plus associated MessageConsumer.
 void setConcurrentConsumers(int concurrentConsumers)
          Specify the number of concurrent consumers to create.
 void setPubSubNoLocal(boolean pubSubNoLocal)
          Set whether to inhibit the delivery of messages published by its own connection.
 void setTaskExecutor(TaskExecutor taskExecutor)
          Set the Spring TaskExecutor to use for executing the listeners.
protected  boolean sharedConnectionEnabled()
          Always use a shared JMS Connection.
 
Methods inherited from class org.springframework.jms.listener.AbstractMessageListenerContainer
checkMessageListener, commitIfNecessary, createConnection, createSession, destroy, doExecuteListener, doInvokeListener, doInvokeListener, doRescheduleTask, doStart, doStop, establishSharedConnection, executeListener, getClientId, getDestination, getDestinationName, getDurableSubscriptionName, getExceptionListener, getMessageListener, getMessageSelector, getSharedConnection, handleListenerException, initialize, invokeExceptionListener, invokeListener, isActive, isClientAcknowledge, isExposeListenerSession, isRunning, isSubscriptionDurable, prepareSharedConnection, refreshSharedConnection, rescheduleTaskIfNecessary, rollbackOnExceptionIfNecessary, setAutoStartup, setClientId, setDestination, setDestinationName, setDurableSubscriptionName, setExceptionListener, setExposeListenerSession, setMessageListener, setMessageSelector, setSubscriptionDurable, shutdown, start, startSharedConnection, stop, stopSharedConnection, waitWhileNotRunning
 
Methods inherited from class org.springframework.jms.support.destination.JmsDestinationAccessor
getDestinationResolver, isPubSubDomain, resolveDestinationName, setDestinationResolver, setPubSubDomain
 
Methods inherited from class org.springframework.jms.support.JmsAccessor
convertJmsAccessException, getConnectionFactory, getSessionAcknowledgeMode, isSessionTransacted, setConnectionFactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransacted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleMessageListenerContainer

public SimpleMessageListenerContainer()
Method Detail

setPubSubNoLocal

public void setPubSubNoLocal(boolean pubSubNoLocal)
Set whether to inhibit the delivery of messages published by its own connection. Default is "false".

See Also:
TopicSession.createSubscriber(javax.jms.Topic, String, boolean)

isPubSubNoLocal

protected boolean isPubSubNoLocal()
Return whether to inhibit the delivery of messages published by its own connection.


setConcurrentConsumers

public void setConcurrentConsumers(int concurrentConsumers)
Specify the number of concurrent consumers to create. Default is 1.


setTaskExecutor

public void setTaskExecutor(TaskExecutor taskExecutor)
Set the Spring TaskExecutor to use for executing the listeners. Default is none, that is, to run in the JMS provider's own receive thread, blocking the provider's receive endpoint while executing the listener.

Specify a TaskExecutor for integration with an existing thread pool, executing the listener with a received message in a different thread - taken from the thread pool, rather than blocking the JMS provider.

See Also:
setConcurrentConsumers(int), SimpleAsyncTaskExecutor, WorkManagerTaskExecutor

afterPropertiesSet

public void afterPropertiesSet()
Validates this instance's configuration.

Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class AbstractMessageListenerContainer
See Also:
AbstractMessageListenerContainer.initialize()

sharedConnectionEnabled

protected final boolean sharedConnectionEnabled()
Always use a shared JMS Connection.

Specified by:
sharedConnectionEnabled in class AbstractMessageListenerContainer
See Also:
AbstractMessageListenerContainer.getSharedConnection()

registerListener

protected void registerListener()
                         throws JMSException
Creates the specified number of concurrent consumers, in the form of a JMS Session plus associated MessageConsumer.

Specified by:
registerListener in class AbstractMessageListenerContainer
Throws:
JMSException - if registration failed
See Also:
createListenerConsumer(javax.jms.Session)

createListenerConsumer

protected MessageConsumer createListenerConsumer(Session session)
                                          throws JMSException
Create a MessageConsumer for the given JMS Session, registering a MessageListener for the specified listener.

Parameters:
session - the JMS Session to work on
Returns:
the MessageConsumer
Throws:
JMSException - if thrown by JMS methods
See Also:
AbstractMessageListenerContainer.executeListener(javax.jms.Session, javax.jms.Message)

destroyListener

protected void destroyListener()
                        throws JMSException
Destroy the registered JMS Sessions and associated MessageConsumers.

Specified by:
destroyListener in class AbstractMessageListenerContainer
Throws:
JMSException - if destruction failed

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.

Parameters:
session - the JMS Session to create a MessageConsumer for
destination - the JMS Destination to create a MessageConsumer for
Returns:
the new JMS MessageConsumer
Throws:
JMSException - if thrown by JMS API methods

The Spring Framework

Copyright © 2002-2006 The Spring Framework.