Skip to content

Message routing map

zhenchuan edited this page Oct 8, 2014 · 8 revisions

A routing map defines where to send the message according to its routing key and filtering criteria. "Where" means which sinks a message should go to. Its format is JSON map with the routing key as the key and the routing information as the value including the following:

  • where: This is the list of com.netflix.suro.routing.RoutingMap.Route. Route is a pair of the sink name and the filter. If the filter is not specified, its value will be null and nothing will be filtered.
  • filter: When the filter is applied to a message and its return value is true, the message will be routed to the specified sinks. Currently, three kinds of filters are supported:
    • A regex filter that is applied on the string representation of messages
    • A XPath-based filter that can be applied to any Javabean-like object as well Java collection objects. It can be customized to support arbitrary payload encoding. Suro by default supports JSON encoded payload.
    • A routing key filter that applies regex patterns on routing key only

The following is the example of routing map:

{
    "routing_key1": {
        "where": [
            {
                "sink": "sink1"
            },
            {
                "sink": "sink2"
            }
        ],
        "filter": {
            "type": "regex",
            "regex": "^prefix*"
        }
    },
    "routing_key2": {
        "where": [
            {
                "sink": "sink2",
                "filter": {
                    "type": "xpath",
                    "filter": "xpath(\"//customerInfo/country\") =~ \"(?i)^US\"",
                    "converter": {
                        "type": "jsonmap"
                    }
                }
            },
            {
                "sink": "sink3",
                "filter": {
                    "type": "xpath",
                    "filter": "xpath(\"//responseInfo/status\") >= 400",
                    "converter": {
                        "type": "jsonmap"
                    }
                }
            }
        ]
    }
}

A message with routing_key1 will be routed to sink1 and sink2 only if its message body contains the pattern "prefix". As for a message with routing_key2, the situation is slightly complicated:

  • If the message contains a call path //customerInfo/country, and its value matches the regex pattern /^US/i, then the message will be dispatched to the sink2. For example, the message can be a JavaBean-like object that contains property customerInfo, which is associated with a JavaBean-like object that contains a property "country", which has value "USA". Or, the message can be of type Map<String, Map<String, String>>, and it contains a key "customerInfo", whose value contains a key "country", whose value is "USA".
  • If the message contains a call path //responseInfo/status, whose value is greater than or equal to 400, then the message will be dispatched to sink3.

Unregistered routing key

For unregistered routing keys, all of them would be sent to 'default' sink in sink configuration.

Clone this wiki locally