Skip to content

Toro Cloud Dev Center


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:

  1. Open the activemq-embedded.xml file. Then look for the transportConnectors property of the broker 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>
    
  2. To add a new transport connector, add a new TransportConnector bean to the transportConnectors list. This bean requires a uri property and an optional name 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.

  3. Save the file.

  4. 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
<!-- ... -->
<property name="transportConnectors">
    <list>
        <!-- ... --> 
        <!-- MQTT transport connector -->
        <bean class="org.apache.activemq.broker.TransportConnector">
            <property name="name" value="mqtt" />
            <property name="uri" value="mqtt://localhost:1884" />
        </bean>
    </list>
</property>
<!-- ... -->

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
<!-- ... -->
<property name="transportConnectors">
    <list>
        <!-- ... --> 
        <!-- MQTT transport connector
        <bean class="org.apache.activemq.broker.TransportConnector">
            <property name="name" value="mqtt" />
            <property name="uri" value="mqtt://localhost:1884" />
        </bean>
        -->
    </list>
</property>
<!-- ... -->

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.

Sending a message from Martini to the MQTT client

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.

Sending a message from the MQTT client to Martini

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.

Sending a message from Martini to the STOMP client

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
telnet [address] [port default is:61613]

CONNECT
accept-version:1.2
host:[address]
login:[username]
passcode:[password]

^@

SEND
destination:[queue]
content-type:text/plain
receipt:123

[message]^@

Sending a message from the STOMP client to Martini

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 &amp;transport.transformer=jms after the URI, see screenshot below.

activemq.xml

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.

Java-based AMQP client

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.

Martini and the AMQP client

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.