Introduction: In the process of enterprise digital transformation, it is natural to encounter scenarios such as message routing, remote live, protocol adaptation and message backup. This article focuses on the application scenarios and experiments of EventBridge message routing to help you understand how to efficiently build message routing capabilities through EventBridge message routing.
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 focuses on the application scenarios and experiments of EventBridge message routing to help you understand how to efficiently build message routing capabilities through EventBridge message routing.
Background knowledge
EventBridge message routing primarily involves the following cloud products and services:
- The event bus EventBridge
EventBridge is a serverless event bus service provided by Ali Cloud. It supports standardized and centralized access of Ali Cloud services, custom applications and SaaS applications, and can route events among these applications using standardized CloudEvents 1.0 protocol. Helps you easily build loosely coupled, distributed event-driven architectures.
- Message queue RabbitMQ version
RabbitMQ support AMQP protocol, fully compatible with RabbitMQ open source ecosystem and multi-language client, to create distributed, high throughput, low latency, high scalability cloud message service. Out of the box, users do not need to deploy without operation and maintenance, easily realize fast cloud, Ali Cloud provides full hosting services, more professional, more reliable, more secure.
- Message queue version MNS
Ali Cloud message service MNS version is an efficient, reliable, secure, convenient, flexible and extensible distributed message notification service. MNS enables application developers to freely transfer data, notification messages, and build loosely coupled systems across distributed components of their applications.
Application scenarios
The EventBridge message routing function is mainly applied to the following three scenarios: message routing, message multi-activity, and multi-protocol adaptation. The following three scenarios are briefly introduced.
Message Routing Scenario
This scenario refers to the scenario in which messages are expected to be re-distributed to other topics or cross-region topics through simple filtering or filtering to achieve message sharing & message desensitization.
The distribution of messages to different Topic consumption through one-layer forwarding is the core capability of message routing. With enterprise transformation, there will be more and more scenarios of message splitting and business desensitization. The following figure shows a typical routing traffic diversion scenario.
Message live scenario
In the message live scenario, a complete and independent MQ cluster is deployed in each data center. The application service in the data center only connects to the local MQ cluster and does not connect to other MQ clusters. The message routing module contained in the MQ cluster is responsible for synchronizing messages for a given topic between different cell MQ clusters.
Application services can be divided into central service and unit service according to whether they have unitary capability. Central services are provided in only one data center; The unit service provides services in each data center, but only takes care of some users that comply with the rules, not all users.
All data centers with unit services are one unit, and all unit services provide services externally at the same time, thus forming a remote multi-live architecture or unit architecture. The multi-activity management platform allows you to dynamically adjust the traffic of each unit service.
Multi-protocol adaptation scenario
With the growing business team, the demand for message construction is increasing day by day. The different technology stacks of departments will lead to different message protocols among departments. Multi-protocol adaptation refers to the ability to migrate smoothly from one messaging protocol to multiple messaging protocols.
Architectural description
EventBridge event flow capability is used for message routing. EventBridge event flow model is the main processing model of EventBridge in the field of message processing, which is applicable to standard Streaming (1:1) stream processing scenarios without the concept of bus. It is used for end-to-end message routing, message dump, message synchronization and processing, and helps developers easily build data pipeline services on the cloud.
The following architecture shows how to route MNS messages to RabbitMQ Queues, MNS Queues by bridging EventBridge. (Either A/B link is tested)
Application experiment
The target
Through the operation of this experimental tutorial, you can create a message routing service in the Event Bus console through ali Cloud console, and realize message routing and simple message desensitization on the EventBridge console.
After experiencing this experiment, the following knowledge can be mastered:
- Create a message routing task;
- Create RabbitMQ instances, MNS instances and simple message sending.
resources
The resources used are as follows :(this experiment follows the principle of minimum resources and uses minimal resources that meet the requirements of the scene)
- Resource 1: EventBridge event bus
- Resource 2: Ali Cloud Message queue RabbitMQ version
- Resource 3: Ali Cloud Message queue MNS version
steps
1) Create MNS resources
This experiment consists of two scenarios: A. Scenario with MNS Queues1 And MNS Queues2. Scenario with MNS Queues1 and RabbitMQ Queues
You can choose different scenarios according to your interests.
This step will guide you through how to create message queue VERSION MNS from the console.
Log in to the Ali Cloud console using your own Ali Cloud account, and then access the Message queue MNS version console. [1]
On the left navigation bar of the console, click the queue list. (Resource region should be the same region, hangzhou is selected by default for this guidance)
On the list page, click Create queue and enter the name “test-MNS-q”.
Click “Details” after creation
Find the INFORMATION about the MNS public network access point and remember this information for future experiments.
E.g.
1825725063814405.mns.cn-hangzhou.aliyuncs.com
Note: Repeat the previous steps to create “test-MNS-Q2” for test link A
2) Create RabbitMQ resources (B experiment optional)
This step will guide you through creating the RabbitMQ version of the message queue from the console.
Log in to the Ali Cloud console using your own Ali Cloud account and then access the Message queue RabbitMQ console. [2]
On the left navigation bar of the console, click the instance list. (Resource region should be the same region, hangzhou is selected by default for this guidance)
On the list page, click Create instance and complete the creation.
After creation, click Details to enter the instance details page;
Create test-amqp-v in Vhost List.
In Queue, set Vhost to test-amqp-v and create test-amqp-q.
3) Create EventBridge eventStream task – MNS TO MNS (A experiment optional)
This step guides you through how to create an EventBridge event flow from the console.
Log in to the Ali Cloud console using your own Ali Cloud account and then access the EventBridge console. [3]
Note: It needs to be opened for the first time.
Click the “Event Flow” list, and create a task in the list (the resource region is the same, hangzhou is selected by default).
Create an event stream named “test-amqp-mNS2mns” and click Next.
Specify the event source, set the event provider to Message Service MNS, set the queue name to test-MNS-q, and click Next.
Specify the rule, the rule part does not filter, default match all, directly click next;
Note: The content of the rules can be specified according to the requirements. In order to reduce the difficulty of the experiment, all the rules are delivered by default. Please refer to:
Help.aliyun.com/document\_d…
Select Message Service MNS for service type, test-MNS-Q2 for queue name, partial Events for message content, and click Create
Note: Message content can be specified according to requirements, and data field is delivered by default in this experiment. For more details, please refer to:
Help.aliyun.com/document\_d…
Once created, you can click Start to start the event stream
4) Create EventBridge eventStream task – MNS TO RabbitMQ (B experiment optional)
This step guides you through how to create an EventBridge event flow from the console.
Log in to the Ali Cloud console using your own Ali Cloud account and then access the EventBridge console. **[3]** Note: It needs to be opened for the first time.
Click the “Event Flow” list, and create a task in the list (the resource region is the same, hangzhou is selected by default).
Create an event stream named test-amqp-mNS2RabbitMQ and click Next
Specify the event source, event provider as Message Service MNS, queue name as test-MNS-q, and click Next
Specify the rule, the rule part does not filter, default match all, directly click next
Note: The content of the rules can be specified according to the requirements. In order to reduce the difficulty of the experiment, all the rules are delivered by default. Please refer to:
Help.aliyun.com/document\_d…
Set service type to Message Queue RabbitMQ Version and click Create
RabbitMQ ID Vhost: select test-amqp-v Target type: Select Queue Queue: select test-amqp-q Body: select partial events and enter $. Data MessageId: Select "Constant" and fill in "0" Properties: Select "Partial Events" and fill in "$.source"Copy the code
Note: Message content can be specified according to requirements, and data field is delivered by default in this experiment. For more details, please refer to:
Help.aliyun.com/document\_d…
Once created, you can click Start to start the event stream
5) Verify the routing task
Send the test message to the MNS Source “test-MNs-q”
Click to download the MNS SDK**[4]**
Modified sample. CFG
In sample. CFG, enter AccessKeyId, AccessKeySecret, and Endpoint
AccessKeyId, AccessKeySecret can be created in Ali Cloud RAM console **[5]**
Endpoint is the IP address of the MNS public network access point
AccessKeyId = LTAI5t96yU2S2E84BYsNNQ33
AccessKeySecret = xxxxxxx
Endpoint = http://1825725063814405.mns.cn-hangzhou.aliyuncs.com
Copy the code
The result is as follows, save
Find the “sendmessage.py” example in the sample directory
Set the loop parameter to 200 and save (optional)
Save and run “python sendmessage.py test-mns-q”
python sendmessage.py test-mns-q
Copy the code
In the event flow console **[6]**, click “test-MNS – Q2” and “test-amqp-q” respectively to view the details of the dump.
Note: MNS Q supports single subscription only and does not support broadcast mode. Therefore, this test requires the MNS/RabbitMQ experiment to be switched off.
For broadcast mode, create an MNS Topic resource.
A Link experiment results:
B Link experiment results:
Advantages and Summary
EventBridge event flows provide end-to-end message routing capabilities that can be easily configured for message distribution, message synchronization, cross-geographic message backup, and cross-product message synchronization. With simple operation and maintenance, low cost, high efficiency, stable use and other advantages. You can also use EventBridge to implement basic data filtering, data desensitization and other data processing capabilities. It is the lowest o&M solution in message routing scenarios.
The original link
This article is the original content of Aliyun and shall not be reproduced without permission.