References
- Using the JMS API in Java EE Applications
- Sending and Receiving Messages Using a Simple Web Application
- Getting started with Java Messaging Service (JMS)
- Asynchronous Receiver in Java Messaging Service (JMS)
- Java Message Service Tutorial
- Need clarification on JMS vs ActiveMQ bean/resource configuration
- Disabling OpenMQ in Payara Server
- Connecting to ActiveMQ with Payara Server
- ActiveMQ with JMS Queues and Topics
What is JMS?
Java Message Service (JMS) is an application program interface (API) from Sun Microsystems that supports the messaging communication between computers / applications / software components in a network.
The messages involved exchange crucial data between computers – rather than only between users – and contain information such as event notification and service requests.
This API allows Java based applications to create, send, receive and read messages without exposing any client architecture information. JMS architecture is very loosely coupled unlike RMI where the remote method name is needed in order to communicate.
Two basic architecture is used for communication:
i. QUEUE – This is a kind of pipeline connection between two clients. For example, One-To-One chat where one client sends a message and the other one receives that.
ii. TOPIC – This can be considered as a common space where all the clients connected to the particular topics can communicate with each other. For example, Group chat where one client sends a message and all the connected clients receives that.
(Reference: https://docs.oracle.com/javaee/6/tutorial/doc/bncdq.html)
JMS Topic vs Queues
What is Apache ActiveMQ?
ActiveMQ is an open-source, messaging software which serve as the backbone for an architecture of distributed applications built upon messaging. ActiveMQ completely implements Java Messaging Service 1.1 (JMS). In order to run a JMS application we need ActiveMQ instance running on a machine which will be treated as a JMS server.
(Reference: http://activemq.apache.org)
Apache ActiveMQ installation
To install ActiveMQ
|
|
To have launchd start activemq now and restart at login:
|
|
Or, if you don’t want/need a background service you can just run:
|
|
To run ActiveMQ Console
|
|
The ActiveMQ broker runs a web-console when it boots that is accessible from http://127.0.0.1:8161. Username is admin
and password is admin
.
Deploy the ActiveMQ RAR to GlassFish Server
To copy activemq-rar from maven repository to current directory
|
|
To deploy rar file to GlassFish Server
|
|
Once it has been deploy as a Java EE connector we need to configure the connector to connect to our default broker.
Configuring the ActiveMQ Connector
First we need to create a Configuration for the resource adapter to refer to our ActiveMQ broker.
The key settings are ServerURL, UserName and Password. For an out of the box ActiveMQ configuration they should be set to;
| ServerURL | tcp://127.0.0.1:61616 | | UserName | admin | | Password | admin |The resource adapter configuration, JMS connection pool, JMS resource (to create JNDI mapping for JMS Connection pool), JMS mapping to Queue can be created using glassfish-resources.xml or asadmin;
Using asadmin administrator tool
|
|
Using glassfish-resources.xml
|
|
|
|
|
|
|
|