Managing Topics and Subscriptions

This section describes how to manage topics  and their subscriptions .

Caution

Avoid entering confidential information when assigning descriptions, tags, or friendly names to your cloud resources through the Oracle Cloud Infrastructure Console, API, or CLI.

A topic is a communication channel for sending messages  to its subscriptions. A topic can have zero, one, or multiple subscriptions that are notified whenever a message is published to a topic.

Prerequisites

IAM policies: To use Notifications, you must be given the required type of access in a policy  written by an administrator, whether you're using the Console or the REST API with an SDK, CLI, or other tool. For Functions, you must have FN_INVOKE permission against the function to be able to add the function as a subscription to a topic. To authorize your function for access to other Oracle Cloud Infrastructure resources, such as Compute instances, include the function in a dynamic group  and create a policy to grant the dynamic group access to those resources. For more information, see Accessing Other Oracle Cloud Infrastructure Resources from Running Functions.

If you get a response that you don’t have permission or are unauthorized, check with your administrator. You may not have the required type of access in the current compartment . For more information on user authorizations, see Notifications Overview.

Creating Automation with Functions and Events

You can create automation by publishing messages to function subscriptions. For an example of a function subscription, see Scenario A: Automatically Resize VMs.

You can create also automation based on state changes of your topics and subscriptions (Notifications resources) by using event types, rules, and actions. For more information, see Overview of Events.

Using the Console

To create a topic
  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. Click Create Topic at the top of the topic list.
  3. In the Create Topic dialog box, configure your topic.

    • Name: Required. Specify a friendly name for the topic. It must be unique across the tenancy; validation is case-sensitive. Avoid entering confidential information.
    • Description: Optional. Enter a description for the topic. Avoid entering confidential information.
  4. Click Create.
To delete a topic
  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. For the topic you want to delete, click the Actions icon (three dots), and then click Delete.
  3. Confirm when prompted.
To update the description for a topic
  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. Click the name of the topic you want to update.
  3. On the topic detail page, next to Description, click the edit icon.
  4. Edit the description.
  5. Click the save icon.
To move a topic to a different compartment

Associated subscriptions remain in their current compartments. For more information, see Moving Topics and Subscriptions to a Different Compartment.

Note

To move resources between compartments, resource users must have sufficient access permissions on the compartment that the resource is being moved to, as well as the current compartment. For more information about permissions for Notifications resources, see Details for the Notifications Service.
  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. In the Scope section, select a compartment.
  3. Find the topic in the list, click the Actions icon (three dots), and then click Move Resource.
  4. Choose the destination compartment from the list.
  5. Click Move Resource.
To create a subscription
Note

While new subscriptions must be created in the same compartment as the topic, you can move them to different compartments after creating them.
  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. Click the name of the topic that you want to add the subscription to.
  3. On the topic detail page, click Create Subscription.
  4. In the Create Subscription dialog box, configure your subscription for the protocol you want: 

    Email subscription

    Sends an email message when you publish a message  to the subscription's parent topic .

    • Protocol: Select Email.
    • Email: Type an email address.
    Function subscription

    Runs the specified function when you publish a message  to the subscription's parent topic . For example, runs a function to resize VMs when an associated alarm is triggered.

    Note

    You must have FN_INVOCATION permission against the function to be able to add the function as a subscription to a topic.

    The Notifications service has no information about a function after it's invoked. For more details, see the troubleshooting information at Function not invoked or run.

    Confirmation is not required for function subscriptions.

    • Subscription Protocol: Select Function.
    • Function Compartment: Select the compartment containing your function.
    • Function Application: Select the application containing your function.
    • Function: Select your function.
    HTTPS (Custom URL) subscription

    Sends specified information when you publish a message  to the subscription's parent topic .

    Endpoint format (URL using HTTPS protocol): 

    https://<anyvalidURL>
    Basic access authentication is supported, allowing you to specify a username and password in the URL, as in https://user:password@domain.com or https://user@domain.com. The username and password are encrypted over the SSL connection established when using HTTPS. For more information about Basic Access Authentication, see RFC-2617.
    Query parameters are not allowed in URLs.
    • Protocol: Select HTTPS (Custom URL).
    • URL: Type (or copy and paste) the URL you want to use as the endpoint.
    PagerDuty subscription

    Creates a PagerDuty incident by default when you publish a message  to the subscription's parent topic .

    Endpoint format (URL): 

    https://events.pagerduty.com/integration/<integrationkey>/enqueue
    Query parameters are not allowed in URLs.

    To create an endpoint for a PagerDuty subscription (set up and retrieve an integration key), see the PagerDuty documentation.

    • Protocol: Select PagerDuty.
    • URL: Type (or copy and paste) the integration key portion of the URL for your PagerDuty subscription. (The other portions of the URL are hard-coded.)
    Slack subscription

    Sends a message to the specified Slack channel by default when you publish a message  to the subscription's parent topic .

    Endpoint format (URL): 

    https://hooks.slack.com/services/<webhook-token>

    The <webhook-token> portion of the URL contains two slashes (/).

    Query parameters are not allowed in URLs.

    To create an endpoint for a Slack subscription (using a webhook for your Slack channel), see the Slack documentation.

    • Protocol: Select Slack.
    • URL: Type (or copy and paste) the Slack endpoint, including your webhook token.
  5. Click Create.

    The subscription has been created.

    Subscriptions using protocols that require confirmation, such as Email, remain in "Pending" status until confirmation is received. For these subscriptions, a subscription confirmation URL is sent. For detailed steps, see To confirm a subscription.

