public class BatchedJmsTemplate extends org.springframework.jms.core.JmsTemplate
JmsTemplate
with additional methods that enable multiple items to be processed in a single transaction for the various supported operations. The
additional methods are identified by the suffix 'batch'.
As with BatchedMessageListenerContainer
, Within each transaction, the first read is a blocking read, that blocks for JmsTemplate.setReceiveTimeout(long)
. Subsequent messages up to
the maximum batch size setBatchSize(int)
are read as non-blocking reads, with the batch completing as soon as the queue cannot service further messages.
Users of this class must handle rollback appropriately. A rollback triggered by failure processing a single message will cause all the messages in the transaction to rollback. It is recommended to
design you message processing so that rollback only occurs for fatal, unexpected and unrecoverable errors such as a failure in the infrastructure. You should handle other errors by, for example,
delivering messages directly to an error queue rather than throwing an exception. To assist in constructing this pattern, the AbstractMessageDriven
POJO is also provided which provides the
basic framework for implementing a MessageListener
that is aligned with this contract.
NB. Due to the design and structure of Spring's DefaultMessageListenerContainer
and its superclasses, implementing this class must by necessity duplicate certain parts of
DefaultMessageListenerContainer
. Consequently, this class has been managed at a source code level as a derivative of DefaultMessageListenerContainer
and copyright messages and
attributions reflect this.
JmsTemplate
. Modifications to this class to enable batching were made by Chris Pheby.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BATCH_SIZE
The default maximum size for a transactional batch
|
Constructor and Description |
---|
BatchedJmsTemplate()
Creates a new instance
|
Modifier and Type | Method and Description |
---|---|
protected List<javax.jms.Message> |
doBatchReceive(javax.jms.Session session,
javax.jms.Destination destination,
String messageSelector,
int batchSize) |
protected List<javax.jms.Message> |
doBatchReceive(javax.jms.Session session,
javax.jms.MessageConsumer consumer,
int batchSize) |
protected javax.jms.Message |
doSingleReceive(javax.jms.Session session,
javax.jms.Destination destination,
String messageSelector) |
protected javax.jms.Message |
doSingleReceive(javax.jms.Session session,
javax.jms.MessageConsumer consumer) |
int |
getBatchSize()
Get the maximum number of messages that can be read in a transaction
|
javax.jms.Message |
receive() |
javax.jms.Message |
receive(javax.jms.Destination destination) |
javax.jms.Message |
receive(String destinationName) |
List<Object> |
receiveAndConvertBatch()
Receive a batch of up to default batch size for default destination and convert each message in the batch.
|
List<Object> |
receiveAndConvertBatch(javax.jms.Destination destination)
Receive a batch of up to default batch size for the given Destination and convert each message in the batch.
|
List<Object> |
receiveAndConvertBatch(javax.jms.Destination destination,
int batchSize)
Receive a batch of up to batchSize for given Destination and convert each message in the batch.
|
List<Object> |
receiveAndConvertBatch(int batchSize)
Receive a batch of up to batchSize for default destination and convert each message in the batch.
|
List<Object> |
receiveAndConvertBatch(String destinationName)
Receive a batch of up to default batch size for given destination name and convert each message in the batch.
|
List<Object> |
receiveAndConvertBatch(String destinationName,
int batchSize)
Receive a batch of up to batchSize for given destination name and convert each message in the batch.
|
List<javax.jms.Message> |
receiveBatch()
Receive a batch of up to default batch size for the default destination.
|
List<javax.jms.Message> |
receiveBatch(javax.jms.Destination destination)
Receive a batch of up to default batch size for given destination.
|
List<javax.jms.Message> |
receiveBatch(javax.jms.Destination destination,
int batchSize)
Receive a batch of up to batchSize for given destination.
|
List<javax.jms.Message> |
receiveBatch(int batchSize)
Receive a batch of up to batchSize.
|
List<javax.jms.Message> |
receiveBatch(String destinationName)
Receive a batch of up to default batch size for given destinationName.
|
List<javax.jms.Message> |
receiveBatch(String destinationName,
int batchSize)
Receive a batch of up to default batch size for given destination.
|
javax.jms.Message |
receiveSelected(javax.jms.Destination destination,
String messageSelector) |
javax.jms.Message |
receiveSelected(String messageSelector) |
javax.jms.Message |
receiveSelected(String destinationName,
String messageSelector) |
List<Object> |
receiveSelectedAndConvertBatch(javax.jms.Destination destination,
String messageSelector)
Receive a batch of up to default batch size for given Destination and message selector and convert each message in the batch.
|
List<Object> |
receiveSelectedAndConvertBatch(javax.jms.Destination destination,
String messageSelector,
int batchSize)
Receive a batch of up to batchSize for given Destination and message selector and convert each message in the batch.
|
List<Object> |
receiveSelectedAndConvertBatch(String messageSelector)
Receive a batch of up to default batch size for default destination and message selector and convert each message in the batch.
|
List<Object> |
receiveSelectedAndConvertBatch(String messageSelector,
int batchSize)
Receive a batch of up to batchSize for default destination and message selector and convert each message in the batch.
|
List<Object> |
receiveSelectedAndConvertBatch(String destinationName,
String messageSelector)
Receive a batch of up to default batch size for given destination name and message selector and convert each message in the batch.
|
List<Object> |
receiveSelectedAndConvertBatch(String destinationName,
String messageSelector,
int batchSize)
Receive a batch of up to batchSize for given destination name and message selector and convert each message in the batch.
|
List<javax.jms.Message> |
receiveSelectedBatch(javax.jms.Destination destination,
String messageSelector)
Receive a batch of up to default batch size for given destination and message selector.
|
List<javax.jms.Message> |
receiveSelectedBatch(javax.jms.Destination destination,
String messageSelector,
int batchSize)
Receive a batch of up to batchSize for given destination and message selector.
|
List<javax.jms.Message> |
receiveSelectedBatch(String messageSelector)
Receive a batch of up to default batch size for default destination and given message selector.
|
List<javax.jms.Message> |
receiveSelectedBatch(String messageSelector,
int batchSize)
Receive a batch of up to batchSize for default destination and given message selector.
|
List<javax.jms.Message> |
receiveSelectedBatch(String destinationName,
String messageSelector)
Receive a batch of up to default batch size for given destination name and message selector.
|
List<javax.jms.Message> |
receiveSelectedBatch(String destinationName,
String messageSelector,
int batchSize)
Receive a batch of up to batchSize for given destination name and message selector.
|
void |
setBatchSize(int batchSize)
Configures the maximum number of messages that can be read in a transaction
|
browse, browse, browse, browseSelected, browseSelected, browseSelected, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, createBrowser, createConsumer, createProducer, doConvertFromMessage, doCreateProducer, doReceive, doReceive, doSend, doSend, doSendAndReceive, execute, execute, execute, execute, execute, getConnection, getDefaultDestination, getDefaultDestinationName, getDeliveryDelay, getDeliveryMode, getMessageConverter, getPriority, getReceiveTimeout, getSession, getTimeToLive, initDefaultStrategies, isExplicitQosEnabled, isMessageIdEnabled, isMessageTimestampEnabled, isPubSubNoLocal, isSessionLocallyTransacted, receiveAndConvert, receiveAndConvert, receiveAndConvert, receiveSelectedAndConvert, receiveSelectedAndConvert, receiveSelectedAndConvert, send, send, send, sendAndReceive, sendAndReceive, sendAndReceive, setDefaultDestination, setDefaultDestinationName, setDeliveryDelay, setDeliveryMode, setDeliveryPersistent, setExplicitQosEnabled, setMessageConverter, setMessageIdEnabled, setMessageTimestampEnabled, setPriority, setPubSubNoLocal, setQosSettings, setReceiveTimeout, setTimeToLive
getDestinationResolver, isPubSubDomain, receiveFromConsumer, resolveDestinationName, setDestinationResolver, setPubSubDomain
afterPropertiesSet, convertJmsAccessException, createConnection, createSession, getConnectionFactory, getSessionAcknowledgeMode, isClientAcknowledge, isSessionTransacted, obtainConnectionFactory, setConnectionFactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransacted
public static final int DEFAULT_BATCH_SIZE
public BatchedJmsTemplate()
public void setBatchSize(int batchSize)
batchSize
- The maximum batch sizepublic int getBatchSize()
public List<javax.jms.Message> receiveBatch() throws org.springframework.jms.JmsException
JmsTemplate.receive()
Message
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveBatch(int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receive()
batchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveBatch(javax.jms.Destination destination) throws org.springframework.jms.JmsException
JmsTemplate.receive(Destination)
destination
- The DestinationMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveBatch(javax.jms.Destination destination, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receive(Destination)
destination
- The DestinationbatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveBatch(String destinationName) throws org.springframework.jms.JmsException
JmsTemplate.receive(String)
destinationName
- The Destination nameMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveBatch(String destinationName, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receive(String)
destinationName
- The DestinationbatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveSelectedBatch(String messageSelector) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelected(String)
messageSelector
- The SelectorMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveSelectedBatch(String messageSelector, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelected(String)
messageSelector
- The SelectorbatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveSelectedBatch(javax.jms.Destination destination, String messageSelector) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelected(Destination, String)
destination
- The DestinationmessageSelector
- The SelectorMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveSelectedBatch(javax.jms.Destination destination, String messageSelector, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelected(Destination, String)
destination
- The DestinationmessageSelector
- The SelectorbatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveSelectedBatch(String destinationName, String messageSelector) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelected(String, String)
destinationName
- The destination namemessageSelector
- The SelectorMessage
org.springframework.jms.JmsException
- The JmsException
public List<javax.jms.Message> receiveSelectedBatch(String destinationName, String messageSelector, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelected(String, String)
destinationName
- The destination namemessageSelector
- The SelectorbatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveAndConvertBatch() throws org.springframework.jms.JmsException
JmsTemplate.receiveAndConvert()
Message
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveAndConvertBatch(int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receiveAndConvert()
batchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveAndConvertBatch(javax.jms.Destination destination) throws org.springframework.jms.JmsException
JmsTemplate.receiveAndConvert(Destination)
destination
- The DestinationMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveAndConvertBatch(javax.jms.Destination destination, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receiveAndConvert(Destination)
destination
- The DestinationbatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveAndConvertBatch(String destinationName) throws org.springframework.jms.JmsException
JmsTemplate.receiveAndConvert(String)
destinationName
- The destination nameMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveAndConvertBatch(String destinationName, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receiveAndConvert(String)
destinationName
- The destination namebatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveSelectedAndConvertBatch(String messageSelector) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelectedAndConvert(String)
messageSelector
- The SelectorMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveSelectedAndConvertBatch(String messageSelector, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelectedAndConvert(String)
messageSelector
- The SelectorbatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveSelectedAndConvertBatch(javax.jms.Destination destination, String messageSelector) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelectedAndConvert(Destination, String)
destination
- The DestinationmessageSelector
- The SelectorMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveSelectedAndConvertBatch(javax.jms.Destination destination, String messageSelector, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelectedAndConvert(Destination, String)
destination
- The DestinationmessageSelector
- The SelectorbatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveSelectedAndConvertBatch(String destinationName, String messageSelector) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelectedAndConvert(String, String)
destinationName
- The destination namemessageSelector
- The SelectorMessage
org.springframework.jms.JmsException
- The JmsException
public List<Object> receiveSelectedAndConvertBatch(String destinationName, String messageSelector, int batchSize) throws org.springframework.jms.JmsException
JmsTemplate.receiveSelectedAndConvert(String, String)
destinationName
- The destination namemessageSelector
- The SelectorbatchSize
- The batch sizeMessage
org.springframework.jms.JmsException
- The JmsException
public javax.jms.Message receive() throws org.springframework.jms.JmsException
receive
in interface org.springframework.jms.core.JmsOperations
receive
in class org.springframework.jms.core.JmsTemplate
org.springframework.jms.JmsException
public javax.jms.Message receive(javax.jms.Destination destination) throws org.springframework.jms.JmsException
receive
in interface org.springframework.jms.core.JmsOperations
receive
in class org.springframework.jms.core.JmsTemplate
org.springframework.jms.JmsException
public javax.jms.Message receive(String destinationName) throws org.springframework.jms.JmsException
receive
in interface org.springframework.jms.core.JmsOperations
receive
in class org.springframework.jms.core.JmsTemplate
org.springframework.jms.JmsException
public javax.jms.Message receiveSelected(String messageSelector) throws org.springframework.jms.JmsException
receiveSelected
in interface org.springframework.jms.core.JmsOperations
receiveSelected
in class org.springframework.jms.core.JmsTemplate
org.springframework.jms.JmsException
public javax.jms.Message receiveSelected(javax.jms.Destination destination, String messageSelector) throws org.springframework.jms.JmsException
receiveSelected
in interface org.springframework.jms.core.JmsOperations
receiveSelected
in class org.springframework.jms.core.JmsTemplate
org.springframework.jms.JmsException
public javax.jms.Message receiveSelected(String destinationName, String messageSelector) throws org.springframework.jms.JmsException
receiveSelected
in interface org.springframework.jms.core.JmsOperations
receiveSelected
in class org.springframework.jms.core.JmsTemplate
org.springframework.jms.JmsException
protected List<javax.jms.Message> doBatchReceive(javax.jms.Session session, javax.jms.Destination destination, String messageSelector, int batchSize) throws javax.jms.JMSException
javax.jms.JMSException
protected List<javax.jms.Message> doBatchReceive(javax.jms.Session session, javax.jms.MessageConsumer consumer, int batchSize) throws javax.jms.JMSException
javax.jms.JMSException
protected javax.jms.Message doSingleReceive(javax.jms.Session session, javax.jms.Destination destination, String messageSelector) throws javax.jms.JMSException
javax.jms.JMSException
protected javax.jms.Message doSingleReceive(javax.jms.Session session, javax.jms.MessageConsumer consumer) throws javax.jms.JMSException
javax.jms.JMSException
Copyright © 2010–2018 Jadira Systems. All rights reserved.