Skip to main content

ActiveMQ and glassfish

1 reply [Last post]
tekkisse
Offline
Joined: 2010-06-23

Can anybody point me in the direction of how to link ActiveMQ to Glassfish to send and receive messages. Do not understnd the limited help on google. Can I just use the JMS connector ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rsitze
Offline
Joined: 2004-04-07

For ApacheMQ 5.3.0, this is what I have done - adjust names/version#s as appropriate.

Install the RAR file distributed with ApacheMQ;
* Find lib/optional/activemq-rar-5.3.0.rar in the ApacheMQ distribution.
* Use the GF Admin console, and deploy activemq-rar-5.3.0.rar using "Applications" (which also deploys modules...).
* Accept the defaults.

Create a Connector Connection Pool:
* GF Admin console -> Resources -> Connectors -> Connector Connection Pools.
* name: ActiveMQPool
* resource adapter: the RAR module deployed above
* connection definition: javax.jms.ConnectionFactory
* other settings: accept default values

Create a Connector Resource:
* GF Admin console -> Resources -> Connectors -> Connector Resources
* name: jms/myBus
* pool name: ActiveMQPool [as specified above]
* other settings: accept default values

From this point, I can send messages from GF by injecting the connection factory resource (see javadocs) into my EJB via:

@Resource(mappedName="jms/myBus")
private javax.jms.ConnectionFactory connectionFactory;

Receiving a message gets a bit more complicated. My experience was with GF 2.1, not GF 3, so the situation may have improved. I was never able to define a JNDI resource to represent an incoming message queue; instead I had to configure my app via sun-ejb-jar.xml & annotations:

@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "MY.ACTIVEMQ.QUEUE.NAME")
})
public class MyMDB implements MessageListener {
...
}

Finally, MyMDB has to be configured in sun-ejb-jar.xml (make sure the RAR name/version# matches your deployed module):




MyMDB


activemq-rar-5.3.0



Good luck,