tencent cloud

Feedback

Quickly Delivering Custom Events

Last updated: 2022-08-12 10:41:31

    Overview

    In addition to Cloud Monitor and CloudAudit events generated by official Tencent Cloud services, events generated by your own applications can only be published to custom event buses. You can create custom event buses and configure event connectors to deliver custom events. Alternatively, you can use an API/SDK to deliver custom events. This document describes how to deliver custom events via an event connector.

    Note:

    In addition to using an event connector, you can call an API to deliver custom events.

    Delivering Custom Events

    Step 1. Create a custom event bus

    1. Log in to the EventBridge console and click Create Event Bus.
    2. Enter the event bus name and description.
    3. Click OK.

    Step 2. Create an event connector

    1. On the Event Bus page, click the name of the custom event bus to enter the event bus details page.
    2. On the event bus details page, click Add in the Event connector area.
    3. Enter information as instructed. (This example takes a CKafka event connector as an example.)

      Set Connector type to CMQ (Kafka), set other parameters as needed, and click OK. For how to configure other types of connectors, see here.
    4. Click OK. After the configuration is completed, the event connector can pull a message from CKafka, generate an event based on the message content, and deliver the event to the event bus. Taking the message "Hello from Ckafka again!" as an example, the event connector generates the following event:
      {       
          "specversion":"1.0",       
          "id":"13a3f42d-7258-4ada-da6d-******3b4662",
          "type":"connector:kafka",   
          "source":"ckafka.cloud.tencent",   
          "subject": "qcs::ckafka:ap-guangzhou:uin/1250000000:ckafkaId/uin/1250000000/ckafka-123456",     
          "time":"1615430559146",   
          "region":"ap-guangzhou",       
          "datacontenttype":"application/json;charset=utf-8",   
          "data":{             
               "topic":"test-topic",         
               "Partition":1,         
               "offset":37,         
               "msgKey":"test",         
               "msgBody":"Hello from Ckafka again!"      
             }
      }
      

    For more information about the event format, see Event Structure.

    Note

    Currently, only delivery for Tencent Cloud CKafka instances is supported. Confirm that no username or password is configured for your CKafka instances. Otherwise, the connector may fail to get messages.

    Step 3. Create an event rule

    1. Select Event Rule on the left sidebar.
    2. At the top of the Event Rule page, select the created event bus from the Event Bus drop-down list and click Create Event Rule.
    3. Enter information as instructed.

      This event pattern means to receive all messages from the Ckafka connector. For how to write an event pattern, see Event Pattern.
    4. Click Next and configure the event target, which can be Serverless Cloud Function (SCF), Cloud Log Service (CLS), message pushing service, or CMQ (Kafka). Here takes SCF as an example. Event content will be delivered to SCF as parameters.

      The test function here is to print the events received, and you can write your function based on the actual business scenario. Alternatively, you can quickly deliver events to CKafka or a downstream SaaS service through a template function provided by the platform. For more information, see SCF Target Delivery.

    Step 4. Test an event

    After sending a message to the target topic, you can see the following information on the corresponding SCF log page:

    START RequestId:79e6d53e-7a98-11ec-8f0d-******4284e2
    Received event: {
    "data": {
      "Partition": 1,
      "msgBody": "Hello from Ckafka again!",
      "msgKey": "test",
      "offset": 37,
      "topic": "target-topic"
    },
    "datacontenttype": "application/json;charset=utf-8",
    "id": "13a3f42d-7258-4ada-da6d-******3b4662",
    "region": "ap-guangzhou",
    "source": "ckafka.cloud.tencent",
    "specversion": "0",
    "status": "",
    "subject": "qcs::ckafka:ap-guangzhou:uin/1250000000:ckafkaId/uin/1250000000/ckafka-123456",
    "tags": null,
    "time": 1615430559146,
    "type": "connector:kafka"
    }
    

    Step 5. Trace the event delivery history

    EventBridge provides the event tracing capability. After enabling event tracing, you can view the event delivery history on the event query page of an event bus.

    If the event tracing mode is set to Default, only the matched events that failed to be delivered to the downstream can be queried. If you want to query all events, choose Event Bus > Event Tracking, set the delivery type to All logs, and select Always report logs of rule matching failures.

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support