jeudi 5 janvier 2012

Glassfish to Glassfish : remote JMS trick


The use case


A Glassfish server named A has to consume a JMS queue named Qtest setlled on a Glassfish named B.
A has to query JNDI resource QCF (a queue connection factory), then query the queue Qtest and finally create a session.
This is basic JMS use case here !
Easy ?

The pitfall


Well it works perfectly from a java client but it does not work at all from A.
When debugging, we can see A attemps to connect to its own JMS service and not to B JMS service !
I find the Glassfish documentation not very helpful for that case.

The solution


You have to create a queue connection factory on A with the same name (QCF) and add a property named addresslist valued with B hostname and B JMS service port (not IIOP !!!!).
Say B hostname is "myB-gf-instance" and B JMS service port is 27676, you will have :
addresslist=myB-gf-instance:27676
In your A domain XML :
<connector-connection-pool name="QCF" resource-adapter-name="jmsra" connection-definition-name="javax.jms.QueueConnectionFactory">
     <property name="addresslist" value="myB-gf-instance:27676"></property>
</connector-connection-pool>
Now, don't forget to use this QCF from Glassfish A !
You have to lookup A QCF and not the remote one on B.
Then, you have 2 ways for queue Qtest :
  • lookup Glassfish B for Qtest
  • lookup Glassfish A for 'Qtest'' but you have to create it on A


Contrat Creative Commons
the jee architect cookbook by Olivier SCHMITT est mis à disposition selon les termes de la licence Creative Commons Paternité - Pas d'Utilisation Commerciale - Pas de Modification 3.0 Unported.