Updated on 2026-08-14 GMT+08:00

Configuring Event Notifications (SDK for Java)

Function

You can configure notifications for certain types of events. When such events happen in your bucket, you will be notified of the operations in a timely manner.

This API is used to configure event notifications for a bucket.

Restrictions

Method

ObsClient.setBucketNotification(final SetBucketNotificationRequest request)

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

request

Table 2

Yes

Explanation:

Request parameters. For details, see Table 2.

Table 2 SetBucketNotificationRequest

Parameter

Type

Mandatory (Yes/No)

Description

bucketName

String

Yes

Explanation:

Bucket name.

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain a period (.) and a hyphen (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets with the same name in the same region, no error will be reported and the bucket properties comply with those set in the first creation request.

Default value:

None

bucketNotificationConfiguration

Table 3

Yes

Explanation:

Array of rules. For details, see Table 3.

Table 3 BucketNotificationConfiguration

Parameter

Type

Mandatory (Yes/No)

Description

topicConfigurations

List<Table 4>

No

Explanation:

List of event notification topic configurations.

Value range:

For details, see Table 4.

Default value:

None

functionGraphConfigurations

List<Table 5>

No

Explanation:

List of FunctionGraph configurations.

Value range:

For details, see Table 5.

Default value:

None

Table 4 TopicConfiguration

Parameter

Type

Mandatory (Yes/No)

Description

id

String

No

Explanation:

Unique ID of each event notification configuration. If the ID is not specified, OBS automatically assigns an ID.

Restrictions:

None

Default value:

None

filter

Table 6

Yes

Explanation:

It stores rules for filtering object names.

Value range:

For details, see Table 6.

Default value:

None

topic

String

Yes

Explanation:

URN of the event notification topic. When OBS detects a specific event in the bucket, it publishes a notification message to the topic. You can find the topic's URN on the Topics page of the SMN console.

Restrictions:

None

Default value:

None

events

List<Table 7>

No

Explanation:

List of event types for which notifications will be sent.

Value range:

For details, see Table 7.

Default value:

None

Table 5 FunctionGraphConfiguration

Parameter

Type

Mandatory (Yes/No)

Description

id

String

No

Explanation:

Unique ID of each event notification configuration. If the ID is not specified, OBS automatically assigns an ID.

Restrictions:

None

Default value:

None

filter

Table 6

Yes

Explanation:

It stores rules for filtering object names.

Value range:

For details, see Table 6.

Default value:

None

functionGraph

String

Yes

Explanation:

URN of FunctionGraph. When OBS detects a specific event in the bucket, it sends a message to FunctionGraph and calls FunctionGraph.

Restrictions:

None

Default value:

None

events

List<Table 7>

No

Explanation:

List of event types for which notifications will be sent.

Value range:

For details, see Table 7.

Default value:

None

Table 6 Filter

Parameter

Type

Mandatory (Yes/No)

Description

filterRules

List<Table 8>

Yes

Explanation:

It stores rules for filtering object names.

Value range:

For details, see Table 8.

Default value:

None

Table 7 EventTypeEnum

Constant

Description

OBJECT_CREATED_ALL

All events for creating objects, including uploading objects using PUT and POST, copying objects, and completing multipart uploads.

OBJECT_CREATED_PUT

All events for uploading objects using PUT.

OBJECT_CREATED_POST

All events for uploading objects using POST.

OBJECT_CREATED_COPY

All events for copying objects.

OBJECT_CREATED_COMPLETE_MULTIPART_UPLOAD

All events for completing multipart uploads.

OBJECT_REMOVED_ALL

Events of calling the APIs for deleting objects or aborting multipart uploads.

These events include deleting objects by specifying object version IDs, and deleting objects without specifying object version IDs after versioning is enabled.

OBJECT_REMOVED_DELETE

Events for deleting objects by specifying object version IDs.

OBJECT_REMOVED_DELETE_MARKER_CREATED

Events for deleting objects without specifying object version IDs after versioning is enabled.

Table 8 FilterRule

Parameter

Type

Mandatory (Yes/No)

Description

name

String

No

Whether to filter objects by object name prefix or suffix. Possible values are:

  • prefix
  • suffix

value

String

No

Keyword used to filter objects based on the chosen prefix or suffix.

Responses

Table 9 Common response headers

Parameter

Type

Description

statusCode

int

Explanation:

HTTP status code.

Value range:

A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response.

For more information, see Status Code.

Default value:

None

responseHeaders

Map<String, Object>

Explanation:

HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header.

Default value:

None

Sample Code

Sample code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Enter the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
String endPoint = "https://obs.ap-southeast-1.myhuaweicloud.com";
// 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_ID.
// 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.
String ak = System.getenv("ACCESS_KEY_ID");
String sk = System.getenv("SECRET_ACCESS_KEY_ID");
// Create an ObsClient instance.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
BucketNotificationConfiguration bucketNotificationConfig = new BucketNotificationConfiguration();

TopicConfiguration topicConfig = new TopicConfiguration();
//Customize a message notification ID.
topicConfig.setId("id1");
//Topic URN. You need to create a topic, for example, urn:smn:region:project_id:smn_topic, on SMN.
topicConfig.setTopic("your topic");
topicConfig.getEventTypes().add(EventTypeEnum.OBJECT_CREATED_ALL);
Filter topicFilter = new Filter();
topicFilter.getFilterRules().add(new FilterRule("prefix", "smn"));
topicFilter.getFilterRules().add(new FilterRule("suffix", ".jpg"));
topicConfig.setFilter(topicFilter);
bucketNotificationConfig.addTopicConfiguration(topicConfig);

obsClient.setBucketNotification("bucketname", bucketNotificationConfig);