2
votes

Technologies used.

  • ActiveMQ 5.5.1
  • Glassfish 3.1
  • genericra 2.1

Where I am at;

  • I have ActiveMQ installed and running
  • genericra is configured and working in Glassfish. I have configured a connector resource (amqRes), Connector connection pool (amqPool) and admin object resource (amqQueue). Deployed genericra and configured the resource adapter configs.
  • I am able to post a message onto the activeMQ queue from an app running in Glassfish. When I post I can see a new entry on the queue in activeMQ admin console.

We are using other JMS queues (within glassfish) and they work well.

The trouble I'm having is getting a message off the queue from activeMQ. I have written a test @MessageDriven bean that implements javax.jms.MessageListener. It has one simple method (onMessage) that just outputs the message. I'm not sure how to register the MDB so that it picks up messages from the activeMQ queue. I have seen quite a few examples of putting entries in ejb-jar.xml, glassfish-ejb-jar.xml or sun-ejb-jar.xml - none of which have worked for me. When I look in the activeMQ console I can't see any consumers for the queue I've created.

I have read a number of blogs but seem to be missing this last piece of the jigsaw.

import javax.ejb.MessageDriven;
import javax.jms.Message;

@MessageDriven(mappedName = "amqQueue")
public class ActiveMQTestListener implements javax.jms.MessageListener {
    public void onMessage(Message message) {
        System.out.println(message.toString());
    }
}
1
I've added MDB to my questionvilvic

1 Answers

4
votes

OK, so after much playing around I got it working. It turns out you don't need to create a connector resource, connection pool or admin object resource in order to receive a message from active mq.

In summary I deployed the connector genericra.rar (I changed the name to genericRA) in glassfish http://java.net/downloads/genericjmsra/v2.1a/binaries/. I configured the resource adapters configs using the settings from http://activemq.apache.org/sjsas-with-genericjmsra.html (copied below - slighyly modified to fit the example). I entered the details manualy in glassfish.

asadmin create-resource-adapter-config
  --property
  SupportsXA=true
  :RMPolicy=OnePerPhysicalConnection
  :ProviderIntegrationMode=javabean
  :ConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory
  :QueueConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory
  :TopicConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory
  :XAConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory
  :XAQueueConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory
  :XATopicConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory
  :UnifiedDestinationClassName=org.apache.activemq.command.ActiveMQDestination
  :QueueClassName=org.apache.activemq.command.ActiveMQQueue
  :TopicClassName=org.apache.activemq.command.ActiveMQTopic
  :ConnectionFactoryProperties=brokerURL\\=tcp\\://127.0.0.1\\:61616
  :LogLevel=FINE
  genericRA

If you want to be ale to send from glassfish we found that the admin object resource wasn't appearing in the jndi list (./asadmin list-jndi-entries). We discovered that the admin object resource was disabled. We had to edit the the domain.xml and set enabled = true.

My test message driven bean;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(activationConfig =  {
    @ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destinationProperties",propertyValue = "PhysicalName=amqQueue")
})
public class ActiveMQTestListener implements MessageListener {
    public void onMessage(Message message) {
        System.out.println(message.toString());
    }
}

My glassfish-ejb-jar.xml;

<glassfish-ejb-jar>
    <enterprise-beans>
        <ejb>
            <ejb-name>ActiveMQTestListener</ejb-name>
            <mdb-resource-adapter>
                <resource-adapter-mid>genericRA</resource-adapter-mid>
            </mdb-resource-adapter>
        </ejb>
    </enterprise-beans>
</glassfish-ejb-jar>

I started activeMQ, glassfish (in debug mode so that I could see the message) and brought up the console (http://localhost:8161/admin). I created a new queue called amqQueue. I created a new message (send in the activeMQ console), set the destination to amqQueue and entered some text in the message body. Clicked send and the break point was triggered in the code.