Help Center/ EventGrid/ Best Practices/ Routing Events from RocketMQ to FunctionGraph Based on Serverless Event Stream
Updated on 2025-08-07 GMT+08:00

Routing Events from RocketMQ to FunctionGraph Based on Serverless Event Stream

This chapter describes how to use EG to route the RocketMQ events to FunctionGraph.

Prerequisites

Perform the following operations before this practice:

Creating a Serverless Event Stream

  1. Log in to the EG console. In the navigation pane, choose Event Streams > Serverless Event Streams. In the upper right corner, click Create Serverless Event Stream.
  2. Click in the upper left corner to configure the event stream name and description, and click OK.
  3. Configure a RocketMQ event source.
  4. Configure event rules. In this example, the default configuration is used.
  5. Configure the FunctionGraph event target.

    In the Rule area, set Transform Type to Variables. The following are examples for Parameters and Template.

    Parameter:

    {
      "message": "$.data.context"
    }

    Template:

    The message is ${message}.
    Figure 1 Configure variables

  6. After the event stream is configured, click Save in the upper right corner and click Enable in the Operation column of the event stream list.
  7. Click in the upper left corner, search for FunctionGraph, and go to the FunctionGraph console. In the navigation pane on the left, choose Functions > Function List, and click the name of the created function to go to the function details page.
  8. Click the Code tab, add the following code to the editing area, and click Deploy to refresh the code.

    print("body is:", json.dumps(event))
    Figure 2 Editing the code

Publishing Events from RocketMQ to FunctionGraph

  1. Click in the upper left corner, search for rocketmq, and access the Distributed Message Service (for RocketMQ) console. In the navigation pane on the left, choose RocketMQ Instances. Click the name of the created instance to go to its details page.
  2. In the navigation pane on the left, choose Topics. Click Produce Message of the created topic. In the Message Body box, enter {"message":"aaa"}. Retain the default values for other parameters and click OK.

    Figure 3 Producing a message

  3. Return to the FunctionGraph console, choose Functions > Function List in the navigation pane, and click a function name to go to the function details page.
  4. Choose Monitoring > Logs > Request Logs to view the event content pushed from the RocketMQ instance.

    Figure 4 Viewing logs