Skip to content

Configuring RabbitMQ for Martini

RabbitMQ is a robust messaging broker using the Advanced Message Queuing Protocol (AMQP), facilitating seamless message exchange. While RabbitMQ is not inherently a Java Message Service (JMS) provider, it offers JMS API compatibility through its JMS topic exchange plugin and JMS client libraries. This flexibility allows systems like Martini Server Runtime to establish connectivity with RabbitMQ, leveraging its powerful message-brokering capabilities for diverse application needs.

Prerequisites

Refer to Installing RabbitMQ for the initial setup. It’s vital to install RabbitMQ with the appropriate plugins that enhance its functionality. Martini Server Runtime leverages the connection to the JMS Topic Exchange and the Management API for efficient message routing and monitoring.

  • RabbitMQ JMS Topic Exchange Plugin: This plugin adds server-side support for the RabbitMQ JMS client. It provides support for JMS topic routing and selection based on JMS SQL selection rules.
  • RabbitMQ Management Plugin: This plugin provides an HTTP-based API for management and monitoring of RabbitMQ nodes and clusters. Martini Server Runtime uses it to query the list of destination names.

In addition, ensure that the following prerequisites are added to the Martini Server Runtime so that RabbitMQ functions properly.

Once obtained, place the library JAR file under <martini-home>/lib/ext/.

Connect to a RabbitMQ instance

In this section, we'll go through the initial steps to configure Martini Server Runtime and establish connectivity with RabbitMQ. This setup will include the bare minimum configurations to be connected to RabbitMQ and enable robust message brokering capabilities.

  1. Configure Martini's connection properties in the <martini-home>/conf/overrides/override.properties.

Configuration properties: These properties represent the bare minimum requirements needed to get started with the application.

1
2
3
4
5
jms.configuration-file=rabbitmq
# The URL of the broker. 
rabbitmq.uri=amqp://[HOST]:5672
# The API URL to connect to the broker.
rabbitmq.apiUri=http://[HOST]:15672/api

Authentication properties: If you are using the default credentials, you can skip the following properties. For guidance on setting up authentication, refer to the documentation here.

1
2
3
4
5
6
# Sets the login when connecting to a RabbitMQ instance.
# If unspecified, Martini will use 'guest' for the login.
rabbitmq.username=[username]
# Sets the password when connecting to a RabbitMQ instance.
# If unspecified, Martini will use 'guest' for the password.
rabbitmq.password=[password]

Optional properties:

1
2
3
# The prefix is added to mitigate overlapping JMS destinations and to distinguish between different Martini instances connected to a single message broker.
# It adds a prefix to the beginning of a queue; for example: `your-prefix.io.lonti.martini`
jms.destination-prefix=your-prefix
  1. Restart Martini Server Runtime to apply the changes.
  2. Verify connection establishment.
1
INFO [MartiniBrokerConfiguration] Using broker configuration at '<martini-home>/conf/broker/rabbitmq.xml'

JMS Messaging

Refer to JMS in Martini to learn more about sending and receiving JMS messages.

AMQP Messaging

RabbitMQ uses the Advanced Message Queuing Protocol (AMQP) by default, for messaging. AMQP provides a standardized, reliable message exchange between applications.

Martini's runtime is adept at both publishing and receiving JMS messages. However, special measures are required for dealing with AMQP message formats, underscoring the importance of thorough preparation and understanding of RabbitMQ's capabilities and limitations.

Sending messages using Martini CLI

To send an AMQP message, the amqp parameter must be set to true in the destination string. If exchangeName and routingKey are not specified, they will assume default values.

Warning

Sending an AMQP-formatted message to a JMS queue may lead to deserialization issues, especially if the queue bindings involve jms.durable.queues exchange.

With the use of Martini CLI, Martini can interact with RabbitMQ to create and publish messages. To start, locate and start your Martini Server Runtime.

  1. Open the Runtime Directory: <martini-home>/bin
  2. Run the Martini Server Runtime in debug mode:
1
./toro-martini debug
  1. Launch the Martini CLI:
1
java -jar toro-martini-cli.jar
  1. Connect to your Martini Server Runtime instance.
1
connect --uri http://[HOST] --client-id [YOUR-ID] --client-secret [YOUR-SECRET]
  1. Use the command publish-string to send a string.
1
publish-sting --destination [URI] --value [STRING]

URI can be queue://{name}?amqp=true

Sending messages using API Explorer

  1. Open a web browser and navigate to [HOST]:8080/api-explorer/ to access the API Explorer.
  2. Locate and click on the broker tag within the API Explorer to view various broker configuration and operation endpoints.
  3. Use the /esbapi/broker/destinations/{type}/{name}/sendString endpoint to send a string.
  4. For the type field, you can type queue or topic based on your needs. For the name field, specify the destination name you want to send to.
  5. Execute the request using the POST method at the chosen endpoint.