Created
May 15, 2023 21:08
-
-
Save clebertsuconic/521ef555697c231375c7fdf27fc1f74f to your computer and use it in GitHub Desktop.
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
import javax.jms.XAConnection; | |
import javax.jms.XASession; | |
import javax.transaction.xa.XAResource; | |
import javax.transaction.xa.Xid; | |
import org.apache.activemq.artemis.core.client.impl.ClientSessionImpl; | |
import org.apache.activemq.artemis.jms.client.ActiveMQConnection; | |
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; | |
/** | |
* A simple JMS example showing the usage of XA support in JMS. | |
*/ | |
public class CommitEverything { | |
public static void main(final String[] args) throws Exception { | |
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); | |
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection(); | |
ClientSessionImpl session = (ClientSessionImpl) connection.getSessionFactory().createSession(true, false, false); | |
Xid[] xids = session.recover(XAResource.TMSTARTRSCAN); | |
XAConnection xaConnection = factory.createXAConnection(); | |
XASession xaSession = xaConnection.createXASession(); | |
for (Xid xid : xids) { | |
System.out.println("Xid::" + xid); | |
xaSession.getXAResource().commit(xid, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment