文档首页 > > SDK参考> .NET> 事件通知> 设置事件通知

设置事件通知

分享
更新时间: 2019/04/22 GMT+08:00

您可以通过ObsClient.SetBucketNotification设置桶的事件通知。以下代码展示了如何设置桶的事件通知:

// 创建ObsClient实例
ObsClient client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", "https://your-endpoint");
// 设置事件通知
try
{
    FilterRule filterRule1 = new FilterRule();
    filterRule1.Name = FilterNameEnum.Prefix;
    filterRule1.Value = "smn";
    TopicConfiguration topicConfiguration1 = new TopicConfiguration();
    topicConfiguration1.Id = "Id001";
    topicConfiguration1.Topic = "your topic1 URN";
    topicConfiguration1.Events.Add(EventTypeEnum.ObjectCreatedAll);
    topicConfiguration1.FilterRules.Add(filterRule1);
    FilterRule filterRule2 = new FilterRule();
    filterRule2.Name = FilterNameEnum.Suffix;
    filterRule2.Value = ".jpg";
    TopicConfiguration topicConfiguration2 = new TopicConfiguration();
    topicConfiguration2.Id = "Id002";
    topicConfiguration2.Topic = "your topic2 URN";
    topicConfiguration2.Events.Add(EventTypeEnum.ObjectCreatedAll);
    topicConfiguration2.FilterRules.Add(filterRule2);
    NotificationConfiguration notificationConfiguration = new NotificationConfiguration();
    notificationConfiguration.TopicConfigurations.Add(topicConfiguration1);
    notificationConfiguration.TopicConfigurations.Add(topicConfiguration2);

    FilterRule filterRule3 = new FilterRule();
    filterRule3.Name = FilterNameEnum.Prefix;
    filterRule3.Value = "xxx";
    FunctionGraphConfiguration functionGraphConfiguration = new FunctionGraphConfiguration();
    functionGraphConfiguration.Id = "Id001";
    functionGraphConfiguration.Topic = "your function graph URN";
    functionGraphConfiguration.Events.Add(EventTypeEnum.ObjectCreatedAll);
    functionGraphConfiguration.FilterRules.Add(filterRule3);
    notificationConfiguration.FunctionGraphConfigurations.Add(functionGraphConfiguration);
    SetBucketNotificationRequest request = new SetBucketNotificationRequest
    {
        BucketName = "bucketname",
        Configuration = notificationConfiguration,
    };
    SetBucketNotificationResponse response = client.SetBucketNotification(request);
    Console.WriteLine("Set bucket notification response: {0}", response.StatusCode);
}

catch (ObsException ex)
{
    Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
    Console.WriteLine("ErrorMessage: {0}", ex.ErrorMessage);
}
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

跳转到云社区