Content Filtering

One of the most powerful features of AMPS is content filtering. With content filtering, filters based on message content are applied at the server, so that your application and the network are not utilized by messages that are uninteresting for your application. For example, if your application is only displaying messages from a particular user, you can send a content filter to the server so that only messages from that particular user are sent to the client. The Filtering Subscriptions by Content under the AMPS User Guide provides full details on content filtering. The AMPS Expressions section of the AMPS User Guide describes the basic syntax of AMPS expressions, including content filters, and the AMPS Functions section describes functions that are available for use in filters.

To apply a content filter to a subscription, simply pass it into the client.subscribe() call:

for (auto message : ampsClient.subscribe("messages", 0, "/sender = 'mom'"))
{
    // process messages from mom
}

In this case, the application will receive messages where the sender field equals mom.

In this example, we have passed in a content filter /sender = 'mom'. This will result in the server only sending us messages, from the messages topic, that have the sender field equal to mom in the message.

For example, the AMPS server will send the following message, where /sender is mom:

{
    "sender" : "mom",
    "text" : "Happy Birthday!",
    "reminder" : "Call me Thursday!"
}

The AMPS server will not send a message with a different /sender value:

{
    "sender" : "henry dave",
    "text" : "Things do not change; we change."
}

Last updated