Cross-Region Replication

Last updated: 2020-08-11 10:07:50

    Overview

    This document provides an overview of APIs and SDK code samples related to cross-region replication.

    API Operation Description
    PUT Bucket replication Setting cross-region replication Sets cross-region replication rules for a bucket
    GET Bucket replication Querying cross-region replication Queries the cross-region replication rules of a bucket
    DELETE Bucket replication Deleting cross-region replication Deletes the cross-region replication rules of a bucket

    SDK API References

    For the parameters and method descriptions of all the APIs in the SDK, see SDK API References.

    Setting Cross-Region Replication

    API description

    This API is used to set cross-region replication rules for a bucket.

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    PutBucketReplicationRequest putBucketReplicationRequest =
            new PutBucketReplicationRequest(bucket);
    
    string ownerUin = "100000000001"; //Replication initiator identifier: OwnerUin
    string subUin = "100000000001"; //Replication initiator identifier: SubUin
    putBucketReplicationRequest.setReplicationConfigurationWithRole(ownerUin,
            subUin);
    
    PutBucketReplicationRequest.RuleStruct ruleStruct =
            new PutBucketReplicationRequest.RuleStruct();
    // Identify the name of a specific rule
    ruleStruct.id = "replication_01";
    //Identify whether to enable the rule. true: enabled; false: disabled
    ruleStruct.isEnable = true;
    // Destination bucket region
    ruleStruct.region = "ap-beijing";
    // Destination bucket
    ruleStruct.bucket = "destinationbucket-1250000000";
    // Prefix matching policy
    ruleStruct.prefix = "dir/";
    putBucketReplicationRequest.setReplicationConfigurationWithRule(ruleStruct);
    
    cosXmlService.putBucketReplicationAsync(putBucketReplicationRequest,
            new CosXmlResultListener() {
        @Override
        public void onSuccess(CosXmlRequest request, CosXmlResult result) {
            PutBucketReplicationResult putBucketReplicationResult =
                    (PutBucketReplicationResult) result;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           CosXmlServiceException serviceException) {
            if (clientException != null) {
                clientException.printStackTrace();
            } else {
                serviceException.printStackTrace();
            }
        }
    });

    Note:

    For more samples, go to GitHub.

    Querying Cross-Region Replication

    API description

    This API is used to query the cross-region replication rules of a specified bucket.

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    GetBucketReplicationRequest getBucketReplicationRequest =
            new GetBucketReplicationRequest(bucket);
    
    cosXmlService.getBucketReplicationAsync(getBucketReplicationRequest,
            new CosXmlResultListener() {
        @Override
        public void onSuccess(CosXmlRequest request, CosXmlResult result) {
            GetBucketReplicationResult getBucketReplicationResult =
                    (GetBucketReplicationResult) result;
        }
    
        @Override
        public void onFail(CosXmlRequest cosXmlRequest,
                           CosXmlClientException clientException,
                           CosXmlServiceException serviceException) {
            if (clientException != null) {
                clientException.printStackTrace();
            } else {
                serviceException.printStackTrace();
            }
        }
    });

    Note:

    For more samples, go to GitHub.

    Deleting Cross-Region Replication

    API description

    This API is used to delete the cross-region replication rules from a bucket.

    Sample code

    String bucket = "examplebucket-1250000000"; // Format: BucketName-APPID
    DeleteBucketReplicationRequest deleteBucketReplicationRequest =
            new DeleteBucketReplicationRequest(bucket);
    
    cosXmlService.deleteBucketReplicationAsync(deleteBucketReplicationRequest,
            new CosXmlResultListener() {
                @Override
                public void onSuccess(CosXmlRequest request, CosXmlResult result) {
                    DeleteBucketReplicationResult deleteBucketReplicationResult =
                            (DeleteBucketReplicationResult) result;
                }
    
                @Override
                public void onFail(CosXmlRequest cosXmlRequest,
                                   CosXmlClientException clientException,
                                   CosXmlServiceException serviceException) {
                    if (clientException != null) {
                        clientException.printStackTrace();
                    } else {
                        serviceException.printStackTrace();
                    }
                }
            });

    Note:

    For more samples, go to GitHub.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help