description |
---|
This page provides the technical details of the Message Filtering policy |
{% hint style="warning" %} This feature requires Gravitee's Enterprise Edition. {% endhint %}
The message-filtering
policy enables the API publisher to create and enforce a filter that controls which messages are streamed to the subscriber/consumer, given a defined set of criteria.
Functional and implementation information for the message-filtering
policy is organized into the following sections:
{% hint style="warning" %} This policy can be applied to v4 message APIs. It cannot be applied to v2 APIs or v4 proxy APIs. {% endhint %}
{% tabs %} {% tab title="Message API example" %} If this is my message:
{
"productId": "1234",
"value": "any value"
}
I will be able to filter any messages according to subscriptions metadata productId
by configuring the policy as follows:
{
"name": "Products filter",
"description": "Filter messages based on subscription product id",
"enabled": true,
"policy": "message-filtering",
"configuration": {
"filter": "#jsonPath(#message.content, '$.productId') == '#subscription.metadata.productId'"
}
}
{% endtab %} {% endtabs %}
Sample policy configuration:
{% code title="Sample Configuration" %}
{
"name": "Message filtering",
"description": "Apply filter to messages",
"enabled": true,
"policy": "message-filtering",
"configuration": {
"filter": "{#jsonPath(#message.content, '$.feature') == #subscription.metadata.feature}"
}
}
{% endcode %}
The phases checked below are supported by the message-filtering
policy:
v2 Phases | Compatible? | v4 Phases | Compatible? |
---|---|---|---|
onRequest | false | onRequest | false |
onResponse | false | onResponse | false |
onRequestContent | false | onMessageRequest | true |
onResponseContent | false | onMessageResponse | true |
You can configure the message-filtering
policy with the following options:
Property | Required | Description | Type | Default |
---|---|---|---|---|
filter | true | The filter's rule | string | - |
{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-message-filtering/blob/master/CHANGELOG.md" %}