Class JmsMatsTransactionManager_JmsAndJdbc
- All Implemented Interfaces:
JmsMatsStatics
,JmsMatsTransactionManager
JmsMatsTransactionManager
that in addition to the JMS transaction also handles a JDBC SQL
Connection
(using only pure java, i.e. no Spring) for which it keeps transaction demarcation along with the
JMS transaction, by means of "Best Effort 1 Phase Commit":
- JMS transaction is entered (a transactional JMS Connection is always within a transaction)
- JMS Message is retrieved.
- SQL transaction is entered
- Code is executed, including SQL statements.
- SQL transaction is committed - Any errors also rollbacks the JMS Transaction, so that none of them have happened.
- JMS transaction is committed.
JmsMatsTransactionManager_Jms
) - and then the Message Broker will probably try to redeliver the message. Also
read the Should I use XA Transactions from Apache
Active MQ.
Wise tip when working with Message Oriented Middleware: Code idempotent! Handle double-deliveries!
The transactionally demarcated SQL Connection can be retrieved from user code using
ProcessContext.getAttribute(Connection.class)
.
It requires a DataSource
upon construction. The DataSource
will be asked for a SQL Connection in any
MatsStage's StageProcessor that requires it: The fetching of the SQL Connection is lazy in that it won't be retrieved
(nor entered into transaction with), until it is actually requested by the user code by means of
ProcessContext.getAttribute(Connection.class)
.
The SQL Connection will be closed
after each stage processing (after each transaction,
either committed or rollbacked) - if it was requested during the user code.
This implementation will not perform any Connection reuse (caching/pooling). It is up to the supplier to implement any pooling, or make use of a pooled DataSource, if so desired. (Which definitely should be desired, due to the heavy use of "get new - use - commit/rollback - close".)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
TheJmsMatsTransactionManager.TransactionContext
-implementation forJmsMatsTransactionManager_Jms
.Nested classes/interfaces inherited from class io.mats3.impl.jms.JmsMatsTransactionManager_Jms
JmsMatsTransactionManager_Jms.TransactionalContext_Jms
Nested classes/interfaces inherited from interface io.mats3.impl.jms.JmsMatsTransactionManager
JmsMatsTransactionManager.JmsMatsTxContextKey, JmsMatsTransactionManager.ProcessingLambda, JmsMatsTransactionManager.TransactionContext
-
Field Summary
Fields inherited from interface io.mats3.impl.jms.JmsMatsStatics
EXTRA_GRACE_MILLIS, ILLEGAL_CALL_FLOWS, JMS_MSG_PROP_AUDIT, JMS_MSG_PROP_DISPATCH_TYPE, JMS_MSG_PROP_FROM, JMS_MSG_PROP_INITIALIZING_APP, JMS_MSG_PROP_INITIATOR_ID, JMS_MSG_PROP_MATS_MESSAGE_ID, JMS_MSG_PROP_MESSAGE_TYPE, JMS_MSG_PROP_TO, JMS_MSG_PROP_TRACE_ID, LOG_PREFIX, MAX_STACK_HEIGHT, MAX_TOTAL_CALL_NUMBER, MDC_MATS_APP_NAME, MDC_MATS_APP_VERSION, MDC_MATS_CALL_NUMBER, MDC_MATS_IN_MESSAGE_SYSTEM_ID, MDC_MATS_INIT, MDC_MATS_OUT_MATS_MESSAGE_ID, MDC_MATS_STAGE, MDC_MATS_STAGE_ID, MDC_MATS_STAGE_INDEX, MDC_TRACE_ID, NO_INVOCATION_POINT, RANDOM_ALPHABET, THREAD_PREFIX, TOTAL_JMS_MSG_PROPS_SIZE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
JmsMatsTransactionManager_JmsAndJdbc
(DataSource dataSource) -
Method Summary
Modifier and TypeMethodDescriptioncreate
(DataSource dataSource) Provides an implementation ofJmsMatsTransactionManager.TransactionContext
.Methods inherited from class io.mats3.impl.jms.JmsMatsTransactionManager_Jms
create
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.mats3.impl.jms.JmsMatsStatics
createFlowId, getInvocationPoint, id, id, idThis, ms3, produceAndSendMsgSysMessages, randomString, setConcurrencyWithLog, stageOrInit
-
Constructor Details
-
JmsMatsTransactionManager_JmsAndJdbc
-
-
Method Details
-
create
-
getTransactionContext
public JmsMatsTransactionManager.TransactionContext getTransactionContext(JmsMatsTransactionManager.JmsMatsTxContextKey txContextKey) Description copied from interface:JmsMatsTransactionManager
Provides an implementation ofJmsMatsTransactionManager.TransactionContext
. (JMS Connection and Session handling is done byJmsMatsJmsSessionHandler
).- Specified by:
getTransactionContext
in interfaceJmsMatsTransactionManager
- Overrides:
getTransactionContext
in classJmsMatsTransactionManager_Jms
- Parameters:
txContextKey
- for whichJmsMatsStage
orJmsMatsInitiator
this request forJmsMatsTransactionManager.TransactionContext
is for.- Returns:
- a
JmsMatsTransactionManager.TransactionContext
for the supplied txContextKey.
-