Show Table of Contents
18.6. Diverts
Diverts are objects configured in HornetQ; which help in diverting messages from one address (to which the message is routed) to some other address. Diverts can be configured in server configuration files (
standalone.xml and domain.xml).
Diverts can be classified into the following types:
Diverts can be configured to apply a
- Exclusive Divert: A message is only diverted to a new address and not sent to the old address at all
- Non-exclusive Divert: A message continues to go 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
Transformer and an optional message filter. An optional message filter helps only divert messages which match the specified filter. A transformer is used for transforming messages to another form. When a transformer is specified; all diverted messages are transformed by the Transformer.
A divert only diverts a message to an address within the same server. If you need to divert a message to an address on a different server, you can follow the pattern described below:
You can combine diverts with bridges to create various routings.
- Divert messages to a local store and forward queue. Setup a bridge which consumes from that queue and directs messages to an address on a different server
18.6.1. Exclusive Divert
An exclusive divert; diverts all messages from an old address to a new address. Matching messages are not routed to the old address at all. You can enable exclusive divert by setting
exclusive attribute as true in standalone.xml and domain.xml server configuration files.
The following example shows an exclusive divert configured in server configuration file(s):
<divert name="prices-divert">
<address>jms.topic.priceUpdates</address>
<forwarding-address>jms.queue.priceForwarding</forwarding-address>
<filter string="office='New York'"/>
<transformer-class-name>
org.hornetq.jms.example.AddForwardingTimeTransformer
</transformer-class-name>
<exclusive>true</exclusive>
</divert>
The following list describes the attributes used in the above example:
address: Messages sent to this address are diverted to another addressforwarding-address: Messages are diverted to this address from the old addressfilter-string: Messages which match thefilter-stringvalue are diverted. All other messages are routed to the normal addresstransformer-class-name: If you specify this parameter; it executes transformation for each matching message. This allows you to change a message's body or property before it is divertedexclusive: Used to enable or disable exclusive divert
18.6.2. Non-exclusive Divert
Non-exclusive diverts forward a copy of the original message to the new address. The original message continues to arrive at the old address. You can configure non-exclusive diverts by setting
exclusive property as false in standalone.xml and domain.xml server configuration files.
The following example shows a non-exclusive divert:
<divert name="order-divert"> <address>jms.queue.orders</address> <forwarding-address>jms.topic.spyTopic</forwarding-address> <exclusive>false</exclusive> </divert>The above example makes a copy of every message sent to
jms.queue.orders address and sends it to jms.topic.spyTopic address.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.