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 specify in the rules.

Scenario

You create a bucket named srcbucket in the China (Hangzhou) region for your company, and then 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 your 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. Click Create Queue. In the Create Queue panel, set Name to myqueue1 and keep the default settings 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 pane, choose Redundancy for Fault Tolerance > Cross-Region Replication.
  4. In the Cross-Region Replication section, click Configure.
  5. Click Cross-Region Replication. In the Cross-Region Replication panel, configure the parameters described in the following table.
    Parameter Description
    Destination Region Select UK (London).
    Destination Bucket Select destbucket.
    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 this feature. For information about the billing methods, see Transfer acceleration fees.
    Applied To Select Files with Specified Prefix, and then specify the following two prefixes: destdir/ and log/.
    Operations Select Add/Delete/Change.
    Replicate Historical Data Select Yes.
  6. Click OK.

Step 3: Configure event notification rules for srcbucket and destbucket

Notice 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 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 pane, choose Basic Settings > Event Notification.
    4. In the Event Notification section, click Configure. On the page that appears, click Create Rule.
    5. In the Create Rule panel, configure the parameters described in the following table. Then, click OK.
      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 is 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 Create Rule panel, configure the parameters described in the following table. Then, click OK.
      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 is created in Step 1.

After you configure the event notification rules, the rules take effect in about 10 minutes.

Step 4: Receive notifications

When the event notification rule that you configure 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 that corresponds to the topic that is automatically created by MNS.
    5. In the View Subscriptions to Topic panel, click Subscriptions. On the page that appears, click Create Subscription.
    6. In the Create Subscription panel, configure 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. Keep the default settings 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.
  2. Receive notifications.
    1. In the left-side navigation pane, click Queues.
    2. Choose More > Send Messages in the Actions column that corresponds to myqueue1.
    3. In the Receive Message section of the Quick Experience page, click Receive Message in the upper-right corner.
      This 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. This 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 avoid unnecessary charges, delete topics that you no longer use.