Glassfish V3.1 running embedded ActiveMQ for JMS (Part 3)

In the third and final part of this tutorial we will crate a MDB (Message Driven Bean) that listens to our embedded ActiveMQ from Part 1.



  • Create a new EJB AmdMDB

    New EJB Project

    New EJB Project

    New EJB Project

  • Create a Message Driven Bean NewMessageBean

    Message Driven Bean

    Message Driven Bean

  • Create a Glassfish Descriptor glassfish-ejb-jar.xml


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE glassfish-ejb-jar PUBLIC "-// GlassFish Application Server 3.1 EJB 3.1//EN" "">
  • Create a Standard Deployment Descriptor ejb-jar.xml


    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar xmlns = ""
             version = "3.1"
             xmlns:xsi = ""
             xsi:schemaLocation = "">
  • Deploy the EJB


  • Send a message from ActiveMQ Web Console

    Send Message

    Receive Message

  • Send Message from external Client (from Part 2)

    External Client



In the 3 parts of the tutorial we walked through all the steps from embedding ActiveMQ into Glassfish, sending messages from both admin client and external client and receiving messages in a MDB. It is a working sample, that requires some finetuning towards more security and certainly features. I hope it helps you to get started, even all the nitty-gritty details and JMS science stuff are omitted. I believe it is much easier to get started with a working sample and begin to adopt to your own needs and read more in some of the JMS, ActiveMQ and Glassfish books and websites.
I spend more time trying to get a external client to talk to Glassfish JMS (unsuccessfully) than to get the above setup into a production system ! Thanks to AvtiveMQ team for this great messaging tool.

8 thoughts on “Glassfish V3.1 running embedded ActiveMQ for JMS (Part 3)

  1. I have a problem with setting Resource Adapter Config

    ServerUrl: vm://localhost:61616
    BrokerXmlConfig: broker:(tcp://localhost:61616)

    When I set localhost MDB (tutorial part 3 works), but remote application won’t work.
    When I set MDB won’t work, but remote application (part 2 works).

  2. Pingback: Glassfish V3.1 running embedded ActiveMQ for JMS (Updates) | The JavaDude Weblog

  3. Thanks for writing this very comprehensible tutorial.

    Is there any way i could get rid of the activemq-rar-5.5.1 setting in the glassfish-ejb-jar.xml so that i do not have this external dependecy when it comes to providing support for other broker-implementations such as OpenMQ? I have tried to simply remove the setting and it did work to a certain extent. Messages could be send to the broker but could not be received by the MDBs.

    Every help / hint would be much appreciated.

  4. Hi, thanks for writing this guide. It was a big help in setting up the basic functionality.

    Could you point me in the right direction in securing the embedded ActiveMQ? I’m trying to prevent users from queuing or consuming messages without a username/password. I’ve tried setting a UserName and Password property on the Resource Adapter Config, and also setup simpleAuthenticationPlugin in broker-config.xml. Neither seem to work, as anyone can still interact with the queue.

    I would appreciate any help. Thanks!

    • I am facing the same requirement for a production system, secure webconsole and broker.
      Trying to apply GF security with user realm for the webconsole.

      The broker-config.xml is NOT read for embedded AMQ if you follow above tutorial.
      Let me try too, you need to place sections in the ra.xml in order to configure through GF.

      Will post another entry on this.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s