JMS - Setting Up And Accessing A Remote Glassfish 4 and OpenMQ JMS Queue via ORB

This is a complete guide to setup JMS queue with Glassfish 4 and the setting required to access the JMS queue with a remote standalone client.

Download Glassfish


1. Download latest Glassfish at https://glassfish.java.net/download.html

2. Follow the instruction at the download page to install Glassfish 4. (Mainly unzip the package and run ./asadmin start-domain). To stop Glassfish server, you can run ./asadmin stop-domain

3. You may want to enable remote admin. Simply run ./asadmin enable-secure-admin

4. After installation, you can access the admin webpage with http://hostname:4848



Check ORB Configuration


Since we are using ORB (Object Request Broker) for remote JMS connectivity, we will take a look at the ORB setup in Glassfish 4.

1. Go to Configurations -> server-config -> ORB -> IIOP Listeners -> orb-listener-1



2. From the above screenshot, you can see that the default listening port is 3700 and we will need this port number for later configuration with JNDI properties.

3. We will be using the default setting of ORB configuration

Check JMS Host Configuration


Now, let's take a look at the JMS Host configuration. JMS host represents a Message Queue broker and I will be using Embedded type as JMS Service Type (MQ broker is co-located in the same JVM as the GlassFish server instance it services and the JMS service uses lazy initialization to start the broker when the first JMS operation is requested instead of immediately when the GlassFish instance is started)

1. Go to Configurations ->server-config -> Java Message Service



2. Note that the Default JMS Host is default_JMS_host. This is usually sufficient and the setting of default_JMS_host is as follow



3. In actual fact, this define the host and port of the Message Queue broker. The Host will be localhost because we are accessing the JMS queue via ORB. The Port is ${JMS_PROVIDER_PORT}. It is actually defined at System Properties (See Below) and the default value is 7676



4. We will be using the default setting for JMS Hosts configuration

Create JMS Physical Destinations


The Message Queue broker uses physical destination to route delivered message and deliver to consumer. We need to create at least 1 Physical Destination for our JMS queue.

1. Go to server (Admin Server) -> JMS Physical Destinations tab



2. Click New

3. Fill in the information (mostly default except Name and Type) and click save.

Note:
a. Name: A name which uniquely identify the physical destination
b. Type: As I am creating a Queue, the Physical Destination Type is javax.jms.Queue.



Create Connection Factories


We need a JMS connection factory that allow an application to create other JMS objects

1. Go to Resources -> JMS Resources -> Connection Factories



2. Click New

3. Fill in the information (mostly default except JNDI Name and Resource Type) and click save

Note:
a. JNDI Name: A name which uniquely identify the connection factory
b. Resource Type: As I am creating a Queue, the Resource Type is javax.jms.QueueConnectionFactory



Create a Destination Resources


We need a JMS destination resource to provide information about the actual physical destination information of the queue.

1. Go to Resources -> JMS Resources -> Destination Resources



2. Click New

3. Fill in the information (mostly default except JNDI Name, Physical Destination Name and Resource Type)

Note:
a. JNDI Name: A name which uniquely identify the destination resource
b: Physical Destination Name: Use the Physical Destination which we had created previously
c. Resource Type: As I am create a Queue, the Resource Type is javax.jms.Queue



Setting Up JNDI Properties for Remote Queue Access


The above should get your JMS Message Broker and Queue up and running. Definitely, you can use telnet to verify if the server/port is running

a. For ORB, use telnet hostname 3700
b. For JMS Message Broker, use telnet hostname 7676

Next, the following JNDI properties (put them into a jndi.properties file) will allow you to perform remote connection to the JMS queue

java.naming.factory.initial: com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs: com.sun.enterprise.naming
java.naming.factory.state: com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
org.omg.CORBA.ORBInitialHost={hostname or IP of your remote client}
org.omg.CORBA.ORBInitialPort=3700

You need to ensure the following jar files are included in the JAVA CLASSPATH

a. {Glassfish 4 installation Path}/mq/lib/jms.jar
b. {Glassfish 4 installation Path}/glassfish/lib/gf-client.jar

With the above, you can use your preferred programming language to write a standalone client (use the Connection Factory and Destination Resource JNDI Name which we had created as JNDI lookup) and connect to your JMS queue remotely.

Reference:

1. Glassfish 4.0 Administration Guide



Comments

  1. Hello,
    I have the same condiguration it works fine, but i want to use a jms browser like HermesJMS but is not working...any help to configure HermesJMS with this configuration.
    Thanks
    Akli

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular Posts