Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

Chapter 23. Diverts

Diverts are objects configured in JBoss EAP messaging that help in diverting messages from one address to another. Diverts can be classified into the following types:

A message is only diverted to a new address and never sent to the old address.
A message is sent the old address, and a copy of it is also sent to the new address. Non-exclusive diverts can be used for splitting the flow of messages.

A divert will only divert a message to an address on the same server. If you want to divert to an address on a different server, a common pattern would be to divert to a local store-and-forward queue, then set up a bridge that consumes from that queue and forwards to an address on a different server.

Diverts are therefore a very sophisticated concept. When combined with bridges, diverts can be used to create interesting and complex routings. The set of diverts on a server can be thought of as a type of routing table for messages. Combining diverts with bridges allows you to create a distributed network of reliable routing connections between multiple geographically distributed servers, creating your global messaging mesh. See Configuring Core Bridges for more information on how to use bridges.

Diverts can be configured to apply a Transformer and an optional message filter. An optional message filter helps to divert only messages which match the specified filter. For more information on filters see Filter Expressions and Message Selectors.

A transformer is used for transforming messages to another form. When a transformer is specified, all diverted messages are transformed by the Transformer. All transformers must implement the org.apache.activemq.artemis.core.server.cluster.Transformer interface:

package org.apache.activemq.artemis.core.server.cluster;
import org.apache.activemq.artemis.core.server.ServerMessage;

public interface Transformer {
   ServerMessage transform(ServerMessage message);

To enable JBoss EAP messaging to instantiate an instance of your transformer implementation, it should be included in a JBoss EAP module, and the module should be added as a dependency to the org.apache.activemq.artemis module. See Create a Custom Module in the JBoss EAP Configuration Guide for information on how to create a custom module. To add a dependency to the org.apache.activemq.artemis module, open the file EAP_HOME/modules/system/layers/base/org/apache/activemq/artemis/main/module.xml in a text editor and add your <module> to the list of <dependencies> like so:

<module xmlns="urn:jboss:module:1.3" name="org.apache.activemq.artemis">
      <module name="<YOUR_MODULE_NAME>" />

23.1. Exclusive diverts

Below is in an example of an exclusive divert as it might appear in configuration:

  filter="office='New York'"

In this example, a divert called prices-divert is configured that will divert any messages sent to the address jms.topic.priceUpdates, which maps to any messages sent to a JMS topic called priceUpdates, to another local address jms.queue.priceForwarding, corresponding to a local JMS queue called priceForwarding

We also specify a message filter string so that only messages with the message property office with a value of New York will be diverted. All other messages will continue to be routed to the normal address. The filter string is optional, if not specified then all messages will be considered matched.

Note that a transformer class is specified. In this example the transformer simply adds a header that records the time the divert happened.

This example is actually diverting messages to a local store and forward queue, which is configured with a bridge that forwards the message to an address on another server. See Configuring Core Bridges for more details.

23.2. Non-exclusive diverts

Below is an example of a non-exclusive divert. Non exclusive diverts can be configured in the same way as exclusive diverts with an optional filter and transformer.


The above divert takes a copy of every message sent to the address jms.queue.orders, which maps to a JMS Queue called orders, and sends it to a local address called jms.topic.SpyTopic, corresponding to a JMS topic called SpyTopic).

Creating diverts

Use the management CLI to create the type of divert you want:


Non-exclusive diverts are created by default. To create an exclusive divert use the exclusive attribute:


The below table captures a divert’s attributes and their description. You can have the management CLI display this information using the following command:



Address to divert from. Required.


Whether the divert is exclusive, meaning that the message is diverted to the new address, and does not go to the old address at all. The default is false.


An optional filter string. If specified then only messages which match the filter expression will be diverted.


Address to divert to. Required.


Routing name of the divert.


The name of a class used to transform the message’s body or properties before it is diverted.