You can configure event notification rules in the Object Storage Service (OSS) console for objects that you want to monitor. If the events that you specified in the rules occur on these objects, you can immediately receive a notification from the HTTP servers or Message Service (MNS) queues that you specified in the rules.

Scenario

You create a bucket named srcbucket in the China (Hangzhou) region for your company, and create two directories named log/ and destdir/ in srcbucket. The log/ directory is used to store log objects that are continuously generated. The names of the log objects contain the log/ prefix and indicate the date when the objects are generated. Examples: log/date1.txt, log/date2.txt, and log/date3.txt. The destdir/ directory is used to store image objects of user cases, which are collected on a weekly basis. The names of the image objects contain the destdir/ prefix. Examples: destdir/photo1.jpg and destdir/photo2.jpg. The following structure shows the directories and objects in srcbucket:

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

A bucket that belongs to the parent company named destbucket is located in the UK (London) region. You want to synchronize the log and image objects and the operations performed on these objects, such as creation, modification, and deletion, from srcbucket to destbucket in real time. In addition, you want the employees of your company and parent company to be notified of any changes to objects in the log/ and destdir/ directories of 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 MNS queues

  1. Log on to the MNS console.
  2. In the left-side navigation pane, click Queues.
  3. In the top navigation bar, select the China (Hangzhou) region.
  4. On the Queues page, click Create Queue.
  5. On the Overview page, click Create Queue. In the Create Queue panel, set Name to myqueue1. Retain the default configurations of other parameters.
  6. Click OK.
  7. Repeat the preceding steps to create a queue named myqueue2 in the UK (London) region to receive notifications sent for the destination bucket 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 Buckets page, click srcbucket.
  3. In the left-side navigation tree, choose Data Management > Cross-Region Replication.
  4. On the Cross-Region Replication tab, click Cross-Region Replication.
  5. In the Cross-Region Replication panel, configure the parameters. The following table describes the parameters.
    Parameter Description
    Destination Bucket Select destbucket, and Select UK (London).
    Acceleration Type To accelerate data transmission between srcbucket in the China (Hangzhou) region and destbucket in the UK (London) region during CRR, we recommend that you select Transfer Acceleration. If you enable transfer acceleration, you are charged for the use of this feature. For more information, see Transfer acceleration fees.
    Objects to Replicate Select Files with Specified Prefix, and specify the following prefixes: destdir/ and log/.
    Replication Policy Select Add/Delete/Change.
    Replicate Historical Data Select Yes.
  6. Click OK.

Step 3: Configure event notification rules for srcbucket and destbucket

Important The CRR rule configured in Step 2 specifies that historical data in srcbucket is synchronized to destbucket. If the amount of the historical data is large, a large number of notifications are sent after you configure event notification rules for srcbucket and destbucket. If you do not want event notification rules to be triggered when the historical data is synchronized, we recommend that you configure event notification rules for srcbucket and destbucket after all historical data is synchronized.
  1. Configure an event notification rule for srcbucket.
    1. Log on to the OSS console.
    2. In the left-side navigation pane, click Buckets. On the Buckets page, click srcbucket.
    3. In the left-side navigation tree, choose Data Processing > Event Notification.
    4. On the Event Notification page, click Create Rule.
    5. In the Create Rule panel, configure the parameters. Then, click OK. The following table describes the parameters.
      Parameter Description
      Rule name Set the rule name to notification1.
      Events Select PutObject, CopyObject, DeleteObject, and DeleteObjects.
      Resource Description Select Prefix and Suffix. Then, specify the following prefixes: log/ and destdir/.
      Endpoint Select Queue. Then, enter myqueue1 that you created in Step 1.
  2. Configure an event notification rule for destbucket.
    1. In the left-side navigation pane, click Buckets. On the Buckets page, click destbucket.
    2. In the left-side navigation tree, choose Data Processing > Event Notification.
    3. On the Event Notification page, click Create Rule.
    4. In the Create Rule panel, configure the parameters. Then, click OK. The following table describes the parameters.
      Parameter Description
      Rule name Set the rule name to notification2.
      Events Select ObjectReplication:ObjectCreated, ObjectReplication:ObjectRemoved, and ObjectReplication:ObjectModified.
      Resource Description Select Prefix and Suffix. Then, specify the following prefixes: log/ and destdir/.
      Endpoint Select Queue. Then, enter myqueue2 that you created in Step 1.

After you configure the event notification rule, the rule takes effect after approximately 10 minutes.

Step 5: Receive notifications

When the event notification rule that you configured for srcbucket or destbucket is triggered, MNS automatically creates a topic whose name is in the following format: mns-en-topics-[Product]-[RuleName]-[Timestamp]. Example: mns-en-topics-oss-notification1-96828124450125. To receive notifications, you must create a subscription to the topic and specify an endpoint in the subscription rule.

  1. Create subscriptions to the topics.
    1. Log on to the MNS console.
    2. In the left-side navigation pane, click Topics.
    3. In the top navigation bar, select the China (Hangzhou) region.
    4. Click View Subscriptions in the Actions column of the topic that is automatically created by MNS.
    5. In the View Subscriptions to Translation01 Topic panel, click Subscriptions. On the page that appears, click Create Subscription.
    6. In the Create Subscription panel, configure the parameters to create a subscription to the topic that is created by MNS for srcbucket. Set Name to mysubscription1, select Queue for Push Type, and set Receiver Endpoint to myqueue1. Retain the default configurations of other parameters.
    7. Click OK.
    8. In the UK (London) region, repeat the preceding steps to create a subscription named mysubscription2 to the topic that is created by MNS for destbucket. Select Queue for Push Type, and set Receiver Endpoint to myqueue2. Retain the default configurations of other parameters.
  2. Receive notifications.
    1. In the left-side navigation pane, click Queues.
    2. On the Queues page, choose More > Send Messages in the Actions column of myqueue1.
    3. In the Receive Message section of the Send Messages 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. The system notifies you when objects in destbucket are created, modified, or deleted based on the CRR rule.
    If you no longer need to receive notifications sent based on an event notification rule, delete the event notification rule. However, the topic that was automatically created by MNS based on the deleted event notification rule is not deleted. To prevent unnecessary charges, delete the topics that you no longer use.