mercredi 27 mai 2015

Using remote JMS connection factory and queue in a local EJB

I have two JBoss EAP 6.1 instances S and T. At server T there is a JMS Queue Q. The requirement is to send a JMS message from S to Q. There is no need that the JMS session participate in the transaction.

My first approach was to use JNDI lookup as from any ordinary client:

Properties p = new Properties();
p.setProperty("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
p.setProperty("java.naming.provider.url", "remote://<IP server T>:4447");
p.setProperty("java.naming.security.principal", "user");
p.setProperty("java.naming.security.credentials", "pass");
InitialContext initialContext = new InitialContext(p);

This works from a client app. However in an EJB in server S I get the exception javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory. With the help of the answer to a question regarding this exception I changed the code to

Properties p = new Properties();
p.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
InitialContext initialContext = new InitialContext(p);

and put the other properties into the file jboss-ejb-client.properties which is located in the classpath root of the EJB-JAR (which itself is packaged into an EAR).

However, with this approach the Naming Context seems to be local, because the remote connection factory java:jboss/exported/jms/RemoteConnectionFactory seems to be the local one and the remote queue java:jboss/exported/jms/queue/Q is not found.

What is the correct way to use the remote JNDI context of the server T in a local EJB in server S?

I see that I could declare the remote connection factory in my local standalone-full.xml to bind it into my local JNDI. However, because there is no need for container managed transactions, I am afraid of other complications like XA recovery problems. These problems would put the whole server at risk while the remote JNDI lookup fail only locally.

Aucun commentaire:

Enregistrer un commentaire