[
https://issues.apache.org/jira/browse/CAMEL-9606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15574220#comment-15574220
]
Tomohisa Igarashi edited comment on CAMEL-9606 at 10/14/16 5:15 AM:
I created an automated unit test and verified it actually is a problem.
https://github.com/igarashitm/issues/blob/master/camel/misc/src/test/java/CamelSjmsTxTest.java
The camel sjms does make Synchronization effort, but it's not really safe.
Sometimes only the producer bit of the
SessionTransactionSynchronization.onComplete() is invoked before terminating a
process, then eventually the consumer side is rolled back (i.e. put back to
queue-in) and the message duplicates. Note that message '0017' is in both of
'test-in' and 'test-out'.
{code}
[ ActiveMQ Session Task-1] sionTransactionSynchronization DEBUG
Processing completion of Exchange
id:ID-localhost-localdomain-44085-1476420609350-0-17
[ ActiveMQ Session Task-1] sionTransactionSynchronization DEBUG
Processing completion of Exchange
id:ID-localhost-localdomain-44085-1476420609350-0-17
[ ActiveMQ Session Task-1] route1 INFO =>
Forwarding a message:[0017] from 'test-in' queue to 'test-out' queue...
[ ActiveMQ Session Task-1] route1 INFO =>
Done.
[ ActiveMQ Session Task-1] sionTransactionSynchronization DEBUG
Processing completion of Exchange
id:ID-localhost-localdomain-44085-1476420609350-0-18
[ main] CamelSjmsTxTestINFO =>
Detroying camel process
[ main] CamelSjmsTxTestINFO
==
[ main] CamelSjmsTxTestINFO Initial,
count=60
[ main] CamelSjmsTxTestINFO
'test-in', count=43 :[0018, 0020, 0022, 0024, 0026, 0028, 0030, 0032,
0034, 0036, 0038, 0040, 0042, 0044, 0046, 0048, 0050, 0052, 0054, 0056, 0058,
0017, 0019, 0021, 0023, 0025, 0027, 0029, 0031, 0033, 0035, 0037, 0039, 0041,
0043, 0045, 0047, 0049, 0051, 0053, 0055, 0057, 0059]
[ main] CamelSjmsTxTestINFO
'test-out', count=18 :[, 0001, 0002, 0003, 0004, 0005, 0006, 0007,
0008, 0009, 0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017]
[ main] CamelSjmsTxTestINFO
==
{code}
The solution would be to let SJMS consumers/producers share a single JMS
session in a Exchange, so that we can just rely on broker implementation to
guarantee transaction atomicity.
was (Author: igarashitm):
I created an automated unit test and verified it actually is a problem.
https://github.com/igarashitm/issues/blob/master/camel/misc/src/test/java/CamelSjmsTxTest.java
The camel sjms does make Synchronization effort, but it's not really safe.
Sometimes only the producer bit of the
SessionTransactionSynchronization.onComplete() is invoked before terminating a
process, then eventually the consumer side is rolled back (i.e. put back to
queue-in) and the message duplicates. Note that message '0017' is in both of
'queue-in' and 'queue-out'.
{code}
[ ActiveMQ Session Task-1] sionTransactionSynchronization DEBUG
Processing completion of Exchange
id:ID-localhost-localdomain-44085-1476420609350-0-17
[ ActiveMQ Session Task-1] sionTransactionSynchronization DEBUG
Processing completion of Exchange
id:ID-localhost-localdomain-44085-1476420609350-0-17
[ ActiveMQ Session Task-1] route1 INFO =>
Forwarding a message:[0017] from 'test-in' queue to 'test-out' queue...
[ ActiveMQ Session Task-1] route1 INFO =>
Done.
[ ActiveMQ Session Task-1] sionTransactionSynchronization DEBUG
Processing completion of Exchange
id:ID-localhost-localdomain-44085-1476420609350-0-18
[ main] CamelSjmsTxTestINFO =>
Detroying camel process
[ main] CamelSjmsTxTestINFO
==
[ main] CamelSjmsTxTestINFO Initial,
count=60
[ main] CamelSjmsTxTestINFO
'test-in', count=43 :[0018, 0020, 0022, 0024, 0026, 0028, 0030, 0032,
0034, 0036, 0038, 0040, 0042, 0044, 0046, 0048, 0050, 0052, 0054, 0056, 0058,
0017, 0019, 0021, 0023, 0025, 0027, 0029, 0031, 0033, 0035, 0037, 0039, 0041,
0043, 0045, 0047, 0049, 0051, 0053, 0055, 0057, 0059]
[ main] CamelSjmsTxTestINFO
'test-out', count=18 :[, 0001, 0002, 0003, 0004, 0005, 0006, 0007,
0008, 0009, 0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017]
[ main] CamelSjmsTxTest