I'm trying to use two resources in the same XA transaction: a local resource and a remote resource. For example:
public class FileProcessor implements MessageListener {
.....
protected QueueConnectionFactory factory;
protected QueueConnection cnn;
protected Queue myQueue;
@PersistenceContext
protected EntityManager em;
@PostConstruct
public void init() {
...
Hashtable<String, String> params = new Hashtable<String, String>();
params.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
params.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
params.put("java.naming.provider.url", "remotehost:remoteport");
InitialContext ic = new InitialContext(params);
factory = (QueueConnectionFactory) ic.lookup("UIL2XAConnectionFactory");
myQueue = (Queue) ic.lookup("queue/myQueue");
cnn = factory.createQueueConnection();
...
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void onMessage(javax.jms.Message msg) {
....
dbUpdate(object);
sendNotifications(object);
....
}
private void dbUpdate(object){
...
em.persist(object);
...
}
private void sendNotifications(object){
...
sess = cnn.createQueueSession(true, 0);
sender = sess.createSender(myQueue);
sender.send(createProcessMessage(object));
...
}
...
}Well, I read the documentation and this is currently impossible.
Bogdan