Topics
To send a notification to multiple endpoints at once, use topics. Topics also allow you to group messages by category, e.g., security alerts, promotional messages, etc. To group messages, create a separate topic for each category.
Topics enable you to target messages to all endpoints or phone numbers subscribed to the relevant topic. Each topic has an ARN, its unique identifier.
To add endpoints to a topic, you can use a subscription. A subscription associates a topic with a single endpoint added to a notification channel. You do not need to pre-add phone numbers to a notification channel. To send messages to different endpoints, subscribe all these endpoints to the relevant topic.
This is how you set up topics:
-
Use CNS to create notification channels. You do not need to create channels to send notifications to Yandex Message Queue queues.
-
Add endpoints to the notification channels. For SMS, adding an endpoint is optional.
-
Create a topic and enable logging to keep track of sent notifications.
-
Add a subscription to the topic and specify the following in it:
- ID (ARN) of the previously created endpoint: for mobile push notifications and browser notifications.
- Phone number: for SMS.
- Queue URL: for Message Queue.
This is how you send notifications:
-
You can send a notification to the topic's ARN via the SDK or API using the
Publishmethod.You can also use the management console
.Notification format in JSON:
{ "default": "<Default_text>", "sms": "<Notification_text_for_sms>", "sqs": "<Notification_text_for_message_queue>", "WEB": "<Notification_text_for_bowser>", "APNS": { "aps": { "alert": { "title": "Notification_title", "body": "Notification_text" } } }, "GCM": { "notification": { "title": "Notification_title", "body": "Notification_text" } }, "HMS": { "notification": { "title": "Notification_title", "body": "<Notification_text>" } }, "RUSTORE": { "notification": { "title": "Notification_title", "body": "<Notification_text>" } } }You can use the same text for all channel types or add different texts for each channel. If you provide no notification message for a particular channel, the default text will be used.
-
CNS validates the request.
-
If the request is valid, authenticated and authorized, the system sends the notification to all topics’ subscribers.
-
If there is an error, e.g., the limits are exceeded, it will be logged in Cloud Logging. Logging is enabled when you create a topic.