All Products
Search
Document Center

Object Storage Service:Use MNS to send notifications of OSS events

Last Updated:Jul 15, 2025

You can configure event notification rules in the Object Storage Service (OSS) console for objects that you want to monitor. If the events that are specified in the rules occur on these objects, a notification is sent.

Example scenario

You create a bucket named srcbucket in the China (Hangzhou) region for your company, and create two directories log/ and destdir/ in srcbucket. The log/ directory is used to store log objects whose names contain the log/ prefix. The destdir/ directory is used to store images whose names contain the destdir/ prefix.

srcbucket
    └── log/
       ├── date1.txt
       ├── date2.txt
       ├── date3.txt
       ├── .......
    └── destdir/       
       ├── photo1.jpg
       ├── photo2.jpg
       ├── ...... 

The company needs to synchronize logs and customer case images in srcbucket and all changes to these objects (such as addition, deletion, and modification of objects) to a bucket named destbucket in the UK (London) region. In addition, the company wants all its employees to be notified of changes to objects in the log/ and destdir/ directories in srcbucket and destbucket.

In this case, you can configure a cross-region replication (CRR) rule for srcbucket and event notification rules for srcbucket and destbucket.

Step 1: Create SMQ queues

  1. Log on to the SMQ console.

  2. In the left-side navigation pane, choose Queue Model > Queues.

  3. In the top navigation bar, select the China (Hangzhou) region.

  4. On the Queues page, click Create Queue. Set the queue name to myqueue1 and retain the default settings for other parameters.

  5. Click OK.

  6. Switch to the UK (London) region in the top navigation bar and repeat the preceding steps to create a queue named myqueue2 for receiving notifications of events on destbucket.

Step 2: Configure a CRR rule for srcbucket

  1. Log on to the OSS console.

  2. In the left-side navigation pane, click Buckets. On the page that appears, click srcbucket.

  3. In the left-side navigation tree, choose Data Management > CRR.

  4. On the CRR tab, click CRR.

  5. In the CRR panel, configure the following parameters then click OK.

    Parameter

    Description

    Destination Bucket

    Select UK (London) and then select destbucket.

    Objects to Replicate

    Select Objects with Specified Prefix, and specify prefixes destdir/ and log/.

    Replication Policy

    Select Add/Delete/Change.

    Replicate Historical Data

    Select Yes.

    RAM Role Name

    Select a role for CRR.

Step 3: Configure event notification rules for srcbucket and destbucket

Important

The CRR rule configured in Step 2 specifies that historical data is replicated to destbucket. If a large amount of historical data is available, lots of notifications are triggered when the replication happens. If you do not want to be notified during the replication, we recommend that you configure event notification rules for srcbucket and destbucket after all historical data is synchronized.

  1. Log on to the OSS console.

  2. In the left-side navigation pane, click Buckets. On the page that appears, select srcbucket and destbucket respectively, and configure event notification ruless for each according to the steps below.

    1. In the left-side navigation tree, choose Data Processing > Event Notification.

    2. On the Event Notification page, click Create Rule.

    3. In the Create Rule panel, configure the parameters according to the following table and click OK.

      Parameter

      srcbucket

      destbucket

      Rule Name

      Set the rule name to notification1.

      Set the rule name to notification2.

      Event Type

      Select PutObject, CopyObject, DeleteObject, and DeleteObjects.

      Select ObjectReplication:ObjectCreated, ObjectReplication:ObjectRemoved and ObjectReplication:ObjectModified.

      Resource Description

      Select Prefix and Suffix, and then add prefixes log/ and destdir/.

      Select Prefix and Suffix, and then add prefixes log/ and destdir/.

      Endpoint

      Select Queue, then enter myqueue1 created in Step 1.

      Select Queue, then enter myqueue2 created in Step 1.

It takes about 10 minutes for new event notification rules to take effect.

Step 4: Configure subscriptions to receive notifications

When an event matching rule is triggered, SMQ automatically creates a topic. The topic name is in the mns-en-topics-[Product]-[RuleName]-[Timestamp] format, such as, mns-en-topics-oss-notification1-1700098799. To receive notifications, you must subscribe to the topic and specify an endpoint in the subscription rule.

  1. Log on and navigate to the Subscriptions page.

    1. Log on to the SMQ(formerly MNS) console.

    2. In the left-side navigation pane, click Topics.

    3. In the top navigation bar, select the China (Hangzhou) region.

    4. Locate the automatically created topic and click View Subscriptions in the Actions column.

  2. Create subscriptions.

    1. In the panel that appears, click Subscriptions. On the page that appears, click Create Subscription.

    2. In the Create Subscription panel, configure parameters to create a subscription to the topic that is created by SMQ for srcbucket. Enter mysubscription1 for Name, select Queue for Push Type, and then enter myqueue1 for Receiver Endpoint. Retain the default settings for other parameters.

    3. Click OK.

  3. Switch to the UK (London) region and repeat the preceding steps to create the mysubscription2 subscription to the topic that is created by MNS for destbucket. Select Queue for the push type and enter myqueue2 for the receiver endpoint. Retain the default settings for other parameters.

  4. Configure settings to receive notifications.

    1. In the left-side navigation pane, click Queues.

    2. Locate myqueue1 and choose More > Send Messages in the Actions column.

    3. In the Receive Message section of the displayed page, click Receive Message.

      The system notifies you when objects in the log/ and destdir/ directories of srcbucket are created, modified, or deleted.

    4. Repeat the preceding steps to receive notifications from myqueue2 that is created for destbucket. After the configuration is complete, you will receive event notifications about object creation, overwriting, or deletion in destbucket based on the CRR rule.

    If you no longer need such notifications, delete the event notification rule. Deleting an event notification rule does not delete the automatically created topic. Therefore, to prevent unnecessary charges, delete unwanted topics at the earliest opportunity.