Routing is the process by which messages are delivered to their destinations. To accomplish this, AMQ Interconnect provides two routing mechanisms: message routing and link routing. Message routing Routing is performed on messages as producers send them to a router. When a message arrives on a router, the router routes the message and its
settlement based on the message’s address and routing pattern. Figure 5.1. Message Routing In this diagram, the message producer attaches a link to the router, and then sends a message over the link. When the router receives the message, it identifies the message’s destination based on the message’s address, and then uses its routing table to determine the best route to deliver the message either to its destination or to the next hop in the route. All dispositions (including settlement) are propagated along the same path that the original message transfer took. Flow control is handled between the sender and the router, and then between the router and the receiver. Link routingRouting is performed on link-attach frames, which are chained together to form a virtual messaging path that directly connects a sender and receiver. Once a link route is established, the transfer of message deliveries, flow frames, and dispositions is performed across the link route. Figure 5.2. Link Routing In this diagram, a router is connected to clients and to a broker, and it provides a link route to a queue on the broker (my_queue). The sender connects to the router, and the router propagates the link-attaches to the broker to form a direct link between the sender and the broker. The sender can begin sending messages to the queue, and the router passes the deliveries along the link route directly to the broker queue. 5.1. Comparison of Message Routing and Link RoutingWhile you can use either message routing or link routing to deliver messages to a destination, they differ in several important ways. Understanding these differences will enable you to choose the proper routing approach for any particular use case. 5.1.1. When to Use Message RoutingMessage routing is the default routing mechanism. You can use it to route messages on a per-message basis between clients directly (direct-routed messaging), or to and from broker queues (brokered messaging). Message routing is best suited to the following requirements:
Message routing is not suitable for any of the following requirements:
5.1.2. When to Use Link RoutingLink routing requires more detailed configuration than message routing as well as an AMQP container that can accept incoming link-attaches (typically a broker). However, link routing enables you to satisfy more advanced use cases than message routing. You can use link routing if you need to meet any of the following requirements:
5.2. Configuring Message RoutingWith message routing, routing is performed on messages as producers send them to a router. When a message arrives on a router, the router routes the message and its settlement based on the message’s address and routing pattern. With message routing, you can do the following:
5.2.1. AddressesAddresses determine how messages flow through your router network. An address designates an endpoint in your messaging network, such as:
When a router receives a message, it uses the message’s address to determine where to send the message (either its destination or one step closer to its destination). 5.2.1.1. Mobile AddressesRouters consider addresses to be mobile such that any users of an address may be directly connected to any router in a network and may move around the topology. In cases where messages are broadcast to or balanced across multiple consumers, the address users may be connected to multiple routers in the network. Mobile addresses are rendezvous points for senders and receivers. Messages arrive at the mobile address and are dispatched to their destinations according to the routing defined for the mobile address. The details of these routing patterns are discussed later. Mobile addresses may be discovered during normal router operation or configured through management settings. 5.2.1.1.1. Discovered Mobile AddressesMobile addresses are created when a client creates a link to a source or destination address that is unknown to the router network. Suppose a service provider wants to offer my-service that clients may use. The service provider must open a receiver link with source address my-service. The router creates a mobile address my-service and propagates the address so that it is known to every router in the network. Later a client wants to use the service and creates a sending link with target address my-service. The router matches the service provider’s receiver having source address my-service to the client’s sender having target address my-service and routes messages between the two. Any number of other clients can create links to the service as well. The clients do not have to know where in the router network the service provider is physically located nor are the clients required to connect to a specific router to use the service. Regardless of how many clients are using the service the service provider needs only a single connection and link into the router network. Another view of this same scenario is when a client tries to use the service before service provider has connected to the network. In this case the router network creates the mobile address my-service as before. However, since the mobile address has only client sender links and no receiver links the router stalls the clients and prevents them from sending any messages. Later, after the service provider connects and creates the receiver link, the router will issue credits to the clients and the messages will begin to flow between the clients and the service. The service provider can connect, disconnect, and reconnect from a different location without having to change any of the clients or their connections. Imagine having the service running on a laptop. One day the connection is from corporate headquarters and the next day the connection is from some remote location. In this case the service provider’s computer will typically have different host IP addresses for each connection. Using the router network the service provider connects to the router network and offers the named service and the clients connect to the router network and consume from the named service. The router network routes messages between the mobile addresses effectively masking host IP addresses of the service provider and the client systems. 5.2.1.1.2. Configured Mobile AddressesMobile addresses may be configured using the router autoLink object. An address created via an autoLink represents a queue, topic, or other service in an external broker. Logically the autoLink addresses are treated by the router network as if the broker had connected to the router and offered the services itself. For each configured mobile address the router will create a single link to the external resource. Messages flow between sender links and receiver links the same regardless if the mobile address was discovered or configured. Multiple autoLink objects may define the same address on multiple brokers. In this case the router network creates a sharded resource split between the brokers. Any client can seamlessly send and receive messages from either broker. Note that the brokers do not need to be clustered or federated to receive this treatment. The brokers may even be from different vendors or be different versions of the same broker yet still work together to provide a larger service platform. 5.2.2. Routing PatternsRouting patterns define the paths that a message with a mobile address can take across a network. These routing patterns can be used for both direct routing, in which the router distributes messages between clients without a broker, and indirect routing, in which the router enables clients to exchange messages through a broker. Routing patterns fall into two categories: Anycast (Balanced and Closest) and Multicast. There is no concept of "unicast" in which there is only one consumer for an address. Anycast distribution delivers each message to one consumer whereas multicast distribution delivers each message to all consumers. Each address has one of the following routing patterns, which define the path that a message with the address can take across the messaging network: Balanced An anycast method that allows multiple consumers to use the same address. Each message is delivered to a single consumer only, and AMQ Interconnect attempts to balance the traffic load across the router network. If multiple consumers are attached to the same address, each router determines which outbound path should receive a message by considering each path’s current number of unsettled deliveries. This means that more messages will be delivered along paths where deliveries are settled at higher rates. AMQ Interconnect neither measures nor uses message settlement time to determine which outbound path to use. In this scenario, the messages are spread across both receivers regardless of path length: Figure 5.3. Balanced Message Routing ClosestAn anycast method in which every message is sent along the shortest path to reach the destination, even if there are other consumers for the same address. AMQ Interconnect determines the shortest path based on the topology cost to reach each of the consumers. If there are multiple consumers with the same lowest cost, messages will be spread evenly among those consumers. In this scenario, all messages sent
by Figure 5.4. Closest Message Routing MulticastMessages are sent to all consumers attached to the address. Each consumer will receive one copy of the message. In this scenario, all messages are sent to all receivers: Figure 5.5. Multicast Message Routing 5.2.3. Message SettlementMessage settlement is negotiated between the producer and the router when the producer establishes a link to the router. Depending on the settlement pattern, messages might be delivered with any of the following degrees of reliability:
AMQ Interconnect treats all messages as either pre-settled or unsettled, and it is responsible for propagating the settlement of each message it routes. Pre-settled Sometimes called fire and forget, the router settles the incoming and outgoing deliveries and propagates the settlement to the message’s destination. However, it does not guarantee delivery. Unsettled The router propagates the settlement between the sender and receiver, and guarantees one of the following outcomes:
5.2.4. Routing Pattern ReliabilityThe following table describes the levels of reliability provided by each routing pattern:
5.2.5. Configuring Addresses for Prioritized Message DeliveryYou can set the priority level of an address to control how AMQ Interconnect processes messages sent to that address. Within the scope of a connection, AMQ Interconnect attempts to process messages based on their priority. For a connection with a large volume of messages in flight, this lowers the latency for higher-priority messages. Assigning a high priority level to an address does not guarantee that messages sent to the address will be delivered before messages sent to lower-priority addresses. However, higher-priority messages will travel more quickly through the router network than they otherwise would. You can also control the priority level of individual messages by setting the priority level in the message header. However, the address priority takes precedence: if you send a prioritized message to an address with a different priority level, the router will use the address priority level. Procedure
Additional resources
5.2.6. Routing Messages Between ClientsYou can route messages between clients without using a broker. In a brokerless scenario (sometimes called direct-routed messaging), AMQ Interconnect routes messages between clients directly. To route messages between clients, you configure an address with a routing distribution pattern. When a router receives a message with this address, the message is routed to its destination or destinations based on the address’s routing distribution pattern. Procedure
5.2.7. Routing Messages Through a Broker QueueYou can route messages to and from a broker queue to provide clients with access to the queue through a router. In this scenario, clients connect to a router to send and receive messages, and the router routes the messages to or from the broker queue. You can route messages to a queue hosted on a single broker, or route messages to a sharded queue distributed across multiple brokers. Figure 5.6. Brokered Messaging In this diagram, the sender connects to the router and sends messages to my_queue. The router attaches an outgoing link to the broker, and then sends the messages to my_queue. Later, the receiver connects to the router and requests messages from my_queue. The router attaches an incoming link to the broker to receive the messages from my_queue, and then delivers them to the receiver. You can also route messages to a sharded queue, which is a single, logical queue comprised of multiple, underlying physical queues. Using queue sharding, it is possible to distribute a single queue over multiple brokers. Clients can connect to any of the brokers that hold a shard to send and receive messages. Figure 5.7. Brokered Messaging with Sharded Queue In this diagram, a sharded queue (my_queue) is distributed across two brokers. The router is connected to the clients and to both brokers. The sender connects to the router and sends messages to my_queue. The router attaches an outgoing link to each broker, and then sends
messages to each shard (by default, the routing distribution is Procedure
5.2.7.1. Configuring Waypoint AddressesA waypoint address identifies a queue on a broker to which you want to route messages. You need to configure the waypoint address on each router that needs to use the address. For example, if a client is connected to Router A to send messages to the broker queue, and another client is connected to Router B to receive those messages, then you would need to configure the waypoint address on both Router A and Router B. Prerequisites An incoming connection ( Procedure
5.2.7.2. Connecting a Router to the BrokerAfter you add waypoint addresses to identify the broker queue, you must connect a router to the broker using autolinks. With autolinks, client traffic is handled on the router, not the broker. Clients attach their links to the router, and then the router uses internal autolinks to connect to the queue on the broker. Therefore, the queue will always have a single producer and a single consumer regardless of how many clients are attached to the router. If the connection to the broker fails, AMQ Interconnect automatically attempts to reestablish the connection and reroute message
deliveries to any available alternate destinations. However, some deliveries could be returned to the sender with a
5.2.8. Handling Undeliverable Messages for an AddressYou handle undeliverable messages for an address by configuring autolinks that point to fallback destinations. A fallback destination (such as a queue on a broker) stores messages that are not directly routable to any consumers. During normal message delivery, AMQ Interconnect delivers messages to the consumers that are attached to the router network. However, if no consumers are reachable, the messages are diverted to any fallback destinations that were configured for the address (if the autolinks that point to the fallback destinations are active). When a consumer reconnects and becomes reachable again, it receives the messages stored at the fallback destination. AMQ Interconnect preserves the original delivery order for messages stored at a fallback destination. However, when a consumer reconnects, any new messages produced while the queue is draining will be interleaved with the messages stored at the fallback destination. Procedure This procedure enables fallback for an address and configures autolinks to connect to the broker queue that provides the fallback destination for the address.
5.2.9. Example: Routing Messages Through Broker QueuesThis example shows how waypoints and autolinks can route messages through a pair of queues on a broker. 5.2.9.1. Router Configurationconnector { 1 name: broker role: route-container host: 198.51.100.1 port: 61617 saslMechanisms: ANONYMOUS } address { 2 prefix: queue waypoint: yes } autoLink { 3 address: queue.first direction: in connection: broker } autoLink { 4 address: queue.first direction: out connection: broker } autoLink { 5 address: queue.second direction: in connection: broker } autoLink { 6 address: queue.second direction: out connection: broker } 1 The outgoing connection from the router to the broker. The The
namespace queue on the broker to which the router should route messages. All addresses that start with The incoming autolink from The outgoing autolink from the router to The incoming autolink from The outgoing autolink from the router to 5.2.9.2. How the Messages are RoutedInitially, when the broker is offline, the autolinks are inactive. $ qdstat --autolinks AutoLinks addr dir phs extAddr link status lastErr ======================================================== queue.first in 1 inactive queue.first out 0 inactive queue.second in 1 inactive queue.second out 0 inactive Once the broker is online, the autolinks
attempt to activate. In this case, the broker starts with the $ qdstat --autolinks AutoLinks addr dir phs extAddr link status lastErr =========================================================================== queue.first in 1 6 active queue.first out 0 7 active queue.second in 1 failed Node not found: queue.second queue.second out 0 failed Node not found: queue.second The producer now connects to the router and sends three messages to $ python simple_send.py -a 127.0.0.1/queue.first -m3 all messages confirmed The router’s address statistics show that the messages were delivered to the queue. $ qdstat -a Router Addresses class addr phs distrib in-proc local remote cntnr in out thru to-proc from-proc ======================================================================================================== mobile queue.first 1 balanced 0 0 0 0 0 0 0 0 0 mobile queue.first 0 balanced 0 1 0 0 3 3 0 0 0 The The consumer now connects to the router and receives
the three messages from $ python simple_recv.py -a 127.0.0.1:5672/queue.first -m3 {u'sequence': int32(1)} {u'sequence': int32(2)} {u'sequence': int32(3)} The router’s address statistics now show that all three messages were received by the consumer from the broker queue. $ qdstat -a Router Addresses class addr phs distrib in-proc local remote cntnr in out thru to-proc from-proc ======================================================================================================== mobile queue.first 1 balanced 0 0 0 0 3 3 0 0 0 mobile queue.first 0 balanced 0 1 0 0 3 3 0 0 0 The command output shows that Phase 1 of the address was used to deliver all three messages from the queue to the consumer. Even in a multi-router network, and with multiple producers and consumers for 5.3. Configuring Link RoutingLink routing provides an alternative strategy for brokered messaging. A link route represents a private messaging path between a sender and a receiver in which the router passes the messages between end points. You can think of a link route as a "virtual connection" or "tunnel" that travels from a sender, through the router network, to a receiver. With link routing, routing is performed on link-attach frames, which are chained together to form a virtual messaging path that directly connects a sender and receiver. Once a link route is established, the transfer of message deliveries, flow frames, and dispositions is performed across the link route. 5.3.1. Link Route AddressesA link route address represents a broker queue, topic, or other service. When a client attaches a link route address to a router, the router propagates a link attachment to the broker resource identified by the address. Using link route addresses, the router network does not participate in aggregated message distribution. The router simply passes message delivery and settlement between the two end points. 5.3.2. Link Route Routing PatternsRouting patterns are not used with link routing, because there is a direct link between the sender and receiver. The router only makes a routing decision when it receives the initial link-attach request frame. Once the link is established, the router passes the messages along the link in a balanced distribution. 5.3.3. Link Route Flow ControlUnlike message routing, with link routing, the sender and receiver handle flow control directly: the receiver grants link credits, which is the number of messages it is able to receive. The router sends them directly to the sender, and then the sender sends the messages based on the credits that the receiver granted. 5.3.4. Creating a Link RouteLink routes establish a link between a sender and a receiver that travels through a router. You can configure inward and outward link routes to enable the router to receive link-attaches from clients and to send them to a particular destination. With link routing, client traffic is handled on the broker, not the router. Clients have a direct link through the router to a broker’s queue. Therefore, each client is a separate producer or consumer. If the connection to the broker fails, the routed links are detached, and the router will attempt to reconnect to the broker (or its backup). Once the connection is reestablished, the link route to the broker will become reachable again. From the client’s perspective, the client will see the detached links (that is, the senders or receivers), but not the failed connection. Therefore, if you want the client to reattach dropped links in the event of a broker connection failure, you must configure this functionality on the client. Alternatively, you can use message routing with autolinks instead of link routing. For more information, see Routing Messages through a Broker Queue. Procedure
5.3.5. Example: Using a Link Route to Provide Client IsolationThis example shows how a link route can connect a client to a message broker that is on a different private network. Router Network with Isolated Clients Public Network +-----------------+ | +-----+ | | B1 | Rp | | | +/--\-+ | | / \ | | / \ | +----/--------\---+ / \ / \ / \ Private Net A / \ Private Net B +--------------/--+ +---\-------------+ | +---/-+ | | +--\--+ | | B2 | Ra | | | | Rb | C1 | | +-----+ | | +-----+ | | | | | | | | | +-----------------+ +-----------------+ Client In this example, client 5.3.5.1. Router Configuration To enable client
The relevant part of the configuration file for router connector { 1 name: broker role: route-container host: 198.51.100.1 port: 61617 saslMechanisms: ANONYMOUS } linkRoute { 2 prefix: b2 direction: in connection: broker } linkRoute { 3 prefix: b2 direction: out connection: broker } 1 The outgoing connection from the router to broker The
incoming link route for receiving links from client senders. Any sender with a target whose address begins with The outgoing link route for sending links to client receivers. Any receivers whose source address begins with This configuration enables router While not required, routers 5.3.5.2. How the Client Receives Messages By using the configured link route, client Router To receive messages from the If broker 5.3.6. Pattern Matching for AddressesIn some router configuration scenarios, you might need to use pattern matching to match a range of addresses rather than a single, literal address. Address patterns match any address that corresponds to the pattern. An address pattern is a sequence of tokens (typically words) that are delimited by either
Example 5.1. Address Pattern This address contains two tokens, separated by the Example 5.2. Address Pattern with Wildcard This address contains three tokens. The The following table shows some address patterns and examples of the addresses that would match them:
Which device is used to select the best path to route a message?A primary function of a router is to determine the best path to use to send packets. To determine the best path, the router searches its routing table for a network address that matches the destination IP address of the packet.
Which layer finds the best path to a destination?The Layer 3, or Network Layer, is responsible for finding the right path for the data packet to reach its destination based on Logical Addresses (means addresses not really present on the network node).
Which device forwards data packets to destinations using the best possible paths?A router inspects a given data packet's destination Internet Protocol address (IP address), calculates the best way for it to reach its destination and then forwards it accordingly. A router is a common type of gateway. It is positioned where two or more networks meet at each point of presence on the internet.
Which device is used to identify the path of one network to another?Router. A router directs data requests from one network to another. Routers examine incoming packets to determine the appropriate destination IP address and then forward the packet to that destination. A router can also enable internet access through its connection to a modem, or as a combined modem-router.
|