Skip to content

Martini JMS Functions

The Jms class in Martini offers functions for efficiently publishing and responding to JMS messages. These functions are integral for interacting with JMS topics and queues in a variety of service scenarios.

Utilizing JMS Functions

Access JMS functions within your project by navigating to the 'functions' node. In the JMS folder, a range of functions is available for direct integration into your services.

Publishing Messages

To publish a message to a JMS destination (topic or queue), use the publishString function. This requires specifying the destination and the message content.

Example:

1
2
3
4
5
// Example of publishing a message to a JMS queue
String destination = "exampleQueue" // Specify your queue name
String message = "Hello, JMS!" // Your message content

"queue://${destination}".publishString(message)

Responding to Messages

When you need to handle responses to messages, the publishString function can be used with a closure. This enables processing of replies in the same context.

Example:

1
2
3
4
5
6
7
// Example of publishing a message and handling a reply
String destination = "exampleQueue" // Specify your queue name
String requestMessage = "Request Data" // Your request message

"queue://${destination}".publishString(requestMessage) { replyMessage ->
    println "Received reply: ${replyMessage}"
}

Advanced Implementation

For advanced use-cases, like triggering a service via a JMS message, you should set up a service that is compatible with JMS endpoints. This includes configuring the service with the publishString function and appropriately setting the destination and message parameters.

Steps for Advanced Configuration: 1. Create a new service compatible with JMS endpoints. 2. Implement the publishString function in your service, specifying the destination and message. 3. Test the service to ensure proper functionality and message handling.