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:
- Enabling EG and Authorizing Permissions.
- Creating a VPC.
- Creating a Security Group.
- Buying a RocketMQ Instance.
- Creating an Event Function. Use Python 3.9 as an example.
Creating a Serverless Event Stream
- 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.
- Click
in the upper left corner to configure the event stream name and description, and click OK.
- Configure a RocketMQ event source.
- Configure event rules. In this example, the default configuration is used.
- 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 - 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.
- 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.
- 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
- 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.
- 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
- 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.
- Choose Monitoring > Logs > Request Logs to view the event content pushed from the RocketMQ instance.
Figure 4 Viewing logs
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot