Author: Ken Meng
In the process of enterprise digital transformation, it is natural to encounter scenarios such as message routing, remote multi-activity, protocol adaptation, and message backup. This article mainly introduces the application scenarios and application experiments of EventBridge message routing to help you understand how to efficiently build message routing capabilities through EventBridge's message routing.
background knowledge
EventBridge message routing mainly involves the following cloud products and services:
- Event Bus EventBridge
The event bus EventBridge is a serverless event bus service provided by Alibaba Cloud. It supports Alibaba Cloud services, custom applications, and SaaS applications to access in a standardized and centralized manner, and can use the standardized CloudEvents 1.0 protocol between these applications. Route events to help you easily build loosely coupled, distributed event-driven architectures.
- message queue RabbitMQ version
Alibaba Cloud Message Queue RabbitMQ version supports AMQP protocol and is fully compatible with RabbitMQ open source ecosystem and multi-language clients, creating a distributed, high-throughput, low-latency, and highly scalable cloud messaging service. Out-of-the-box, users do not need to deploy without operation and maintenance, and easily realize fast cloud access. Alibaba Cloud provides fully managed services, which are more professional, more reliable, and more secure.
- Message Queuing MNS version
Alibaba Cloud Message Service MNS version is an efficient, reliable, secure, convenient, and elastically scalable distributed message notification service. MNS can help application developers to freely pass data, notify messages on the distributed components of their applications, and build loosely coupled systems.
Scenario application
The EventBridge message routing function is mainly used in the following three scenarios in the process of building a message system. One is the message routing scenario, the other is the message multi-activity scenario, and the third is the multi-protocol adaptation scenario. The three scenarios are briefly described below. introduce.
message routing scenarios
This scenario refers to the scenario where you want to redistribute messages, and distribute messages to other topics or cross-regional topics through simple filtering or filtering, to achieve message sharing & message desensitization.
Distributing messages to different topics for consumption through a layer of forwarding is the core capability of message routing. With the transformation of enterprises, there will be more and more scenarios of news splitting and business desensitization. The following figure is a typical routing diversion scenario.
news scene
The multi-active message scenario means that each data center deploys a complete and independent MQ cluster. The application services in the data center only connect to the local MQ cluster, not to the MQ clusters of other units. The message routing module included in the MQ cluster is responsible for synchronizing messages on the specified topic between different unit MQ clusters.
According to whether the application service has the unitization capability, it can be divided into two categories: central service and unit service. The central service only provides services in one data center; the unit service provides services in each data center, but is only responsible for some users who meet the rules, not all users.
All data centers that deploy unit services are a unit, and the unit services of all units provide external services at the same time, thus forming a remote multi-active architecture or a unitized architecture. Through the multi-active management and control platform, the traffic that each unit service is responsible for can be dynamically adjusted.
Multi-protocol adaptation scenarios
As the business team grows larger, the demand for message construction is increasing day by day. Due to the different technology stacks of departments, the message protocols between departments are also different. Multi-protocol adaptation refers to the ability to smoothly migrate from one message protocol to multiple message protocols.
Architecture description
Use EventBridge's event stream capability for message routing. The event stream model is the main processing model of EventBridge in the message field. It is suitable for standard Streaming (1:1) stream processing scenarios and has no bus concept. It is used for end-to-end message routing, message dumping, message synchronization and processing, etc., to help developers easily build cloud data pipeline services.
The following architecture shows how to route MNS messages to RabbitMQ Queues, MNS Queues by bridging EventBridge. (A/B link chooses one to test)
application experiment
Target
Through the operation of this experimental tutorial, you can create a message routing service in the event bus console through the Alibaba Cloud console, and implement message routing and simple message desensitization in the EventBridge console.
After experiencing this experiment, the knowledge that can be acquired is:
- Create a message routing task;
- Create RabbitMQ instance, MNS instance and simple message sending.
resource
The resources used are as follows: (The resources in this experiment follow the principle of minimum, and use the minimum resources that meet the needs of the scene)
- Resource 1: EventBridge event bus
- Resource 2: Alibaba Cloud Message Queue RabbitMQ version
- Resource 3: Alibaba Cloud Message Queue MNS version
step
1) Create MNS resource
This experiment is divided into two optional scenarios A/B:
A. The scene is delivered to MNS Queues2 through MNS Queues1\
B. The scene is delivered to RabbitMQ Queues through MNS Queues1
Different scenes can be selected according to interests.
This step will guide you how to create a Message Queuing MNS version through the console.
Log in to the Alibaba Cloud console with your own Alibaba Cloud account, and then access the Message Queuing MNS console. [1]
In the left navigation bar of the console, click Queue List. (The resource region can be the same region, and Hangzhou is selected by default for this guide)
On the list page, click Create Queue and fill in the name information "test-mns-q"
After creation, click "Details"
Find the MNS public network access point information, and remember this information, which will be used in subsequent experiments.
E.g.http://1825725063814405.mns.cn-hangzhou.aliyuncs.com
Note: Repeat the above steps to create "test-mns-q2" of experimental link A
2) Create RabbitMQ resources (optional for B experiment)
This step will guide you on how to create a message queue for RabbitMQ through the console.
Log in to the Alibaba Cloud console with your own Alibaba Cloud account, and then access the message queue RabbitMQ version console. [2]
In the left navigation bar of the console, click Instance List. (The resource region can be the same region, and Hangzhou is selected by default for this guide)
On the list page, click Create Instance and complete the creation.
After the creation is complete, click Details to enter the instance details page;
Create "test-amqp-v" in "Vhost list";
In "Queue List", select Vhost as "test-amqp-v", and create "test-amqp-q";
3) Create EventBridge event flow task - MNS TO MNS (optional for A experiment)
This step will guide you on how to create an EventBridge event stream through the console.
Log in to the Alibaba Cloud console with your own Alibaba Cloud account, and then access the EventBridge console. [3]
Note: It needs to be activated for the first use.
Click the "Event Stream" list, and create a task in the list (the resource region can be the same region, this guide selects Hangzhou by default)
Create an event stream named "test-amqp-mns2mns", click Next;
Specify the event source, the event provider is "Message Service MNS", the queue name is "test-mns-q", and click Next;
Specify the rule, the rule part can not be filtered, the default matches all, just click Next;
Note: The content of the rules can be specified according to your needs. In order to reduce the difficulty of this experiment, all are delivered by default. For more details, please refer to:
https://help.aliyun.com/document_detail/181432.html
Select "Message Service MNS" for the service type, "test-mns-q2" for the queue name, "Partial Events" for the message content, and click Create
Note: The content of the message can be specified according to your needs. The data field is delivered by default in this experiment. For more details, please refer to:
https://help.aliyun.com/document_detail/181429.html
After the creation is complete, you can click "Start" to start the event flow
4) Create EventBridge event flow task - MNS TO RabbitMQ (optional for B experiment)
This step will guide you on how to create an EventBridge event stream through the console.
Log in to the Alibaba Cloud console with your own Alibaba Cloud account, and then access the EventBridge console. [3] Note: It needs to be activated for the first time.
Click the "Event Stream" list, and create a task in the list (the resource region can be the same region, this guide selects Hangzhou by default)
Create an event stream named "test-amqp-mns2rabbitmq", click Next
Specify the event source, the event provider is "Message Service MNS", the queue name is "test-mns-q", and click Next
Specify the rule, the rule part can not be filtered, the default matches all, just click Next
Note: The content of the rules can be specified according to your needs. In order to reduce the difficulty of this experiment, all are delivered by default. For more details, please refer to:
https://help.aliyun.com/document_detail/181432.html
Select "Message Queue RabbitMQ Version" for the service type, the specific configuration is as follows, click Create
实例ID:选择创建好的RabbitMQ ID
Vhost:选择“test-amqp-v”
目标类型:选择“Queue”
Queue:选择“test-amqp-q”
Body:选择“部分事件”,填写“$.data”
MessageId:选择“常量”,填写“0”
Properties:选择“部分事件”,填写“$.source”
Note: The content of the message can be specified according to your needs. The data field is delivered by default in this experiment. For more details, please refer to:
https://help.aliyun.com/document_detail/181429.html
After the creation is complete, you can click "Start" to start the event flow
5) Verify the routing task
Send experiment message to MNS Source "test-mns-q"\
Click to download MNS SDK [4]
Modify sample.cfg
Fill in AccessKeyId, AccessKeySecret, Endpoint and other information in "sample.cfg"
AccessKeyId and AccessKeySecret can be created in Alibaba Cloud RAM console [5]
Endpoint is step 1, MNS public network access point address
AccessKeyId = LTAI5t96yU2S2E84BYsNNQ33
AccessKeySecret = xxxxxxx
Endpoint = http://1825725063814405.mns.cn-hangzhou.aliyuncs.com
Fill in the effect as follows, save
Find the "sendmessage.py" example in the sample directory
Adjust the loop parameter to 200 and save (optional)
Save and run "python sendmessage.py test-mns-q"
python sendmessage.py test-mns-q
In the event stream console [6] , click "test-mns-q2" and "test-amqp-q" to view the details of the dump.
Note: MNS Q only supports single subscription and does not support broadcast mode. Therefore, the test requires two experiments of MNS/RabbitMQ, and one of them is selected to be shut down before the experiment.
For broadcast mode, create an MNS Topic resource.
A link experiment results:
B link experimental results:
Advantages and Summary
EventBridge event flow provides end-to-end message routing capabilities, and can complete message distribution, message synchronization, cross-regional message backup, and cross-product message synchronization through simple configuration. It has the advantages of simple operation and maintenance, low cost, high efficiency and stable use. At the same time, using EventBridge can realize basic data processing capabilities such as data filtering and data desensitization. It is the solution with the lowest operation and maintenance cost in the message routing scenario.
Related Links
[1] Message Queue MNS console
[](https://mns.console.aliyun.com/accounttraceid=a42e9ca8e911475087856852d4526c4dsjeq)
https://mns.console.aliyun.com/accounttraceid=a42e9ca8e911475087856852d4526c4dsjeq
[2] Message queue RabbitMQ version console
[](https://amqp.console.aliyun.com/)
https://amqp.console.aliyun.com/
[3] EventBridge Console
[](https://eventbridge.console.aliyun.com/overview)
https://eventbridge.console.aliyun.com/overview
[4] Click to download MNS SDK
[5] Alibaba Cloud RAM Console
[](https://ram.console.aliyun.com/manage/ak)
https://ram.console.aliyun.com/manage/ak
[6] Event Stream Console
[](https://eventbridge.console.aliyun.com/cn-hangzhou/event-streamings)
(https://eventbridge.console.aliyun.com/cn-hangzhou/event-streamings)
Click “ ” at the end of the article to learn more about Cloud EventBridge 10~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。