tencent cloud

masukan

Cross-region replication

Terakhir diperbarui:2024-02-01 17:32:35

    Overview

    This document provides an overview of APIs and SDK code samples related to cross-region replication.
    API
    Operation
    Description
    Setting a cross-region replication rule
    Sets a cross-region replication rule for a bucket
    Querying a cross-region replication rule
    Queries the cross-region replication rule of a bucket
    Deleting a cross-region replication rule
    Deletes the cross-region replication rule from a bucket

    SDK API References

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

    Setting Cross-region Replication Rules

    Description

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

    Sample code

    // Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    String bucket = "examplebucket-1250000000";
    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;
    }
    
    // If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:
    // clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?
    @Override
    public void onFail(CosXmlRequest cosXmlRequest,
    @Nullable CosXmlClientException clientException,
    @Nullable CosXmlServiceException serviceException) {
    if (clientException != null) {
    clientException.printStackTrace();
    } else {
    serviceException.printStackTrace();
    }
    }
    });
    Note:
    For more samples, please visit GitHub.

    Querying Cross-region Replication Rules

    Description

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

    Sample code

    // Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    String bucket = "examplebucket-1250000000";
    GetBucketReplicationRequest getBucketReplicationRequest =
    new GetBucketReplicationRequest(bucket);
    
    cosXmlService.getBucketReplicationAsync(getBucketReplicationRequest,
    new CosXmlResultListener() {
    @Override
    public void onSuccess(CosXmlRequest request, CosXmlResult result) {
    GetBucketReplicationResult getBucketReplicationResult =
    (GetBucketReplicationResult) result;
    }
    
    // If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:
    // clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?
    @Override
    public void onFail(CosXmlRequest cosXmlRequest,
    @Nullable CosXmlClientException clientException,
    @Nullable CosXmlServiceException serviceException) {
    if (clientException != null) {
    clientException.printStackTrace();
    } else {
    serviceException.printStackTrace();
    }
    }
    });
    Note:
    For more samples, please visit GitHub.

    Deleting Cross-region Replication Rules

    Description

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

    Sample code

    // Bucket name in the format of BucketName-APPID (APPID is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
    String bucket = "examplebucket-1250000000";
    DeleteBucketReplicationRequest deleteBucketReplicationRequest =
    new DeleteBucketReplicationRequest(bucket);
    
    cosXmlService.deleteBucketReplicationAsync(deleteBucketReplicationRequest,
    new CosXmlResultListener() {
    @Override
    public void onSuccess(CosXmlRequest request, CosXmlResult result) {
    DeleteBucketReplicationResult deleteBucketReplicationResult =
    (DeleteBucketReplicationResult) result;
    }
    
    // If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:
    // clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?
    @Override
    public void onFail(CosXmlRequest cosXmlRequest,
    @Nullable CosXmlClientException clientException,
    @Nullable CosXmlServiceException serviceException) {
    if (clientException != null) {
    clientException.printStackTrace();
    } else {
    serviceException.printStackTrace();
    }
    }
    });
    Note:
    For more samples, please visit GitHub.
    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24