Overview
JMS (Java Message Service) is a kind of messaging middleman for different software components or systems. It’s like a postal service for applications. It orchestrates the exchange of messages, allowing applications to share information without direct dependencies. Here are a few pointers for JMS.
Messaging Paradigm:
- Point-to-Point (P2P): Think of it like sending a private letter. One sender, one receiver.
- Publish/Subscribe (Pub/Sub): It’s more like a newspaper subscription. A sender (publisher) broadcasts messages, and multiple receivers (subscribers) can choose to receive them.
Messaging Models:
- Synchronous: The sender waits for the receiver to acknowledge or respond before proceeding.
- Asynchronous: The sender doesn’t wait around; it just sends the message and moves on.
JMS API:
- ConnectionFactory: Establishes a connection to the message broker.
- Connection: Represents the connection to the message broker.
- Session: A single-threaded context for sending and receiving messages.
- Message: The object carrying the data being sent.
- Destination: The target (queue or topic) for a message.
Reliable Messaging:
- Acknowledgments: Senders can know if their message was received successfully.
- Transactions: Multiple operations can be grouped as a single unit to ensure consistency.
JNDI(Java Naming and Directory Interface) :
It is a Java API that provides a standardized way to access naming and directory services, making it easier for Java applications to locate and access resources and objects. It is useful for processing messages to and from Universal Messaging in webMethods.
Connection Factory :
ConnectionFactory acts as a connector for clients to link up with the server. It holds information about the server’s location and various configuration settings, serving as the go-to resource for clients to establish connections. This object essentially streamlines the connection process by encapsulating the details required for communication between these clients and the server in one convenient package.
Pub/Sub work through:
Start Universal messaging and Enable connection :
- Navigate to your file system where you have installed the webMethods product suite. If you have not installed it yet, click here to check out our article on the same.
- Run ‘nserver.bat‘ located in the ‘C:\SoftwareAG\UniversalMessaging\server\umserver\bin‘ path for Windows, and for Linux, execute ‘nserver.sh‘. Please note that this directory may vary depending on your installation directory.
- Login to your integration server administrator page and navigate to the ‘JMS settings’ option under the ‘Messaging’ tab.
- If you encounter the below error then we need to create the local_um connector factory.
Erro: com.wm.app.b2b.server.jms.JMSSubsystemException: [ISS.0134.9016] Error creating connection factory: javax.naming.NamingException: Internal lookup failed for name=local_um [Root exception is javax.naming.NamingException: Name not found during lookup for local_um]
- Navigate to ‘C:\SoftwareAG\UniversalMessaging\java\umserver\bin‘ location and open ‘nenterprisemgr‘ application.
- Once you open the application the local UM will be automatically connected.
- Navigate to JNDI, right-click on ‘Connection Factories‘, and create a new factory named ‘local_um‘.
- Log in again to your Integration Server Administrator page, navigate to the ‘JMS Settings’ option under the ‘Messaging’ tab, and attempt to enable the connection. This time, you will notice that it is successfully enabled.
Create Topic and Queue in UM:
- Open Enterprise Manager, and right-click the ‘Queue‘ option to create a queue. Similarly, right-click on ‘Topic‘ to create a new topic.
- Once you have successfully created Queue and Topic then we can publish the message and subscribe to it as well.
Publish message:
- Create a package in Designer and follow the below package structure.
- HG_JMSDemo
- HG_JMSDemo
- v1
- publish
- subscribe
- trigger
- v1
- HG_JMSDemo
- HG_JMSDemo
- Create a flow service in the publish folder with the name ‘publishMessage‘.
- In the input of the flow service, create the following variables and set the ‘destinationType‘ as a picklist with two options: ‘QUEUE‘ and ‘TOPIC‘.
- connectionAliasName.
- destinationName.
- destinationType.
- message.
- Invoke ‘pub.jms:send‘ service inside ‘publishMessage‘ service and perform the below mapping.
- Now run the service with the below inputs then it will send the message to the subsequent queue or topic.
- connectionAliasName : DEFAULT_IS_JMS_CONNECTION(This is the default connection alias , you can create your own).
- destinationName : Queue or Topic Name.
- destinationType : Select QUEUE/TOPIC based on your destination.
- message : ‘Hello JMS’.
- Once you run the service, navigate to the Enterprise Manager. If you see the queue/topic, you will be able to observe the number of messages that have been published to the QUEUE/TOPIC.
- If you navigate to the ‘Snoop‘ option of the queue or topic, you will find a ‘Start‘ button. Clicking on the ‘Start‘ button allows you to view the messages available in the queue or topic.
Subscribe message:
We need to create a trigger to subscribe to messages from the Queue/Topic and a service that will process the received messages from the Queue/Topic. Follow the points below to subscribe to the messages.
- Create a flow service inside the subscribe folder with the name ‘subscribeMessage‘.
- Create an input variable by referencing the ‘pub.jms:JMSMessage‘ document and name it ‘JMSMessage‘.
- Invoke ‘pub.flow:debugLog‘ service to log the message that we received from the UM and follow the below mapping.
- JMSMessage/body/string: message
- Create a JMS trigger inside the trigger folder and configure the below properties to subscribe to the message.
- JMS Connection Alias Name : Select ‘DEFAULT_IS_JMS_CONNECTION’ alias or if you have created anything in your own that also you can select it here.
- JMS Destinations and message selector: Select the destination and the type.
- Message Routing: Select ‘subscribeMessage‘ service which we have created to process the message.
- Once you have configured everything, run the publish service to send the message, and monitor the server log. You will be able to see the message in the server log that you have published to the Queue/Topic.
In this article, we have discussed the basics. We will continue with a series to delve into each and every property of the JMS Trigger and other UM concepts.
Download source code from github.
Hope you have enjoyed this article, Cheers!