Setting Event Notifications (SDK for C)
You can call set_notification_configuration to set event notifications for a bucket.
Method
void set_notification_configuration(const obs_options *options,
obs_smn_notification_configuration* notification_conf, obs_response_handler *handler,
void *callback_data); Parameter Description
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| options | The context of the bucket request. For details, see Configuring option (SDK for C). | Mandatory | Bucket parameter |
| notification_conf | obs_smn_notification_configuration* | Mandatory | Indicates the container for configuring the event notification. |
| handler | obs_response_handler * | Mandatory | Callback function |
| callback_data | void * | Optional | Callback data |
The following table describes the parameter obs_smn_notification_configuration.
| Parameter | Type | Mandatory (Yes/No) Description |
|---|---|---|
| topic_conf | obs_smn_topic_configuration* | Container for configuring the event notification topic |
| topic_conf_num | unsigned int | Number of topic_conf |
The following table describes the parameter obs_smn_topic_configuration.
| Parameter | Type | Mandatory (Yes/No) Description |
|---|---|---|
| topic | char * | URN of the event notification topic. After detecting a specific event in the bucket, OBS sends a message to the topic. |
| id | char * | Unique ID of each event notification. If no ID is specified, the system automatically assigns one. |
| filter_rule | obs_smn_filter_rule * | Container that defines key-value pairs of filter rules |
| filter_rule_num | unsigned int | Number of filter_rule |
| event | obs_smn_event_enum* | Type of events that need to be notified |
| event_num | unsigned int | Number of event types |
Code Examples
static void test_set_notification_configuration()
{
obs_options option;
obs_status ret_status = OBS_STATUS_BUTT;
obs_smn_notification_configuration notification_conf;
obs_smn_topic_configuration topic_conf;
obs_smn_event_enum topic1_event[2];
obs_smn_filter_rule filter_rule;
// Set option.
init_obs_options(&option);
option->bucket_options.hostName = "<your-endpoint>";
option->bucket_options.bucketName = "<Your bucketname>";
// Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY.
// Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
option.bucket_options.access_key = getenv("ACCESS_KEY_ID");
option.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY");
// Set callback function.
obs_response_handler response_handler =
{
NULL, &response_complete_callback
};
// Set the unique ID of the notification configuration.
topic_conf.id = "Id001";
// Set the URN of the event notification topic.
topic_conf.topic = "urn:smn:southchina:ea79855fbe0642718cb4df1551c3cb4e:test_cwx298983";
// Set the event types for notification.
topic_conf.event = topic1_event;
topic_conf.event[0] = SMN_EVENT_OBJECT_CREATED_ALL;
topic_conf.event[1] = SMN_EVENT_OBJECT_CREATED_POST;
topic_conf.event_num = 2;
// Set filtering rules for notification objects.
filter_rule.name = OBS_SMN_FILTER_PREFIX;
filter_rule.value = "aaa";
topic_conf.filter_rule = &filter_rule;
topic_conf.filter_rule_num = 1;
memset(¬ification_conf, 0, sizeof(obs_smn_notification_configuration));
notification_conf.topic_conf = &topic_conf;
notification_conf.topic_conf_num = 1;
set_notification_configuration(&option, ¬ification_conf, &response_handler, &ret_status);
if (OBS_STATUS_OK == ret_status) {
printf("set_notification_configuration success.\n");
}
else {
printf("set_notification_configuration failed(%s).\n",
obs_get_status_name(ret_status));
}
} Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot