Spring Integration

org.springframework.integration.core
Interface PseudoTransactionalMessageSource<T,V>

All Superinterfaces:
MessageSource<T>
All Known Implementing Classes:
MailReceivingMessageSource, MongoDbMessageSource, RedisStoreMessageSource

public interface PseudoTransactionalMessageSource<T,V>
extends MessageSource<T>

MessageSources implementing this sub-interface can participate in a Spring transaction. While the underlying resource is not strictly transactional, the final disposition of the resource will be synchronized with any encompassing transaction. For example, when a message source is used with a transactional poller, if any upstream activity causes the transaction to roll back, then the afterRollback(Object) method will be called, allowing the message source to reset the state of whatever. If the transaction commits, the afterCommit(Object) method is called.

For example, with a MailReceivingMessageSource, the email can be deleted on successful commit, but not deleted if the transaction rolls back.

This implements the 'Best Chance 1PC' pattern where there is only a small (but present) window in which a transaction might commit but the resource is not updated to reflect that. This could result in duplicate messages.

All MessageSources can have success/failure expressions evaluated either as part of a transaction with a <transactional/> poller or after success/failure when running in a <pseudo-transactional/> poller. This interface is for those message sources that need additional flexibility than that provided by SpEL expressions.

Since:
2.2
Author:
Gary Russell

Method Summary
 void afterCommit(java.lang.Object object)
          Invoked via TransactionSynchronization when the transaction commits.
 void afterReceiveNoTx(V resource)
          Called when there is no transaction and the receive() call completed.
 void afterRollback(java.lang.Object object)
          Invoked via TransactionSynchronization when the transaction rolls back.
 void afterSendNoTx(V resource)
          Called when there is no transaction and after the message was sent to the channel.
 V getResource()
          Obtain the resource on which appropriate action needs to be taken.
 
Methods inherited from interface org.springframework.integration.core.MessageSource
receive
 

Method Detail

getResource

V getResource()
Obtain the resource on which appropriate action needs to be taken. This resource is passed back into the other methods. In addition, it is made available to transaction synchronization SpEL expressions in the '#resource' variable.

Returns:
The resource.

afterCommit

void afterCommit(java.lang.Object object)
Invoked via TransactionSynchronization when the transaction commits.

Parameters:
object - The resource to be "committed"

afterRollback

void afterRollback(java.lang.Object object)
Invoked via TransactionSynchronization when the transaction rolls back.

Parameters:
object -

afterReceiveNoTx

void afterReceiveNoTx(V resource)
Called when there is no transaction and the receive() call completed.

Parameters:
resource -

afterSendNoTx

void afterSendNoTx(V resource)
Called when there is no transaction and after the message was sent to the channel.

Parameters:
resource -

Spring Integration