ActiveMQ transport connectors
Transport connectors define the means (protocol) by which clients connect to brokers. By adding more transport connectors, you can broaden the means by which clients can connect to Martini's embedded ActiveMQ broker. Transports such as AMQP, MQTT, STOMP, and others can be configured in addition to the default TCP and VM transports that come with Martini out-of-the-box, as a need for a new transport arises.
ActiveMQ-specific configuration
Transport connectors are used exclusively by ActiveMQ brokers.
To add, modify, or delete transport connectors, the XML configuration file of the ActiveMQ broker must be modified.
This configuration file can be found under <martini-home>/conf/broker/activemq-embedded.xml
.
Adding a transport connector
Additional information
- This configuration only applies to the embedded instance of ActiveMQ and that standalone instances of ActiveMQ Classic and ActiveMQ Artemis do not require further configuration.
Adding a transport connector can be done by following these steps:
-
Open the
activemq-embedded.xml
file. Then look for thetransportConnectors
property of thebroker
bean. This section is responsible for configuring the transport connectors of the embedded ActiveMQ.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<bean id="broker" class="org.apache.activemq.xbean.XBeanBrokerService"> <!-- ... --> <property name="transportConnectors"> <list> <bean class="org.apache.activemq.broker.TransportConnector"> <property name="uri" value="vm://localhost" /> </bean> <bean class="org.apache.activemq.broker.TransportConnector"> <property name="name" value="openwire" /> <property name="uri" value="#{activeMqProperties.uriString()}" /> </bean> </list> </property> <!-- ... --> </bean>
-
To add a new transport connector, add a new
TransportConnector
bean to thetransportConnectors
list. This bean requires auri
property and an optionalname
attribute.Consider the following example, provided by default in
activemq-embedded.xml
, which defines a VM transport connector:1 2 3
<bean class="org.apache.activemq.broker.TransportConnector"> <property name="uri" value="vm://localhost" /> </bean>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<property name="transportConnectors"> <list> <bean class="org.apache.activemq.broker.TransportConnector"> <property name="uri" value="vm://localhost" /> </bean> <bean class="org.apache.activemq.broker.TransportConnector"> <property name="name" value="openwire" /> <property name="uri" value="#{activeMqProperties.uriString()}" /> </bean> <!-- MQTT transport connector --> <bean class="org.apache.activemq.broker.TransportConnector"> <property name="uri" value="mqtt://localhost:1883" /> </bean> </list> </property>
Pre-populated configurations
For convenience, there are pre-populated samples for common transports such as MQTT, NIO, AMQP, and others included in the
activemq-embedded.xml
file. Simply uncomment the entry for transport connector that you want to use and you're good to go. The transport connectors you can add is not limited to the pre-populated samples. Refer to ActiveMQ's documentation for more information. -
Save the file.
- Restart Martini to see the changes reflected.
Editing a transport connector
Similar to adding, editing a transport connector is done by modifying the existing TransportConnector
bean elements
under the broker
bean's transportConnector
property.
The affected Martini instance must be restarted after changes in activemq-embedded.xml
have been
saved in order to reflect updates made.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Removing a transport connector
As with the previous sections, removing a transport connector is done by removing the corresponding
TransportConnector
bean element of the transport connector that you no longer need. Commenting the XML element will
also do the trick; in fact, this is recommended if there is any chance in the future you might need the transport
connector back.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Configuring a transport connector
Additional information
- The commands that will be used below are for Linux only, except for the AMQP protocol.
- This configuration also applies to ActiveMQ Classic and ActiveMQ Artemis.
MQTT
To test this protocol, we need to install the MQTT client on our system by using this command
sudo apt install mosquitto-clients -y
. We will only install the client because ActiveMQ comes with an
MQTT broker already. After installing the client, we can test it by subscribing to the topic using the
command mosquitto_sub -h [address] -t [topic]
. After that, we can now try sending a JMS message from Martini
to the MQTT client, which you can see in the screenshot below.
Next, we are going to publish a message to the topic by using the command
mosquitto_pub -h [address] -t [topic] -m "[message]"
to test if Martini can receive a message from the Terminal,
which you can see in the screenshot below.
Additional information
- This protocol only supports Topics.
STOMP
To test this protocol, we need to install a STOMP client using the command sudo apt install python3-stomp
some additional information regarding this client can be found on this man page for
STOMP. To subscribe to the queue created from
Martini, we need to enter this command stomp -H [address] -P [port default is:61613] -L [queue]
and after that,
we can now try sending a JMS message from Martini to the STOMP client, which you can see in the screenshot below.
Next, we are going to publish a message to the queue using telnet
with these commands to test if Martini can
receive the message.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
As you can see from the screenshot above, Martini has successfully received a message from the queue.
Additional information
- This protocol only supports Queues.
AMQP
To test this protocol, we are going to edit the file located at <installation dir>/conf/activemq.xml
of
ActiveMQ, and we’re going to look for the AMQP transport connector and append &transport.transformer=jms
after the URI, see screenshot below.
For Artemis...
You may proceed to the next step below.
For this documentation, we will be using a simple Java-based AMQP client to publish and subscribe to AMQP messages to ActiveMQ, see the screenshot below.
Next, we will select the service that will be invoked when a message is received. This simple service will print the message received to the console. Now let’s run the AMQP client to send a message to the queue, and there you go, the message was received by Martini, which you can see in the screenshot below.
Additional information
- This protocol only supports Queues.
- ActiveMQ supports the AMQP 1.0 protocol which is an OASIS standard. Whilst the names are similar, this standard is completely different from the AMQP 0-9-1 protocol specification supported by RabbitMQ.
Before you migrate...
If you're using an embedded instance of ActiveMQ and have decided to switch over to a stand-alone version instead, the existing transport connectors will not be automatically migrated over. You will have to copy your existing configuration in order to carry your settings over.