This topic describes how to query and analyze events in custom event buses in the EventBridge console.
Background information
You can query the content of all events in custom event buses. Before you can query the content of events, you must create a schema and map the relationship between the events and the schema to the event analysis platform. Then, you can perform key-value pair retrieval, GUI-based analysis, event tracing, and event source tracing on the event analysis platform based on the bound schema. You can use one of the following methods to bind a schema to custom events:
Push mapping: allows you to bind the Uniform Resource Identifier (URI) of a schema by defining the dataschema parameter when you call the PutEvents API operation to publish events.
Rule mapping: allows you to bind the URI of a schema by using the schema ID when you configure an event rule.
Prerequisites
EventBridge is activated and the required permissions are granted to a Resource Access Management (RAM) user. For more information, see Activate EventBridge and grant permissions to a RAM user.
An Alibaba Cloud account is created and the AccessKey pair of the Alibaba Cloud account is obtained. You can create or view your AccessKey pair on the Security Management page of the Alibaba Cloud Management Console.
Usage notes
You can create and query only event schemas that meet the OpenAPI 3.0 specifications.
Step 1: Create a custom schema
- Log on to the EventBridge console. In the left-side navigation pane, click Schemas.
- In the top navigation bar, select the region.
On the Schemas page, click the Custom Schema Groups tab. On the Custom Schema Groups tab, click Create Schema.
In the Create Schema panel, configure the parameters and click OK. The following table describes the parameters.
Parameter
Description
Example
Schema ID
The name of the schema.
test
Schema Description
The description of the schema.
demo
Schema Content
Create Directly: The system automatically creates JSON text that meets the OpenAPI 3.0 specifications.
Create Based on JSON: The system generates a schema based on the JSON sample that you provide.
Create Directly
Compatible Type
Specifies whether to enable the compatibility check between new and old versions. By default, no compatibility check is performed.
No Compatibility Check
After the schema is created, you can view the URI, version, format, and compatibility type of the schema on the Custom Schema Groups tab of the Schemas page.
Step 2: Use one of the following methods to map the schema
Rule mapping
On the Event Buses page, click the custom event bus that you want to manage. In the left-side navigation pane, click Event Rules. Then, click Create Rule.
In the Create Rule panel, configure the parameters and click Create.
In the Configure Basic Info step, configure the Name and Description parameters and click Next Step.
In the Configure Event Pattern step, specify the custom event source that you want to query and click Next Step.
In the Configure Targets step, set the Service Type parameter to Event Analysis and the Mapping Method parameter to Rule Mapping. Then, select the same group, ID, and version as the schema that you created in Step 1: Create a custom schema for the Group Name, Schema ID, and Schema Version parameters.
Push mapping
Add the dataschema parameter and the URI that you obtained in Step 1: Create a custom schema to the SDK and push events. Sample code:
import com.aliyun.eventbridge.EventBridge; import com.aliyun.eventbridge.EventBridgeClient; import com.aliyun.eventbridge.models.CloudEvent; import com.aliyun.eventbridge.models.Config; import com.aliyun.eventbridge.models.PutEventsResponse; import com.aliyun.eventbridge.util.EventBuilder; import com.google.gson.Gson; import java.net.URI; import java.util.ArrayList; import java.util.Date; import java.util.List; public class PutEventsSample { private EventBridge eventBridgeClient; public PutEventsSample() { Config authConfig = new Config(); authConfig.accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");// The AccessKey ID that is provided by Alibaba Cloud for authentication. You can obtain the AccessKey ID on the Security Management page in the Alibaba Cloud Management Console. For more information, see the "Prerequisites" section of this topic. authConfig.accessKeySecret =System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");// The AccessKey secret that is provided by Alibaba Cloud for authentication. You can obtain the AccessKey secret on the Security Management page in the Alibaba Cloud Management Console. For more information, see the "Prerequisites" section of this topic. authConfig.endpoint = "{endpoint}";// The endpoint. For more information, see Regions and endpoints. eventBridgeClient = new EventBridgeClient(authConfig); } public void putEventsSample() { List<CloudEvent> cloudEventList = new ArrayList<>(); CloudEvent cloudEvent = EventBuilder.builder() .withId("a5074581-7e74-4e4c-868f-47e7afdf****") .withSource(URI.create("acs.oss")) .withType("oss:ObjectCreated:PostObject") .withSubject("acs:oss:cn-hangzhou:{yourAccountId}:xls-papk/game_apk/123.jpg") .withTime(new Date()) .withJsonStringData("{ \"E-Mail\": \"${email}\" }") .withAliyunEventBus("demo-bus") .build(); cloudEvent.setDataschema("{Schema URI}");// Specify the schema URI that is obtained in Step 1. cloudEventList.add(cloudEvent); PutEventsResponse putEventsResponse = eventBridgeClient.putEvents(cloudEventList); System.out.println(new Gson().toJson(putEventsResponse)); } public static void main(String[] args){ PutEventsSample sample = new PutEventsSample(); try { sample.putEventsSample(); } catch (Throwable e) { e.printStackTrace(); } } }
On the Event Buses page, click the custom event bus that you want to manage. In the left-side navigation pane, click Event Rules. Then click Create Rule.
In the Create Rule panel, configure the parameters and click Create.
In the Configure Basic Info step, configure the Name and Description parameters and click Next Step.
In the Configure Event Pattern step, specify the custom event source that you want to query and click Next Step.
In the Configure Targets tab, set the Service Type parameter to Event Analysis and Mapping Method to Push Mapping.
Step 3: Query events
- Log on to the EventBridge console. In the left-side navigation pane, choose .
- In the top navigation bar, select the region.
- On the Event Analysis page, configure the parameters that are described in the following table and click Query.
Parameter Required Description Event Bus Yes The name of the event bus whose events you want to query. Schema Yes The schema of the event type to be queried. For more information about the types of Alibaba Cloud service events, see Alibaba Cloud service event sources. Key-value Match No The key-value pair that is used to match events. You can specify one or more key-value pairs. Conditional expressions support the following operators: =
: If you use = as the operator, you must specify the value of the field. In this case, all events that meet the key = value condition are queried.!=
: If you use != as the operator, you must specify the value of the field. In this case, all events that meet the key != value condition are queried.exists
: All events that meet thekey exists
condition are queried.does-not-exist
: All events that meet thekey does-not-exist
condition are queried.
Note You can also select AND or OR to the right of the Key-value Match parameter to specify the relationship between multiple key-value pairs.Aggregate Function No The aggregate function that is used for data visualization. If you want to view the query results in charts, you must set the Aggregate Function parameter. You can select one or more aggregate functions. An aggregate function corresponds to a line chart. Grouped By No The name of the field based on which events are grouped. If you want to group the queried events, enter a field that specifies an event property. You can enter one or more fields. Ordered By No The name of the field based on which events are sorted. Events can be sorted in ascending or descending order based on the aggregate functions specified by the Aggregate Function parameter. You can enter one or more fields. Time Range No The time range to query the events. Number of Events No The maximum number of events to be queried. After the preceding steps are performed, you can view the query results on the Aggregate Function and Table tabs of the Event Analysis page.
Step 4: Analyze the results
For information about the queried event parameters, see Analysis of the events in the system event bus.