Contact Us 1-800-596-4880

Configure Rules on Message Exchanges to Route Messages

Anypoint MQ includes the ability to create intelligent message routing rules to route a subset of the messages published to an exchange to a specific queue.

You configure the message routing rule on the binding on an exchange. When you publish a message to the exchange, the message routing rule routes the message to a queue only if the message includes a property or header that matches the rule.

Any bindings without configured message routing rules continue to receive all messages from the exchange.
Routing rules on exchange bindings

For example, you might want to designate a queue to handle all orders for size medium items and another queue for premium items.

To route messages published to an exchange to specific queues:

  1. Define message routing rules on the binding between the exchange and the queue.

    You configure one message routing rule per binding on the exchange. Anypoint MQ evaluates the configured message routing rules against all headers and properties attributes in the published messages.

  2. Specify filtering criteria by defining properties and headers in the message.

    If you publish the following message to the purchases exchange, the exchange forwards it only to premiumPurchases queue and not to the sizeMedium queue based on the routing rule configuration.

    {
        "headers" : {
            "itemSize" : "large"
        },
        "body" : "User added an item to the cart"
    }

Create a Message Routing Rule

To create a message routing rule:

  1. Log in to Anypoint Platform.

  2. Click MQ in navigation area or the main Anypoint Platform screen.

  3. Click Destinations and then click the name of the exchange to configure rules.

  4. On the Exchange Settings page, click Add Rule to add a rule to a bound queue.

    Add Rule button on the Exchange Settings page
  5. Complete the fields on the Create Routing Rule page.

    Create Routing Rule page
    • Specify the property name and value to match.

    • For each property type, specify a matcher type.

  6. Click Add Rule.

Change a Message Routing Rule

To change a message routing rule:

  1. Log in to Anypoint Platform.

  2. Click MQ in navigation area or the main Anypoint Platform screen.

  3. Click Destinations and then click the name of the exchange to configure rules.

  4. On the Exchange Settings page, click Edit Rule to change a rule on a bound queue.

    Edit Rule button on the Exchange Settings page
  5. On the Edit Routing Rule page, change the rule settings.

    For information about property types and matcher types, see Matcher Type.

  6. Click Save Rule.

Delete a Message Routing Rule

To delete a message routing rule:

  1. Log in to Anypoint Platform.

  2. Click MQ in navigation area or the main Anypoint Platform screen.

  3. Click Destinations and then click the name of the exchange to configure rules.

  4. On the Exchange Settings page, click Delete Rule .

    Delete Rule button on the Exchange Settings page
  5. In the Delete Routing Rule confirmation box, select the checkbox and click Delete Routing Rule to verify that you want to delete the rule.

Create or Change a Message Routing Rule with Anypoint Admin API

For information about using the Anypoint MQ Admin API to manage message routing rules, see Create or Change Message Routing Rules.

Matcher Type

Property Type Matcher Type Description

String

Equals

Message property value is an exact match for the value in this rule.

Prefix

Message property value starts with the value in this rule.

Any of

Message property value matches any of the values in this rule.

None of

Message property value does not match any of the values in this rule.

Exists

Message includes a property with a name that matches the property name in this rule.

Number

Equals

Message property value is equal to the value in this rule.

Less than

Message property value is less than the value in this rule.

Less than or equal

Message property value is less than or equal to the value in this rule.

Greater than

Message property value is greater than the value in this rule.

Greater than or equal

Message property value is greater than or equal to the value in this rule.

Range

Message property value is within the inclusive range of values specified in this rule.

None of

Message property value does not match any of the values in this rule.

Exists

Message includes a property with a name that matches the property name in this rule.

Property values support the period (.) character (not the comma (,) character) for decimal notation in numeric property values.

If you create routing rules on numeric property values and you use Anypoint MQ Connector to publish messages, you must upgrade to Anypoint MQ Connector version 3.2.0 or later. Previous versions of the connector send all property values as strings, which results in messages not matching routing rules on numeric properties.

Send a Message with Routing Properties

To send messages to an exchange and route them to specific queues, use either:

To view the routing properties on a published message:

  1. In the Message Sender page for the exchange, click View Messages for a queue that is bound to the exchange.

    Anypoint MQ displays the Message Browser page for the selected queue.

  2. Click Get Messages.

  3. Click the message row to view the message payload, including the user properties, in the details pane:

    View user properties in the Message Browser page

Requirements and Restrictions

If you create routing rules on numeric property values and you use Anypoint MQ Connector to publish messages, you must upgrade to Anypoint MQ Connector version 3.2.0 or later. Previous versions of the connector send all property values as strings, which results in messages not matching routing rules on numeric properties.

Anypoint MQ supports message routing rules with the following restrictions:

  • Exchanges must have 10 or fewer queue bindings.

    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.

  • You can configure a message routing rule on only one property with the following restrictions:

    • Maximum size of the property name is 180 bytes.

    • Maximum size of the property value is 45 KB.

  • Property values for routing rules can contain whitespace, alphanumeric (a-z, A-Z, 0-9), and punctuation (@ ! & | # $ % - _ : ; , . ') characters.

Anypoint MQ evaluates messages against the routing rule only if they meet the following criteria:

  • Total number of headers and properties is fewer than 500.

    This total includes operational headers, such as messageId and createdTimestamp, that Anypoint MQ creates.

  • Maximum total size of headers and properties is 215 KB.

If a message doesn’t meet these criteria, Anypoint MQ ignores the headers and properties when evaluating the message against the message routing rules.

Anypoint MQ retains the headers and properties in the payload and, when it publishes the message to the exchange, the headers and properties are available for consumption.