Help Center/ Simple Message Notification/ User Guide/ Appendix/ Using a Subscription Filtering Policy
Updated on 2024-12-05 GMT+08:00

Using a Subscription Filtering Policy

Scenario

This section describes how to configure a subscription filtering policy when adding a subscription to specify the scope of message publishing. The default filtering policy applies to message attributes. If you have set a filtering policy and message attributes when publishing a message, the system determines whether to push the message to the subscriber based on the filtering policy.

Prerequisites

A topic has been created. For details, see Creating a Topic.

Adding a Subscription

You can add the following subscriptions to the created topic by referring to Adding a Subscription to a Topic.

  • If you add a subscription endpoint A to the topic and want to receive notifications every Sunday and Wednesday morning or afternoon, you can configure the following subscription filtering policy when creating subscription A:
    {
        "filter_polices": [
            {
                "name": "week",
                "string_equals": [
                    "sunday",
                    "wednesday"
                ]
            },
            {
                "name": "time",
                "string_equals": [
                    "morning",
                    "afternoon"
                ]
            }
        ]
    }
  • If you add a subscription endpoint B to the topic and want to receive notifications at night or late night on Monday, Tuesday, and Wednesday, you can configure the following subscription filtering policy when creating the subscription:
    {
        "filter_polices": [
            {
                "name": "week",
                "string_equals": [
                    "monday",
                    "tuesday",
                    "wednesday"
                ]
            },
            {
                "name": "time",
                "string_equals": [
                    "night",
                    "midnight"
                ]
            }
        ]
    }

Publishing a Message

When you publish messages to a topic, different results will be obtained in different scenarios.

For details about how to publish a message, see Introduction.

  • Scenario 1

    The message attribute fields are as follows:

    {
        "name": "week",
        "type": "STRING",
        "value": [
            "sunday"
        ]
    }

    Sending result: The message will only be sent to subscription A because only week is specified, and time is not specified.

  • Scenario 2:

    The message attribute fields are as follows:

    [
        {
            "name": "week",
            "type": "STRING",
            "value": [
                "sunday"
            ]
        },
        {
            "name": "time",
            "type": "STRING",
            "value": [
                "night"
            ]
        }
    ]

    Sending result: Neither subscription A nor subscription B will receive the message because this message is intended only for subscribers who receive it on Sunday night.

  • Scenario 3:

    The message attribute fields are as follows:

    [
        {
            "name": "week",
            "type": "STRING",
            "value": [
                "monday"
            ]
        },
        {
            "name": "time",
            "type": "STRING",
            "value": [
                "night"
            ]
        }
    ]

    Sending result: This message is only sent to subscription B because this message is intended for subscribers who receive it on Monday night.

  • Scenario 4

    The message attribute fields are as follows:

    [
        {
            "name": "week",
            "type": "STRING",
            "value": [
                "sunday"
            ]
        },
        {
            "name": "time",
            "type": "STRING",
            "value": [
                "morning"
            ]
        }
    ]

    Sending result: This message is only sent to subscription A because this message is intended for subscribers who receive it on Sunday morning.

  • Scenario 5

    The message attribute fields are as follows:

    [
        {
            "name": "week",
            "type": "STRING_ARRAY",
            "value": [
                "sunday",
                "monday"
            ]
        },
        {
            "name": "time",
            "type": "STRING_ARRAY",
            "value": [
                "morning",
                "night"
            ]
        }
    ]

    Sending result: Both subscription A and subscription B can receive this message because this message is intended for subscribers who receive it in the morning or night on Sunday or Monday.

  • Scenario 6

    No subscription filtering policy is configured.

    Sending result: Subscriptions without subscription filtering policies will not receive messages with any attributes.