LibraryToggle FramesPrintFeedback

If you are using a network topology such as a hub-and-spoke (see Figure 2.9) or a tree (see Figure 2.10), the network route is inherently deterministic and you do not need to concern yourself with choosing an optimum route. For other topologies, however, it is possible to have multiple alternative routes joining a producer to a consumer across the network. In such cases, it is usually preferable to simplify the routing behavior, so that an optimum route is preferred by the network.

Certains kinds of network—for example, Hub and spokes topology and Tree topology—have determinate routes. That is, there exists a unique route between any two brokers in the network.

If your network is a mesh, on the other hand, you might find that there are multiple routes joining some pairs of brokers. For such indeterminate networks, it is normally preferable for messages to propagate along the shortest route, in order to maximize the efficiency of the network. To ensure that the shortest route is preferred, enable the decreaseNetworkConsumerPriority option on all of the connectors in the network (the default is false). For example, you can enable this option on a network connector as follows:

<networkConnectors>
    <networkConnector name="linkToBrokerB"
       uri="static:(tcp://localhost:61002)"
       networkTTL="3"
       decreaseNetworkConsumerPriority="true" />
</networkConnectors>

When decreaseNetworkConsumerPriority is set to true, the priority is set as follows:

  • Local consumers (attached directly to the broker) have a priority of 0.

  • Network subscriptions have an initial priority of -5.

  • The priority of a network subscription is reduced by 1 for every network hop that it traverses

A broker sends messages preferentially to the subscription with the highest priority, but if the prefetch buffer is full, the broker will divert messages to the subscription with the next highest priority. If multiple subscriptions have the same priority, the broker distributes messages equally between those subscriptions.

Figure 2.18 illustrates the effect of setting this option in a broker network.


In this network, there are three alternative routes connecting producer P to consumer C1—these are PBAFEC1 (three broker hops), PBEC1 (one broker hop), and PBCDEC1 (three broker hops). When decreaseNetworkConsumerPriority is enabled, the route, PBEC1, has highest priority, so messages from P to C1 are sent preferentially along this route.

In some cases, setting decreaseNetworkConsumerPriority to true is not enough to ensure deterministic routing in a network. Consider the network of brokers, A, B, and C, shown in Figure 2.19. In this scenario, a producer, P, (which writes messages to queue, foo) connects to broker A and a consumer, C1, (which reads messages from queue, foo) connects to broker B. The network TTL is equal to 2, so two alternative routes are possible: the short route, PABC1, and the long route, PACBC1.


Now, if you set decreaseNetworkConsumerPriority to true, the short route is preferred. So, messages are propagated along the route PABC1. However, under heavy load conditions, the short route, PABC1, can become overloaded and in this case the broker, A, will fall back to the long route, PACBC1. The problem with this scenario is that when the consumer, C1, shuts down, it can lead to messages getting stuck on broker C. In order to avoid this problem, it is recommended that you set the suppressDuplicateQueueSubscriptions option to true on all of the network connectors in you network. For example, you can set this option as follows:

<networkConnectors>
    <networkConnector name="linkToBrokerB"
       uri="static:(tcp://localhost:61002)"
       networkTTL="3"
       decreaseNetworkConsumerPriority="true"
       suppressDuplicateQueueSubscriptions="true"/>
</networkConnectors>

The effect of enabling this option is that the broker allows only a single queue subscription to be created for a given consumer. This means that only a single route can be created between a producer and a consumer, so that the routing becomes fully deterministic. In general, it is recommended that you enable both the decreaseNetworkConsumerPriority option and the suppressDuplicateQueueSubscriptions option together.

[Note]Note

In the example shown in Figure 2.19, you could have suppressed the long route by reducing the network TTL to 1. Normally, however, in a large network you do not have the option of reducing the network TTL arbitrarily. The network TTL has to be large enough for messages to reach the most distant brokers in the network.

Comments powered by Disqus