-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MessageConsumer XA Commit and Rollback tests for artemis-jms
Add MessageConsumer XA Commit and Rollback tests Add XA Commit and Rollback tests
- Loading branch information
1 parent
8d262ed
commit 7fb8105
Showing
21 changed files
with
407 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ms/common/src/main/java/io/quarkus/it/artemis/jms/common/ArtemisJmsXaConsumerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.quarkus.it.artemis.jms.common; | ||
|
||
import jakarta.jms.*; | ||
import jakarta.transaction.RollbackException; | ||
import jakarta.transaction.Synchronization; | ||
import jakarta.transaction.SystemException; | ||
import jakarta.transaction.TransactionManager; | ||
|
||
public class ArtemisJmsXaConsumerManager extends ArtemisJmsConsumerManager { | ||
private final XAConnectionFactory xaConnectionFactory; | ||
private final TransactionManager tm; | ||
private String queueName; | ||
|
||
/** | ||
* This constructor exists solely for CDI ("You need to manually add a non-private no-args constructor"). | ||
*/ | ||
@SuppressWarnings("unused") | ||
ArtemisJmsXaConsumerManager() { | ||
this(null, null, null, null); | ||
} | ||
|
||
public ArtemisJmsXaConsumerManager(ConnectionFactory connectionFactory, | ||
XAConnectionFactory xaConnectionFactory, | ||
TransactionManager tm, | ||
String queueName) { | ||
super(connectionFactory, queueName); | ||
this.tm = tm; | ||
this.queueName = queueName; | ||
this.xaConnectionFactory = xaConnectionFactory; | ||
} | ||
|
||
public String receiveXA(boolean rollback) throws SystemException, RollbackException { | ||
XAJMSContext context = xaConnectionFactory.createXAContext(); | ||
JMSConsumer consumer = context.createConsumer(context.createQueue(queueName)); | ||
|
||
tm.getTransaction().enlistResource(context.getXAResource()); | ||
tm.getTransaction().registerSynchronization(new Synchronization() { | ||
@Override | ||
public void beforeCompletion() { | ||
} | ||
|
||
@Override | ||
public void afterCompletion(int i) { | ||
consumer.close(); | ||
context.close(); | ||
} | ||
}); | ||
if (rollback) { | ||
tm.setRollbackOnly(); | ||
} | ||
try { | ||
return consumer.receive(1000L).getBody(String.class); | ||
} catch (JMSException | NullPointerException e) { | ||
throw new RuntimeException("Could not receive message", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.