I want to distribute messages from an on-premises broker to an Amazon MQ for RabbitMQ broker using the RabbitMQ Federation plugin.
Short description
To set up the RabbitMQ Federation plugin on an Amazon MQ for RabbitMQ broker, complete the following tasks on the downstream broker:
- Create one or more federation-upstream parameters that define the federation connections to remote queues or exchanges.
- Create a RabbitMQ policy that allows specific remote queues or exchanges to become federated.
- Create an exchange with a new queue bound to it to receive messages.
Note: Amazon MQ doesn't support private Amazon MQ brokers to be used as upstream queue or exchange.
Resolution
The following procedure requires two brokers:
Create one or more federation-upstream parameters
To create one or more federation-upstream parameters that define the federation connections to remote queues or exchanges, complete the following steps:
-
Open the Amazon MQ console.
-
In the navigation pane, choose Brokers.
-
In the Name column, choose the name of your downstream broker.
-
In the Connections pane, select the URL that's listed below RabbitMQ web console. The RabbitMQ web console login page for your downstream broker opens.
-
Enter your Username and Password for your broker. Then, choose Login to log in to the RabbitMQ web console.
-
In the RabbitMQ web console, choose the Admin tab. Then, in the navigation pane, choose Federation Upstreams.
-
Choose Add a new upstream.
-
For Name, enter a name for your upstream parameter.
-
For URI, delete the default amqp:// text and enter the upstream broker's URI in the following format:
amqps://$UPSTREAM_BROKER_USER:$UPSTREAM_BROKER_PASSWORD@$UPSTREAM_BROKER_ENDPOINT:5671
-
Choose Add upstream.
Create a RabbitMQ policy that allows specific remote queues or exchanges to become federated
To create a RabbitMQ policy that allows specific remote queues or exchanges to become federated, complete the following steps:
- Open the RabbitMQ web console of the downstream broker.
- Choose the Admin tab. Then, in the navigation pane, choose Policies.
- Choose Add / update a policy.
- For Name, enter a name for your policy.
- For Pattern, enter a regular expression that matches the queues or exchange names that you want to allow to become federated.
- For Apply to, select Exchanges from the dropdown list.
Note: Applying the policy to Exchanges allows the policy to apply to exchanges in the downstream broker only.
- For Priority, enter 1.
Note: The Priority setting is used to determine which policy is applied to an exchange or queue if multiple policies have the same name. Specifying the Priority setting as 1 prevents any default Amazon MQ policies that have the same name from overriding the policy.
- For Definition, enter federation-upstream-set as the key in the first text box. Then, enter all as the value in the second text box.
- Choose Add / update policy.
Create an exchange with a new queue bound to the exchange to receive messages
To create an exchange with a new queue bound to the exchange to receive messages, complete the following steps:
- Open the RabbitMQ web console of the downstream broker.
- Choose the Queues tab.
- Under Add a new queue, for Name, enter a name for the new queue that receives messages.
- Choose Add queue.
- Choose the Exchanges tab.
- Under Add a new exchange, for Name, enter the regular expression that matches the exchange name that you used when you created the RabbitMQ policy.
- Choose Add exchange.
Note: RabbitMQ also creates an exchange on the upstream broker that has the same name automatically.
- Choose the Exchanges tab.
- Under All exchanges, choose the name of the new exchange.
- Under Bindings, for Add binding from this exchange, select To queue from the dropdown. Then, enter the name of the queue that you created.
- For Routing key, enter a value of your choice. The messages that are sent to the exchange using the routing key value are also sent to the queue bound to this exchange.
- Choose Bind.
Test the setup
To test the setup for the RabbitMQ Federation plugin, complete the following tasks:
Send a test message to the upstream broker's source exchange
- Open the RabbitMQ web console of the upstream broker.
Note: For more information about how to access the RabbitMQ web console, see Management plugin in the RabbitMQ documentation.
- Choose the Exchanges tab. Then, select the source exchange's name.
- In the navigation pane, choose Publish message.
- In the Routing key text box, enter the routing key value.
- In the Payload text box, enter a test message.
Note: You can leave the Headers and Properties text boxes blank.
- Choose the Publish message button. The test message is sent to the source exchange. If your federation parameter is correctly configured, then the message is also sent to the downstream broker's destination queue.
Verify that the test message is received by the downstream broker's destination queue
- Open the RabbitMQ web console of the downstream broker.
- Choose the Queues tab. Then, choose the destination queue's name.
- In the navigation pane, choose Get messages.
- Choose the Get messages button. If the federation parameter is correctly configured, the test message that you sent to the source exchange appears as the Payload value.
Related information
How do I set up the RabbitMQ Shovel plugin on my Amazon MQ broker?