This discussion is archived
0 Replies Latest reply: Oct 19, 2012 9:30 AM by 969586 RSS

Glassfish Howto config multiple JMS Queue residing on diff remote locations

969586 Newbie
Currently Being Moderated
Problem: In glassfish I have several message driven bean configured. Each bean listens to different queue and the physical destination of these queue could be in many different location.

For example here is an example condition the following Queue

jms/workflow Host:localhost port:1234
jms/errors host:localhost port:1234
jms/notifications host:myserver port:9876

so the message driven beans have to connect to different JMS brokers one at mq://localhost:1234 and the other mq://myserver:9876


Solution:
Step 1
In glassfish admin console create a destination resource(Resources->JMS Resources->Destination Resources). Create a new physical destination with the same name as the destination name on the host server. So in the above problem we have to create 3 different destination.

Step 2
Then for each JMS broker create a connection factory. For the above problem we need to create 2 different connection factory

1) LocahostConnectionFactory fill in all the regular connection pool info. In the properties add the following properties and values
     addresslist: mq://localhost:1234
     userid:myuser
password:mypassword

2) MyServerConnectionFactory fill in all the regular connection pool info. In the properties add the following properties and values
     addresslist: mq://myserver:9876
     userid:myuser
password:mypassword

Steps 3
now we need to tell each messagedriven bean what queue messages to listen so add the below annotation for each message driven bean. The mappedname parameter needs to have the exact same JNDI name used to create the Destination resource in step 1.

@MessageDriven(mappedName = "jms/workflow", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
,@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
public class WorkflowListner implements MessageListener {
}

Step 4:
Finally we need to tell for each MDB queue which connection factory to use. this is done in the ejb-jar.xml file
<ejb>
     <ejb-name>WorkflowListner</ejb-name>
     <mdb-connection-factory>
     <jndi-name>jms/LocahostConnectionFactory</jndi-name>
</mdb-connection-factory>
</ejb>