users@glassfish.java.net

Re: ActiveMQ and glassfish

From: <glassfish_at_javadesktop.org>
Date: Fri, 25 Jun 2010 11:07:20 PDT

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):


<sun-ejb-jar>
        <enterprise-beans>
                <ejb>
                        <ejb-name>MyMDB</ejb-name>

                        <mdb-resource-adapter>
                                <resource-adapter-mid>activemq-rar-5.3.0</resource-adapter-mid>
                        </mdb-resource-adapter>
                </ejb>
        </enterprise-beans>
</sun-ejb-jar>


Good luck, <ras>
[Message sent by forum member 'rsitze']

http://forums.java.net/jive/thread.jspa?messageID=475853