20.7. 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:
  • 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
Diverts can be configured to apply a 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:
  • 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
You can combine diverts with bridges to create various routings.

20.7.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 address
  • forwarding-address: Messages are diverted to this address from the old address
  • filter-string: Messages which match the filter-string value are diverted. All other messages are routed to the normal address
  • transformer-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 diverted
  • exclusive: Used to enable or disable exclusive divert