Chapter 3. Configuring messaging protocols in network connections
You can configure messaging protocols, such as AMQP or MQTT, to customize how acceptors handle incoming connections over the network.
The broker supports the following protocols:
- AMQP
- MQTT
- OpenWire
- STOMP
In addition to the protocols above, the broker also supports its own native protocol known as "Core". Past versions of this protocol were known as "HornetQ" and used by Red Hat JBoss Enterprise Application Platform.
3.1. Default acceptors Copy linkLink copied to clipboard!
The default AMQ Broker configuration includes acceptors for Core, AMQP, MQTT, and STOMP protocols, plus an acceptor that supports all protocols. You can customize the acceptors for your environment.
The default acceptors are configured in the <broker_instance_dir>/etc/broker.xml file.
3.2. Parameters configured in default acceptors Copy linkLink copied to clipboard!
Review all the other parameters configured in the default acceptors and customize as required for your environment.
| Acceptor(s) | Parameter | Description |
|---|---|---|
| All-protocols acceptor AMQP STOMP | tcpSendBufferSize |
Size of the TCP send buffer in bytes. The default value is |
| tcpReceiveBufferSize |
Size of the TCP receive buffer in bytes. The default value is TCP buffer sizes should be tuned according to the bandwidth and latency of your network. In summary TCP send/receive buffer sizes should be calculated as: buffer_size = bandwidth * RTT.
Where bandwidth is in bytes per second and network round trip time (RTT) is in seconds. RTT can be easily measured using the For fast networks you might want to increase the buffer sizes from the defaults. | |
| All-protocols acceptor AMQP STOMP HornetQ MQTT | useEpoll |
Use Netty epoll if using a system (Linux) that supports it. The Netty native transport offers better performance than the NIO transport. The default value of this option is |
| All-protocols acceptor AMQP | amqpCredits |
Maximum number of messages that an AMQP producer can send, regardless of the total message size. The default value is To learn more about how credits are used to block AMQP messages, see Section 7.3.2, “Blocking AMQP producers”. |
| All-protocols acceptor AMQP | amqpLowCredits |
Lower threshold at which the broker replenishes producer credits. The default value is To learn more about how credits are used to block AMQP messages, see Section 7.3.2, “Blocking AMQP producers”. |
| HornetQ compatibility acceptor | anycastPrefix |
Prefix that clients use to specify the For more information about configuring a prefix to enable clients to specify a routing type when connecting to an address, see Section 4.6, “Adding a routing type to an acceptor configuration”. |
| multicastPrefix |
Prefix that clients use to specify the For more information about configuring a prefix to enable clients to specify a routing type when connecting to an address, see Section 4.6, “Adding a routing type to an acceptor configuration”. |
Additional resources
3.3. Configuring a network connection to use a messaging protocol Copy linkLink copied to clipboard!
You can configure a network connection to use specific messaging protocols.
Prerequisite
You created and configured a network connection. For more information, see Chapter 2, Configuring acceptors and connectors in network connections.
Procedure
-
Open the
<broker_instance_dir>/etc/broker.xmlconfiguration file. Add the
protocolsparameter to the URI for an acceptor and specify the protocol name:<acceptor name="ampq">tcp://0.0.0.0:3232?protocols=AMQP</acceptor>
<acceptor name="ampq">tcp://0.0.0.0:3232?protocols=AMQP</acceptor>Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, the acceptor is configured to receive messages on port 3232 by using the AMQP protocol. If you want to use multiple protocols, specify a comma-separated list of protocol names. For example:
<acceptor name="ampq">tcp://0.0.0.0:3232?protocols=AMQP,STOMP,MQTT</acceptor>
<acceptor name="ampq">tcp://0.0.0.0:3232?protocols=AMQP,STOMP,MQTT</acceptor>Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf the
protocolsparameter is omitted from the URI, all protocols are enabled.
3.4. Using AMQP with a network connection Copy linkLink copied to clipboard!
You can use the Advanced Message Queuing Protocol (AMQP) with a network connection to help enable interoperability with other messaging systems.
The broker supports the AMQP 1.0 specification. An AMQP link is a uni-directional protocol for messages between a source and a target, that is, a client and the broker.
An AMQP link has two endpoints, a sender and a receiver. When senders transmit a message, the broker converts it into an internal format, so it can be forwarded to its destination on the broker. Receivers connect to the destination at the broker and convert the messages back into AMQP before they are delivered.
If an AMQP link is dynamic, a temporary queue is created and either the remote source or the remote target address is set to the name of the temporary queue. If the link is not dynamic, the address of the remote target or source is used for the queue. If the remote target or source does not exist, an exception is sent.
A link target can also be a Coordinator, which is used to handle the underlying session as a transaction, either rolling it back or committing it.
AMQP allows the use of multiple transactions per session, amqp:multi-txns-per-ssn, however the current version of AMQ Broker will support only single transactions per session.
The details of distributed transactions (XA) within AMQP are not provided in the 1.0 version of the specification. If your environment requires support for distributed transactions, it is recommended that you use the AMQ Core Protocol JMS.
See the AMQP 1.0 specification for more information about the protocol and its features.
3.4.1. Using an AMQP Link as a Topic Copy linkLink copied to clipboard!
Unlike JMS, the AMQP protocol does not include topics. However, it is still possible to treat AMQP consumers or receivers as subscriptions rather than just consumers on a queue. By default, any receiving link that attaches to an address with the prefix jms.topic. is treated as a subscription, and a subscription queue is created. The subscription queue is made durable or volatile, depending on how the Terminus Durability is configured, as captured in the following table:
| To create this kind of subscription for a multicast-only queue… | Set Terminus Durability to this… |
|---|---|
| Durable |
|
| Non-durable |
|
The name of a durable queue is composed of the container ID and the link name, for example my-container-id:my-link-name.
AMQ Broker also supports the qpid-jms client and will respect its use of topics regardless of the prefix used for the address.
3.4.2. AMQP security Copy linkLink copied to clipboard!
The broker supports AMQP SASL Authentication. See Security for more information about how to configure SASL-based authentication on the broker.
3.5. Using MQTT with a network connection Copy linkLink copied to clipboard!
The broker supports MQTT v3.1.1 and v5.0 (and also the older v3.1 code message format). MQTT is a lightweight, client to server, publish/subscribe messaging protocol. MQTT reduces network traffic and a client’s code footprint. For these reasons, MQTT is ideally suited to constrained devices such as sensors and actuators and is quickly becoming the standard communication protocol for Internet of Things(IoT).
Procedure
-
Open the
<broker_instance_dir>/etc/broker.xmlconfiguration file. Add an acceptor with the MQTT protocol enabled. For example:
<acceptors> <acceptor name="mqtt">tcp://localhost:1883?protocols=MQTT</acceptor> ... </acceptors>
<acceptors> <acceptor name="mqtt">tcp://localhost:1883?protocols=MQTT</acceptor> ... </acceptors>Copy to Clipboard Copied! Toggle word wrap Toggle overflow MQTT includes several useful features:
- Quality of Service
- Each message can define a quality of service that is associated with it. The broker will attempt to deliver messages to subscribers at the highest quality of service level defined.
- Retained Messages
Messages can be retained for a particular address. New subscribers to that address receive the last-sent retained message before any other messages, even if the retained message was sent before the client connected.
Retained messages are stored in a queue named
sys.mqtt.<topic name>and remain in the queue until a client deletes the retained message or, if an expiry is configured, until the message expires. When a queue is empty, the queue is not removed until you explicitly delete it. For example, the following configuration deletes a queue:<address-setting match="$sys.mqtt.retain.#"> <auto-delete-queues>true</auto-delete-queues> <auto-delete-addresses>true</auto-delete-addresses> </address-setting>
<address-setting match="$sys.mqtt.retain.#"> <auto-delete-queues>true</auto-delete-queues> <auto-delete-addresses>true</auto-delete-addresses> </address-setting>Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Wildcard subscriptions
- MQTT addresses are hierarchical, similar to the hierarchy of a file system. Clients are able to subscribe to specific topics or to whole branches of a hierarchy.
- Will Messages
- Clients are able to set a "will message" as part of their connect packet. If the client abnormally disconnects, the broker will publish the will message to the specified address. Other subscribers receive the will message and can react accordingly.
3.5.1. MQTT properties Copy linkLink copied to clipboard!
You can append key-value pairs to the MQTT acceptor to configure connection properties. For example:
<acceptors> <acceptor name="mqtt">tcp://localhost:1883?protocols=MQTT;receiveMaximum=50000;topicAliasMaximum=50000;maximumPacketSize;134217728; serverKeepAlive=30;closeMqttConnectionOnPublishAuthorizationFailure=false</acceptor> ... </acceptors>
<acceptors>
<acceptor name="mqtt">tcp://localhost:1883?protocols=MQTT;receiveMaximum=50000;topicAliasMaximum=50000;maximumPacketSize;134217728;
serverKeepAlive=30;closeMqttConnectionOnPublishAuthorizationFailure=false</acceptor>
...
</acceptors>
- receiveMaximum
-
Enables flow-control by specifying the maximum number of QoS 1 and 2 messages that the broker can receive from a client before an acknowledgment is required. The default value is
65535. A value of-1disables flow-control from clients to the broker. This has the same effect as setting the value to 0 but reduces the size of the CONNACK packet. - topicAliasMaximum
-
Specifies for clients the maximum number of aliases that the broker supports. The default value is
65535. A value of -1 prevents the broker from informing the client of a topic alias limit. This has the same effect as setting the value to 0, but reduces the size of the CONNACK packet. - maximumPacketSize
-
Specifies the maximum packet size that the broker can accept from clients. The default value is
268435455. A value of -1 prevents the broker from informing the client of a maximum packet size, which means that no limit is enforced on the size of incoming packets. - serverKeepAlive
-
Specifies the duration the broker keeps an inactive client connection open. The configured value is applied to the connection only if it is less than the keep-alive value configured for the client or if the value configured for the client is 0. The default value is
60seconds. A value of-1means that the broker always accepts the client’s keep alive value (even if that value is 0). - closeMqttConnectionOnPublishAuthorizationFailure
-
By default, if a PUBLISH packet fails due to a lack of authorization, the broker closes the network connection. If you want the broker to sent a positive acknowledgment instead of closing the network connection, set
closeMqttConnectionOnPublishAuthorizationFailuretofalse.
3.6. Using Openwire with a network connection Copy linkLink copied to clipboard!
You can use use the OpenWire protocol to allow JMS clients to communicate with the AMQ Broker over a network connection. Use this protocol to communicate with older versions of AMQ Broker.
Currently AMQ Broker supports OpenWire clients that use standard JMS APIs only.
For examples of how to configure an Openwire network connection, see the Openwire example.
3.7. Using Stomp with a network connection Copy linkLink copied to clipboard!
To allow STOMP clients to exchange messages with AMQ Broker, configure a network connection that uses the lightweight, text-oriented STOMP protocol.
The broker supports STOMP 1.0, 1.1 and 1.2. STOMP clients are available for several languages and platforms making it a good choice for interoperability.
For an example of how to configure a broker with STOMP, see the STOMP example.
The following limitations apply when a network connection uses the STOMP protocol:
-
The broker currently does not support virtual hosting, which means the
hostheader inCONNECTframes are ignored. -
Message acknowledgments are not transactional. The
ACKframe cannot be part of a transaction, and it is ignored if itstransactionheader is set.
3.7.1. Configuring IDs for STOMP Messages Copy linkLink copied to clipboard!
STOMP messages received through a JMS consumer or a QueueBrowser do not contain any JMS properties, such as JMSMessageID. You can configure a broker parameter that sets a message ID on each incoming STOMP message.
Procedure
-
Open the
<broker_instance_dir>/etc/broker.xmlconfiguration file. Set the
stompEnableMessageIdparameter totruefor theacceptorused for STOMP connections, as shown in the following example:<acceptors> <acceptor name="stomp-acceptor">tcp://localhost:61613?protocols=STOMP;stompEnableMessageId=true</acceptor> ... </acceptors>
<acceptors> <acceptor name="stomp-acceptor">tcp://localhost:61613?protocols=STOMP;stompEnableMessageId=true</acceptor> ... </acceptors>Copy to Clipboard Copied! Toggle word wrap Toggle overflow By using the
stompEnableMessageIdparameter, each stomp message sent using this acceptor has an extra property added. The property key isamq-message-idand the value is a String representation of an internal message id prefixed with “STOMP”, as shown in the following example:amq-message-id : STOMP12345
amq-message-id : STOMP12345Copy to Clipboard Copied! Toggle word wrap Toggle overflow If
stompEnableMessageIdis not specified in the configuration, the default value isfalse.
3.7.2. Setting a connection time to live Copy linkLink copied to clipboard!
If a STOMP client exits without sending a DISCONNECT frame, or if it fails, the broker cannot determine if the client is still alive. You can configure a connection Time To Live (TTL) on the broker to automatically close inactive STOMP client connections and clean up resources on the server.
STOMP connections are configured to have a "Time to Live" (TTL) of 1 minute. The means that the broker stops the connection to the STOMP client if it has been idle for more than one minute.
Procedure
-
Open the
<broker_instance_dir>/etc/broker.xmlconfiguration file. Add the
connectionTTLparameter to the URI of theacceptorused for STOMP connections, as shown in the following example:<acceptors> <acceptor name="stomp-acceptor">tcp://localhost:61613?protocols=STOMP;connectionTTL=20000</acceptor> ... </acceptors>
<acceptors> <acceptor name="stomp-acceptor">tcp://localhost:61613?protocols=STOMP;connectionTTL=20000</acceptor> ... </acceptors>Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the preceding example, any STOMP connection that using the
stomp-acceptorwill have its TTL set to 20 seconds.NoteVersion 1.0 of the STOMP protocol does not contain any heartbeat frame. It is therefore the user’s responsibility to make sure data is sent within the connection TTL or the broker will assume the client is dead and clean up server-side resources. With version 1.1, you can use heart-beats to maintain the life cycle of STOMP connections.
3.7.2.1. Overriding the broker default time to live Copy linkLink copied to clipboard!
The default TTL for a STOMP connection is one minute. If you do not want clients to be able to specify their own connection TTL, you can set a global parameter on the broker to override values set by clients.
Procedure
-
Open the
<broker_instance_dir>/etc/broker.xmlconfiguration file. Add the
connection-ttl-overrideattribute and provide a value in milliseconds for the new default. It belongs inside the<core>stanza, as below.Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the preceding example, the default Time to Live (TTL) for a STOMP connection is set to 30 seconds,
30000milliseconds.
3.7.3. Sending and consuming STOMP messages from JMS Copy linkLink copied to clipboard!
STOMP is mainly a text-orientated protocol. To make it simpler to interoperate with JMS, the STOMP implementation checks for presence of the content-length header to decide how to map a STOMP message to JMS.
| If you want a STOMP message to map to a … | The message should…. |
|---|---|
| JMS TextMessage |
Not include a |
| JMS BytesMessage |
Include a |
The same logic applies when mapping a JMS message to STOMP. A STOMP client can confirm the presence of the content-length header to determine the type of the message body (string or bytes).
See the STOMP specification for more information about message headers.
3.7.4. Mapping STOMP destinations to AMQ Broker addresses and queues Copy linkLink copied to clipboard!
When sending messages and subscribing, STOMP clients typically include a destination header. Destination names are string values, which are mapped to a destination on the broker. In AMQ Broker, these destinations are mapped to addresses and queues.
For more information about the destination frame, see the STOMP specification .
Take for example a STOMP client that sends the following message (headers and body included):
SEND destination:/my/stomp/queue hello queue a ^@
SEND
destination:/my/stomp/queue
hello queue a
^@
In this case, the broker will forward the message to any queues associated with the address /my/stomp/queue.
For example, when a STOMP client sends a message (by using a SEND frame), the specified destination is mapped to an address.
It works the same way when the client sends a SUBSCRIBE or UNSUBSCRIBE frame, but in this case AMQ Broker maps the destination to a queue.
SUBSCRIBE destination: /other/stomp/queue ack: client ^@
SUBSCRIBE
destination: /other/stomp/queue
ack: client
^@
In the preceding example, the broker will map the destination to the queue /other/stomp/queue.
3.7.4.1. Mapping STOMP destinations to JMS destinations Copy linkLink copied to clipboard!
JMS destinations are also mapped to broker addresses and queues. If you want to use STOMP to send messages to JMS destinations, the STOMP destinations must follow the same convention:
Send or subscribe to a JMS Queue by prepending the queue name by
jms.queue.. For example, to send a message to theordersJMS Queue, the STOMP client must send the frame:SEND destination:jms.queue.orders hello queue orders ^@
SEND destination:jms.queue.orders hello queue orders ^@Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send or subscribe to a JMS Topic by prepending the topic name by
jms.topic.. For example, to subscribe to thestocksJMS Topic, the STOMP client must send a frame similar to the following:SUBSCRIBE destination:jms.topic.stocks ^@
SUBSCRIBE destination:jms.topic.stocks ^@Copy to Clipboard Copied! Toggle word wrap Toggle overflow