java.lang.Object | |||||
↳ | org.springframework.jms.support.JmsAccessor | ||||
↳ | org.springframework.jms.support.destination.JmsDestinationAccessor | ||||
↳ | org.springframework.jms.listener.AbstractJmsListeningContainer | ||||
↳ | org.springframework.jms.listener.AbstractMessageListenerContainer | ||||
↳ | org.springframework.jms.listener.AbstractPollingMessageListenerContainer |
Known Direct Subclasses |
Known Indirect Subclasses |
Base class for listener container implementations which are based on polling. Provides support for listener handling based on javax.jms.MessageConsumer, optionally participating in externally managed transactions.
This listener container variant is built for repeated polling attempts,
each invoking the receiveAndExecute(Object, Session, MessageConsumer)
method. The MessageConsumer used
may be reobtained fo reach attempt or cached inbetween attempts; this is up
to the concrete implementation. The receive timeout for each attempt can be
configured through the "receiveTimeout"
property.
The underlying mechanism is based on standard JMS MessageConsumer handling,
which is perfectly compatible with both native JMS and JMS in a J2EE environment.
Neither the JMS MessageConsumer.setMessageListener
facility
nor the JMS ServerSessionPool facility is required. A further advantage
of this approach is full control over the listening process, allowing for
custom scaling and throttling and of concurrent message processing
(which is up to concrete subclasses).
Message reception and listener execution can automatically be wrapped
in transactions through passing a Spring
PlatformTransactionManager
into the
"transactionManager"
property. This will usually
be a JtaTransactionManager
in a
J2EE enviroment, in combination with a JTA-aware JMS ConnectionFactory obtained
from JNDI (check your J2EE server's documentation).
This base class does not assume any specific mechanism for asynchronous
execution of polling invokers. Check out DefaultMessageListenerContainer
for a concrete implementation which is based on Spring's
TaskExecutor
abstraction,
including dynamic scaling of concurrent consumers and automatic self recovery.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
long | DEFAULT_RECEIVE_TIMEOUT | The default receive timeout: 1000 ms = 1 second. |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jms.listener.AbstractJmsListeningContainer
| |||||||||||
From class
org.springframework.jms.support.JmsAccessor
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Initialize this container.
| |||||||||||
Set whether to inhibit the delivery of messages published by its own connection.
| |||||||||||
Set the timeout to use for receive calls, in milliseconds.
| |||||||||||
Set the transaction mode that is used when creating a JMS Session.
| |||||||||||
Specify the Spring
PlatformTransactionManager
to use for transactional wrapping of message reception plus listener execution. | |||||||||||
Specify the transaction name to use for transactional wrapping.
| |||||||||||
Specify the transaction timeout to use for transactional wrapping, in seconds.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a JMS MessageConsumer for the given Session and Destination.
| |||||||||||
Create a MessageConsumer for the given JMS Session,
registering a MessageListener for the specified listener.
| |||||||||||
Actually execute the listener for a message received from the given consumer,
fetching all requires resources and invoking the listener.
| |||||||||||
Fetch an appropriate Connection from the given JmsResourceHolder.
| |||||||||||
Fetch an appropriate Session from the given JmsResourceHolder.
| |||||||||||
Return the Spring PlatformTransactionManager to use for transactional
wrapping of message reception plus listener execution.
| |||||||||||
Return whether to inhibit the delivery of messages published by its own connection.
| |||||||||||
This implementation checks whether the Session is externally synchronized.
| |||||||||||
Template method that gets called right when a new message has been received,
before attempting to process it.
| |||||||||||
Template method that gets called when no message has been received,
before returning to the receive loop again.
| |||||||||||
Execute the listener for a message received from the given consumer,
wrapping the entire operation in an external transaction if demanded.
| |||||||||||
Receive a message from the given consumer.
| |||||||||||
Determine whether to trigger a commit after no message has been received.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jms.listener.AbstractMessageListenerContainer
| |||||||||||
From class
org.springframework.jms.listener.AbstractJmsListeningContainer
| |||||||||||
From class
org.springframework.jms.support.destination.JmsDestinationAccessor
| |||||||||||
From class
org.springframework.jms.support.JmsAccessor
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.BeanNameAware
| |||||||||||
From interface
org.springframework.beans.factory.DisposableBean
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
| |||||||||||
From interface
org.springframework.context.Lifecycle
| |||||||||||
From interface
org.springframework.context.Phased
| |||||||||||
From interface
org.springframework.context.SmartLifecycle
|
The default receive timeout: 1000 ms = 1 second.
Initialize this container.
Creates a JMS Connection, starts the javax.jms.Connection
(if "autoStartup"
hasn't been turned off),
and calls doInitialize()
.
Set whether to inhibit the delivery of messages published by its own connection. Default is "false".
Set the timeout to use for receive calls, in milliseconds. The default is 1000 ms, that is, 1 second.
NOTE: This value needs to be smaller than the transaction timeout used by the transaction manager (in the appropriate unit, of course). -1 indicates no timeout at all; however, this is only feasible if not running within a transaction manager.
setTransactionTimeout(int)
Set the transaction mode that is used when creating a JMS Session. Default is "false".
Note that within a JTA transaction, the parameters passed to
create(Queue/Topic)Session(boolean transacted, int acknowledgeMode)
method are not taken into account. Depending on the J2EE transaction context,
the container makes its own decisions on these values. Analogously, these
parameters are not taken into account within a locally managed transaction
either, since the accessor operates on an existing JMS Session in this case.
Setting this flag to "true" will use a short local JMS transaction when running outside of a managed transaction, and a synchronized local JMS transaction in case of a managed transaction (other than an XA transaction) being present. The latter has the effect of a local JMS transaction being managed alongside the main transaction (which might be a native JDBC transaction), with the JMS transaction committing right after the main transaction.
Specify the Spring PlatformTransactionManager
to use for transactional wrapping of message reception plus listener execution.
Default is none, not performing any transactional wrapping.
If specified, this will usually be a Spring
JtaTransactionManager
or one
of its subclasses, in combination with a JTA-aware ConnectionFactory that
this message listener container obtains its Connections from.
Note: Consider the use of local JMS transactions instead.
Simply switch the "sessionTransacted"
flag
to "true" in order to use a locally transacted JMS Session for the entire
receive processing, including any Session operations performed by a
SessionAwareMessageListener
(e.g. sending a response message).
Alternatively, a JmsTransactionManager
may be used for fully synchronized Spring transactions based on local JMS
transactions. Check AbstractMessageListenerContainer
's javadoc for
a discussion of transaction choices and message redelivery scenarios.
Specify the transaction name to use for transactional wrapping. Default is the bean name of this listener container, if any.
Specify the transaction timeout to use for transactional wrapping, in seconds. Default is none, using the transaction manager's default timeout.
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 for |
---|---|
destination | the JMS Destination to create a MessageConsumer for |
if thrown by JMS API methods | |
JMSException |
Create a MessageConsumer for the given JMS Session, registering a MessageListener for the specified listener.
session | the JMS Session to work on |
---|
if thrown by JMS methods | |
JMSException |
Actually execute the listener for a message received from the given consumer, fetching all requires resources and invoking the listener.
session | the JMS Session to work on |
---|---|
consumer | the MessageConsumer to work on |
status | the TransactionStatus (may be null ) |
if thrown by JMS methods | |
JMSException |
Fetch an appropriate Connection from the given JmsResourceHolder.
This implementation accepts any JMS 1.1 Connection.
holder | the JmsResourceHolder |
---|
null
if none found
Fetch an appropriate Session from the given JmsResourceHolder.
This implementation accepts any JMS 1.1 Session.
holder | the JmsResourceHolder |
---|
null
if none found
Return the Spring PlatformTransactionManager to use for transactional wrapping of message reception plus listener execution.
Return whether to inhibit the delivery of messages published by its own connection.
This implementation checks whether the Session is externally synchronized. In this case, the Session is not locally transacted, despite the listener container's "sessionTransacted" flag being set to "true".
session | the Session to check |
---|
Template method that gets called right when a new message has been received, before attempting to process it. Allows subclasses to react to the event of an actual incoming message, for example adapting their consumer count.
invoker | the invoker object (passed through) |
---|---|
session | the receiving JMS Session |
Template method that gets called when no message has been received, before returning to the receive loop again. Allows subclasses to react to the event of no incoming message, for example marking the invoker as idle.
invoker | the invoker object (passed through) |
---|---|
session | the receiving JMS Session |
Execute the listener for a message received from the given consumer, wrapping the entire operation in an external transaction if demanded.
session | the JMS Session to work on |
---|---|
consumer | the MessageConsumer to work on |
if thrown by JMS methods | |
JMSException |
Receive a message from the given consumer.
consumer | the MessageConsumer to use |
---|
null
if noneif thrown by JMS methods | |
JMSException |
Determine whether to trigger a commit after no message has been received. This is a good idea on any JMS provider other than Tibco, which is what this default implementation checks for.
session | the current JMS Session which received no message |
---|
commitIfNecessary(Session, Message)
on the given Session