Federation is used to provide geographical distribution of brokers. A number of individual brokers, or clusters of brokers, can be federated together. This allows client machines to see and interact with the federation as though it were a single broker. Federation can also be used where client machines need to remain on a local network, even though their messages have to be routed out.
Federation is used primarily for connecting disparate locations across a wide area network. Full connectivity across an enterprise can be achieved while keeping local message traffic isolated to a single location. Departmental brokers can be specified with individual policies that control inter-departmental message traffic flow.
Some applications can benefit from having a broker co-resident with the client. This is good for situations where the client produces data that must be delivered reliably but connectivity can not be guaranteed. In this case, a co-resident broker provides queueing and durability that is not available in the client on its own.
Federation bridges disjointed IP networks. Message brokers can be configured to allow message connectivity between networks where there is no IP connectivity. For example, an isolated, private IP network can have messaging connectivity to brokers in other outside IP networks.
Federation is configured through a series of links and routes.
A link is a connection between two brokers that allows messages to be passed between them. A link is a transport level connection (using a protocol such as TCP, RDMA, or SSL) that is initiated by a broker and accepted by another broker. The broker that initiates the link is considered the client in the connection. The broker that receives that connection will not treat it any differently from any other client connection, other than annotating it as being for federation.
Routes are the paths that messages take from one broker to another, and can run along one or more links to the final destination. A route is associated with an AMQP session established over the link connection. A route controls the flow of messages across the link between brokers, and multiple routes can share the same link. Messages will flow over a single route in only one direction. For bi-directional connectivity a pair of routes must be created, one for each direction of message flow. Routes always consist of a session and a subscription for consuming messages. Depending on the configuration, a route can have a private queue on the source broker with a binding to an exchange on that broker.
Routes can be configured from either the source broker or the destination broker. In most cases, they are configured from the source broker. Sometimes it is more convenient to configure links and routes from the destination broker. For instance, if brokers are co-resident with data sources, each source can be configured to send data to the central broker.
When a link is created on a broker, it will immediately attempt to establish a transport-level connection to another broker. If the connection fails due to a communication error, it will continue trying. The retry interval begins at 2 seconds and, as more attempts are made, grows out to 64 seconds. It will continue to try to make the connection every 64 seconds until explicity told to stop trying. If the connection fails due to an authentication problem, it will not continue to retry.
Links can be made durable by using the --durable option when creating it in the qpid-route tool. Durable links will persist between broker restarts. When the broker starts again the link will be restored and will begin establishing connectivity.
Routes can also be made durable with the --durable option, as long as they run over durable links.
Dynamic routing creates a set of distributed exchanges. All the brokers in a network collectively behave in the same way as a single exchange in a single broker. Each client connects to its local broker, where it can bind queues and publish messages to the distributed exchange.
When configuring dynamic routing, it is only necessary to define which pairs of brokers are connected by a unidirectional route. Queue configuration and bindings are then handled automatically by the brokers in the network.
When a consuming client binds a queue to the distributed exchange, information about that binding is sent to the other brokers in the network. This ensures that any messages matching the binding will be forwarded to the client's local broker. Messages published to the distributed exchange are forwarded to other brokers only if there are remote consumers to receive the messages. The dynamic binding protocol ensures that messages are routed only to brokers with eligible consumers. This includes topologies where messages must make multiple hops to reach the consumer.
An exchange route is like a dynamic route except that the exchange binding is statically set when it is created, and does not dynamically track changes in the network. When an exchange route is created, a private auto-delete, exclusive queue is created on the source broker. The queue is bound to the exchange with the specified key and the destination broker subscribes to the queue with the specified exchange. Only one exchange name is supplied, as exchange routes require that the source and destination exchanges have the same name.
A queue route is created when the destination broker subscribes to a pre-existing queue on the source broker. The queue does not need to be any particular exchange. Queue routes can be used to connect exchanges of different names and types. They can also be used to distribute or balance traffic across multiple destination brokers.
Using qpid-route to manage federation
The
qpid-route utility provides the ability to configure and manage links and routes. If a route is created and a link does not already exist,
qpid-route will automatically create that link.
Note
The command line utilities are included in the python client library package. Follow the installation instructions in the Messaging Installation Guide to install the python-qpid and amqp packages.
Commands are entered at the shell prompt in the format
# qpid-route [options] [command] [destination broker] [source broker]
When adding and deleting routes exchange and routing key information is also required.
Brokers can be specified in a number of different ways. If the broker requires authentication, specify the username and password separated by a
/ character and followed by the
@ character. The broker itself can be specified by either hostname or IP address, which can be followed by a port number separated by a
: character. The format for brokers is:
[username]/[password]@[hostname]|[IP Address]:[port]
Some valid examples are:
localhost
10.1.1.7:10000
broker-host:10000
guest/guest@localhost
To add links, use the
link add command, specifying both the destination broker and the source broker:
$ qpid-route -v link add destination-broker localhost
To delete links, use the
link delete command, specifying both the destination broker and the source broker of the link you wish to remove:
$ qpid-route -v link del destination-broker localhost
To view a complete list of links to a particular broker, use the
link list command, specifying broker you wish to view:
$ qpid-route link list localhost:10001
Host Port Transport Durable State Last Error
=============================================================================
localhost 10002 tcp N Operational
localhost 10003 tcp N Operational
localhost 10009 tcp N Waiting Connection refused
Create dynamic routes using the
dynamic option. When creating a dynamic routing network, the type and name of the exchange must be the same on each broker.
Note
Unless you intend all messaging to be federated, it is strongly recommended that dynamic routes are not created using standard exchanges.
Firstly, create an exchange on each broker:
$ qpid-config -a localhost:10003 add exchange topic fed.topic
$ qpid-config -a localhost:10004 add exchange topic fed.topic
Now, create the dynamic routes:
$ qpid-route dynamic add localhost:10003 localhost:10004 fed.topic
$ qpid-route dynamic add localhost:10004 localhost:10003 fed.topic
To add static exchange routes, use the
route add command. Specify both the destination broker and the source broker. It also requires an exchange type (direct, fanout or topic) and a routing key:
$ qpid-route route add localhost:10001 localhost:10002 amq.topic global.#
Use
# characters as wildcards when specifying the routing key for a topic exchange, to send to all possible matches.
To view a complete list of the routes to a particular broker, use the
route list command, specifying the broker you wish to view:
$ qpid-route route list localhost:10003
localhost:10003 localhost:10004 fed.topic <dynamic>
To add static queue routes, firstly create a queue on the source broker:
$ qpid-config -a localhost:10002 add queue public
Now, create the queue route to the new queue:
$ qpid-route queue add localhost:10001 localhost:10002 amq.fanout public
A more comprehensive view of a network can be achieved using the
route map command, with a single broker name.
qpid-route will then attempt to recursively find all of the brokers related to the starting broker, and map the relationships it finds:
$ qpid-route route map localhost:10003
Finding Linked Brokers:
localhost:10003... Ok
localhost:10004... Ok
Dynamic Routes:
Exchange fed.topic:
localhost:10004 <=> localhost:10003
Static Routes:
none found
To remove all messages currently en-route to a particular broker, use the
route list command, specifying the broker you wish to flush:
$ qpid-route -v route flush localhost
Options for using qpid-route to Manage Federation
|
|---|
-v
|
Verbose output.
|
-q
|
Quiet output, will not print duplicate warnings.
|
-d
|
Make the configuration change durable.
|
-e
|
Delete link after deleting the last route on the link
|
Table 7.2. Options for using qpid-route to manage federation