Content Matchers

A content matcher filters the inbound stream of messages for a subscriber.

Content matchers operate during the match phase of message delivery. (Also see Subscriber Interest.)

A subscriber can have at most one content matcher. A subscriber without a content matcher distributes all inbound messages to its event queue: it does not filter out any messages. In contrast, a subscriber with a content matcher distributes only the messages that match it.

An inbox subscriber cannot have a content matcher. An inbox subscriber always receives all the messages sent to its inbox.

Each content matcher has a match string, which defines its filtering action. The match string specifies a set of field names paired with corresponding values. Fields can be matched as true (value present), false (value absent), a string value, or a long value. (see Match Semantics).

Content matchers can be constructed to match on the following which removes the need to construct multiple subscribers.

  • Match on all fields (a logical AND match): The match string matches a message if and only if every field specification in the match string correctly matches the presence, absence, or value of a corresponding field in the message. For example, a subscriber with the following interest would receive messages only if the bank is ABCBank and the type is debits. The subscriber would not receive the message if the publisher were sending a message with bank ABCBank and type of credits.
    {“bank”: “ABCBank”, “type”: “debits”}
    which can be read as:
    ("bank" is "ABCBank") AND ("type" is "debits")

  • Match on one or more fields (a logical OR match): The match string matches a message if any field in the match string matches the presence, absence, or value of a corresponding field in the message. For example, a subscriber with the following interest would receive messages if the bank is ABCBank and the type is debits or credits.

    [{"type": "debits"}, {"type": "credits"}]

    or this shorter syntax:
    {"type": ["debits", "credits"]}
    which can be read as (any bank):
    ("type" is "debits" OR "type" is "credits")

    Caution: A logical OR match is not permitted on the key field in the matcher used by a last-value durable subscriber. A subscriber must specify exactly one string value for the key field.
  • A combination of AND and OR matching For example:
    {“bank”: “ABCBank”, “type”: [“debits”, “credits”]}
    which can be read as:
    ("bank" is "ABCBank") AND ("type" is "debits" OR "type" is "credits")

Note: There are some restrictions on last-value durables with regard to the key field. See Last-Value Durables, "Content Matchers".