This topic describes how to push events from Message Service (MNS) to Function Compute by using EventBridge.

Step 1: Create a connector

  1. Log on to the EventBridge console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Custom Event Buses.
  4. On the Custom Event Buses page, find the required event bus and click Connectors in the Operations column.
  5. On the Connectors page, click Create Connector.
  6. In the Select Event Source step, click Message Service.
  7. In the Configure Connector step, perform the following operations and click Create and Start:
    • Name: Enter the name of the connector.
    • Event Source: Select Message Service.
    • Custom Event Bus: Select the custom event bus that you specify in Step 4.
    • Queue Name: Select the created MNS queue.

Step 2: Publish events

  1. Log on to the MNS console.
  2. Select a region in the top navigation bar.
  3. In the left-side navigation pane, click Queues.
  4. On the Queues page of the console, find MyQueue. In the Action column, click Send Message.
  5. In the Send Message dialog box, enter a message and click Send Message.sendmessage

Step 3: Create an event rule

  1. Log on to the EventBridge console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Custom Event Buses.
  4. On the Custom Event Buses page, find the required event bus and click Rules in the Operations column.
  5. On the Rules page, click Create Rule.
  6. On the Create Rule page, perform the following steps:
    1. In the Configure Basic Info step, enter a rule name in the Name field and a rule description in the Description field, and then click Next Step.
    2. In the Configure Event Pattern step, select Customized Pattern for Event Pattern Type, specify the event pattern in the Event Pattern Content section, and then click Next Step.

      For more information, see Event patterns.

    3. In the Configure Targets step, configure an event target.
      • Service type: Click Function Compute.
      • Service: Select the service that you created.
      • Function: Select the function that you created.
      • Event: Select the type of event transformer.
        • Complete Event: The complete data structure is delivered without conversion. The data structure is defined in the CloudEvents 1.0 protocol.
        • Partial Event: JSONPath is used to extract the content that needs to be delivered to the event target.
        • Constant: The event serves as a trigger. Only constants are delivered regardless of the event content.
        • Template: Events are routed based on a custom template. You can customize variables in the template.

          The following scripts shows examples of variables and a template.

          Variables:

          {
            "source":"$.source",
            "type":"$.type"
          }

          Template:

          The event comes from ${source},event type is ${type}.

        For more information, see Transform events.

      • Service Version and Alias: Select a service version and alias.
      Notice Make sure that the event target and the event rule are in the same region.
    4. Click Create.

Verify the result

To verify the result, you can view logs in the Function Compute console.

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Service/Function.
  4. On the Service/Function page, click the service. Then, click the function name in the Function Name column on the Functions tab.
  5. On the page that appears, click the Log tab to view logs.
    FC Invoke Start RequestId: c2be67a7-fh1a-9619-ei4c-3c04gcf6****
    2020-11-19T11:11:34.161Z c2be67a7-fh1a-9619-ei4c-3c04gcf6c**** [verbose] Receive Event v2 ==> The event comes from aliyun.ui,event type is ui:Created:PostObject.
    2020-11-19T11:11:34.167Z c2be67a7-fh1a-9619-ei4c-3c04gcf6c**** 
    FC Invoke End RequestId: c2be67a7-fh1a-9619-ei4c-3c04gcf6c****