To confirm a subscription

Confirmation is not required for function subscriptions.

Navigate to the confirmation URL that is sent to the subscription's endpoint.

Some protocols provide confirmation URLs in unique ways: 

  • HTTPS (Custom URL): You can find the confirmation URL in the request header or body of the subscription confirmation message (request of content-type: "application/json") that is sent to the endpoint. 
    • In the request header, see the value of the X-OCI-NS-ConfirmationURL field.

      Example request header: 
      "X-OCI-NS-SignatureVersion":"1.0"
                                          "X-OCI-NS-Signature":"<example-signature>"
                                          "X-OCI-NS-SigningCertURL":"<example-url>"
                                          "X-OCI-NS-TopicOcid":"ocid.compartment.oc1..<unique_ID>"
                                          "X-OCI-NS-Timestamp":"2019-04-19T21:26:00.310+0000"
                                          "X-OCI-NS-MessageId":"<unique_ID>"
                                          "X-OCI-NS-TopicName":"mytopic"
                                          "X-OCI-NS-MessageType":"SubscriptionConfirmation"
                                          "X-OCI-NS-ConfirmationURL":"<exampleConfirmationURL>"
                                          "X-OCI-NS-SubscriptionId":"ocid1.onssubscription.oc1.phx.<unique_ID>"
                                          "X-OCI-NS-State":"Pending"
    • In the request body, see the value of the ConfirmationURL key.

      Example ConfirmationURL key and value (request body): 

      "ConfirmationURL":"<exampleConfirmationURL>"
      
  • PagerDuty: Incident titled "Oracle Notification Service Subscription Confirmation". For more information, see the PagerDuty documentation for Oracle Cloud Infrastructure.
  • Slack: Message sent to Slack channel containing the text "To confirm the subscription".
To resend a subscription confirmation

The ability to resend subscription confirmations is only applicable for pending subscriptions.

  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. For the subscription you want to resend the confirmation for, click the Actions icon (three dots), and then click Resend Confirmation.
To update the retry duration for a subscription

The retry duration is part of the delivery policy for the subscription. By default, Notifications retries delivery of a message for up to two hours.

  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. For the subscription you want to update, click the Actions icon (three dots), and then click Update Delivery Policy.

  3. In the Update Delivery Policy dialog box, click the edit icon for Max Retry Duration in Minutes, type the new value, and then click the save icon.
To move a subscription to a different compartment

The associated topic remains in its current compartment. For more information, see Moving Topics and Subscriptions to a Different Compartment.

Note

To move resources between compartments, resource users must have sufficient access permissions on the compartment that the resource is being moved to, as well as the current compartment. For more information about permissions for Notifications resources, see Details for the Notifications Service.
  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. In the Scope section, select a compartment.
  3. Find the subscription in the list, click the Actions icon (three dots), and then click Move Resource.
  4. Choose the destination compartment from the list.
  5. Click Move Resource.
To delete a subscription (unsubscribe)
Note

Every message sent out as email contains a link to unsubscribe from the related topic.
  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. For the subscription you want to delete, click the Actions icon (three dots), and then click Delete.
  3. Confirm when prompted.

Managing Tags for a Topic or Subscription

You can apply tags to your resources, such as topics and subscriptions, to help you organize them according to your business needs. You can apply tags at the time you create a topic or subscription, or you can update the topic or subscription later with the tags you want. For general information about applying tags, see Resource Tags.

To manage tags for a topic
  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. Choose the Compartment that contains the topic you want to tag, and then click the topic's name.
  3. Click the Tags tab to view or edit existing tags, or click Add Tags to add new ones.

For more information, see Resource Tags.

To manage tags for a subscription
  1. Open the navigation menu. Under Solutions and Platform, go to Application Integration and click Notifications.
  2. Choose the Compartment that contains the subscription you want to tag, and then click the name of the topic that has the subscription.
  3. For the subscription you want to tag, click the Actions icon (three dots), and then click Add Tags.

    To view or edit existing tags, click the Actions icon (three dots), and then click View Tags.

For more information, see Resource Tags.

Using the API