Sending Messages to Multiple Queues Using Message Exchanges
You can send messages to multiple standard queues simultaneously by binding those queues to a message exchange.
You can also route messages to specific queues that are bound to the message exchange by creating intelligent message-routing rules on the bindings. For information, see Route Messages by Configuring Rules on Message Exchanges.
The maximum size of a message sent to a message exchange is 10 MB. You can bind a maximum of 450 queues to a message exchange. You can bind a maximum of 10 queues to an exchange with message routing rules defined. If an exchange has more than 10 queue bindings, you cannot use intelligent message routing.
Before creating a message exchange, create one or more queues. For information, see Create a Queue.
Message exchanges support only the Publish operation; they don’t support the Consume operation. Anypoint MQ forwards messages published to a message exchange to the bound queues and the app consumes from the queue. If an app attempts to consume from a message exchange,
the Anypoint MQ REST API throws the following error:
|
Create a Message Exchange
To create a message exchange:
-
Sign in to Anypoint Platform.
-
Click MQ from the navigation menu or the main Anypoint Platform screen.
-
Click Destinations.
-
Click the Add icon to display the menu:
-
Select Exchange.
For Queue or FIFO Queue, see Configuring and Using Queues.
-
In the Create Exchange page, name the message exchange.
Message exchange names can contain up to 127 alphanumeric (a-z, A-Z, 0-9) and punctuation (. -) characters. They cannot contain spaces or other characters.
-
Click the checkboxes to bind queues to this message exchange:
-
Click Save Changes.
-
In the Destinations page, click the message exchange type for the new exchange to display the bound queues in the details pane:
Bind a Queue to a Message Exchange
You can bind a maximum of 450 queues to a message exchange. You can bind a maximum of 10 queues to an exchange with message routing rules defined. If an exchange has more than 10 queue bindings, you cannot use intelligent message routing. |
To bind a queue to a message exchange:
-
In Anypoint Platform > MQ, click Destinations in the navigation menu.
-
Click the message exchange ID to display the Exchange Settings page:
-
In the settings page, click Bind or Unbind for each single queue you want to bind to or unbind from the message exchange.
To select multiple queues to bind to the exchange, select the checkboxes and click the Bind Selected Queues button that appears:
Send a Message to a Message Exchange
Sending a message to a message exchange is similar to sending a message to a queue. The only difference is that you can get the message from any queue bound to a message exchange. The maximum size for a message sent to a message exchange is 10 MB.
If the payload contains any format except text (such as CSV, HTML, JSON, and XML), Anypoint MQ converts it to a string before sending, which increases the payload size.
This conversion might result in the payload exceeding the maximum payload size of 10 MB and causing a Payload too large
error.
To send a message to a message exchange:
-
In Anypoint Platform > MQ, click Destinations in the navigation menu.
-
Click the message exchange ID to display the Exchange Settings page.
-
In the settings page, click Message Sender in the navigation menu:
-
Leave the Type field set to Text.
-
Enter text in the Payload field, such as
Hello Queues from myMessageExchange
. -
If you want, toggle Add User Properties, specify the property name-value pairs to send, and click Add Property:
-
Click Send.
-
Click View Messages for a queue that is bound to the exchange to view the queue with the Message Browser.
You also send JSON content or comma-separated values (CSV) in the payload by changing the message Type value. See Send a JSON Message to a Queue and Send a CSV Message to a Queue.
Delete a Message Exchange
If a message exchange is no longer needed, you can delete it. All queue bindings for the deleted exchange queue are lost. Clients can’t publish or subscribe to the exchange.
To delete a message exchange:
-
In Anypoint Platform > MQ, click Destinations in the navigation menu.
-
In the Destinations page, click the message exchange type for the exchange to display the details pane.
-
Click the Delete icon:
-
In the Delete Exchange window, select the checkbox to confirm and click Delete Exchange.