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
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 | <!-- ... --> <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> <!-- ... --> |
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.