In most cases, live streaming for online education involves multiple channels, and each channel has multiple members. This topic describes how to use ApsaraMQ for MQTT to mute a member and send interaction messages, client status notifications, and system notifications during live streaming. In the sample scenarios provided in this topic, one teacher and two students are in a single channel. The teacher and students use HTML web clients. The backend applications are developed in Java.
Background information
To implement data exchange between ApsaraMQ for MQTT and ApsaraMQ for RocketMQ in live streaming interaction, you must create the corresponding data exchange rules, including the data inbound rule, the data outbound rule, and the rule for sending client status notifications. For more information, see Import data from other cloud services to ApsaraMQ for MQTT, Export data from ApsaraMQ for MQTT to other Alibaba Cloud services, and Export status events of ApsaraMQ for MQTT clients.
When you use an ApsaraMQ for MQTT client to send and receive messages, the ApsaraMQ for MQTT broker authenticates the client based on the Username and Password parameters that you configured for the client. The definitions of the Username and Password parameters vary based on the authentication scenario. In the sample scenarios of this topic, token-based authentication is used. For more information, see Overview of token-based authentication.
For information about the terms that are used in this topic, see the "Terms" section of this topic.
Sample scenarios
One teacher and two students are involved in each of the four online education scenarios provided in this topic. The teacher and students use different ApsaraMQ for MQTT clients and have different group IDs and device IDs. To prevent consumption loops in ApsaraMQ for RocketMQ, the topic that you create for the clients in a channel to send messages must be different from the topic that you create for the clients in the channel to subscribe to messages. The following sections describe the scenarios.
Scenario 1: Send interaction messages
For example, one teacher and two students are in a live streaming channel. If you want all members in the channel to receive a text message from Student A, you can associate the channel with topics in ApsaraMQ for MQTT. For example, the clients can use the roomSend/message topic to send messages and use the room/message/123456 topic to subscribe to messages, where:
roomSend is a parent topic that is used by all clients in the channel to send messages. You must create the topic in the ApsaraMQ for MQTT console.
room is a parent topic that is used by all clients in the channel to subscribe to messages. You must create the topic in the ApsaraMQ for MQTT console.
/message is a custom level-2 topic. You do not need to create the topic in the ApsaraMQ for MQTT console. In this example, /message indicates the text message.
/123456 is a custom level-3 topic. You do not need to create the topic in the ApsaraMQ for MQTT console. In this example, /123456 is the ID of the channel.
All members in the same channel subscribe to the room/message/123456 topic. The following figure shows the message flow.
The preceding process consists of the following steps:
Student A uses the client to send a message to ApsaraMQ for MQTT. Sample message:
topic: "roomSend/message", body: "{ 'peer': 'xxx', 'roomId': '123456', 'msg': 'xxx' }"
NoteMessages that are sent by using HTML web clients are in the JSON format.
ApsaraMQ for MQTT forwards the message to ApsaraMQ for RocketMQ based on the created data outbound rule.
The backend application that subscribes to the topic in ApsaraMQ for RocketMQ consumes the message to implement business processing, such as content moderation.
The backend application sends the processed message to the topic in ApsaraMQ for RocketMQ.
ApsaraMQ for RocketMQ forwards the message to ApsaraMQ for MQTT based on the created data inbound rule.
ApsaraMQ for MQTT pushes the message to all web clients, including the clients of the teacher, Student A, and Student B.
Scenario 2: Mute a member
This is a common scenario in which the point-to-point (P2P) messaging feature of ApsaraMQ for MQTT is used. In this scenario, a command message that indicates a student is muted by the teacher is sent to the client of the muted student. At the same time, the broker adds a muted member list for service verification and message filtering. The teacher client needs to send the message to the roomSend/command topic, where:
roomSend is a parent topic that is used by all clients in the channel to send messages. You must create the topic in the ApsaraMQ for MQTT console.
command is a custom level-2 topic. You do not need to create the topic in the ApsaraMQ for MQTT console. The command topic is different from the message level-2 topic and is used to send command messages.
You do not need to subscribe to P2P messages. In this scenario, the sample value is room/p2p/GID_student@@@002.
The following figure shows the message flow.
The preceding process consists of the following steps:
The teacher uses the client to send a command message to ApsaraMQ for MQTT to mute a student.
ApsaraMQ for MQTT forwards the message to ApsaraMQ for RocketMQ based on the created data outbound rule.
The backend application that subscribes to the topic in ApsaraMQ for RocketMQ receives the command message, verifies the message, and then saves the muted member list. This way, messages from the muted student can be filtered. The backend application also sends a P2P message room/p2p/GID_student@@@002 to the client of Student B to display the muting effect on the client.
Scenario 3: Send client status notifications
The asynchronous notification feature of ApsaraMQ for MQTT ensures that all members in the channel can receive notifications when other members come online and go offline. In this scenario, all clients must subscribe to the room/status topic, where:
room is a parent topic. You must create the topic in the ApsaraMQ for MQTT console.
status is a custom level-2 topic. You do not need to create the topic in the ApsaraMQ for MQTT console. In this example, status indicates messages related to client status.
After all ApsaraMQ for MQTT clients subscribe to this topic, ApsaraMQ for MQTT triggers an event message and sends the message to ApsaraMQ for RocketMQ when a client comes online or goes offline. The following figure shows the message flow.
The preceding process consists of the following steps:
ApsaraMQ for MQTT sends the notification about Student A coming online to ApsaraMQ for RocketMQ based on the created rule for sending client status notifications.
The backend application that subscribes to the topic in ApsaraMQ for RocketMQ consumes the message and implements business processing, such as attendance recording.
The backend application sends the processed message to the topic in ApsaraMQ for RocketMQ.
ApsaraMQ for RocketMQ forwards the message to ApsaraMQ for MQTT based on the created data inbound rule.
ApsaraMQ for MQTT broadcasts the message to all clients, including the clients of the teacher, Student A, and Student B.
Scenario 4: Send system notifications
In this scenario, the messaging feature of ApsaraMQ for MQTT is used. Notifications about system updates are sent to all members in the channel. In this scenario, all clients must subscribe to the room/system topic, where:
room is a parent topic. You must create the topic in the ApsaraMQ for MQTT console.
system is a custom level-2 topic. You do not need to create the topic in the ApsaraMQ for MQTT console. In this example, system indicates messages that are sent by the system.
The following figure shows the message flow.
The preceding process consists of the following steps:
The backend application sends the notification about a system update to the topic in ApsaraMQ for RocketMQ.
ApsaraMQ for RocketMQ forwards the message to ApsaraMQ for MQTT based on the created data inbound rule.
ApsaraMQ for MQTT pushes the message to all the clients, including the clients of the teacher, Student A, and Student B.
Process
The following figure shows the process of the four sample scenarios of live streaming for online education. The code that is used for the SDKs varies because different features of ApsaraMQ for MQTT are used in each scenario. For more information, see the description of each scenario.
Procedure
Create the following resources in the ApsaraMQ for MQTT console.
Resource
Example
References
Instance
post-cn-0pp12gl****
Step 1: Create an ApsaraMQ for MQTT instance and obtain the endpoint of the instance
Parent topic (level-1 topic)
room: a parent topic to which all clients in the channel subscribe.
roomSend: a parent topic that all clients in the channel use to send messages.
Subtopic
The following items describe the subtopics that are used in the sample scenarios:
Send interaction messages: /message/123456
Mute a student: /command and /p2p/GID_student@@@002. This is a typical scenario in which the P2P messaging feature is used.
Send client status notifications: /status
Send system notifications: /system
NoteYou do not need to create subtopics. For more information, see the "Terms" section of this topic.
N/A
Group ID
Teacher: GID_teacher
Students: GID_student
Rule
Data inbound rule
Data outbound rule
Rule for sending client status notifications
The following table shows the mappings between the clients of the teacher and students and the groups to which they belong.
Role
Group ID
Device ID
Client ID
Teacher
GID_teacher
001
GID_teacher@@@001
Student A
GID_student
001
GID_student@@@001
Student B
GID_student
002
GID_student@@@002
NoteYou do not need to create a device ID. For more information, see the "Terms" section of this topic.
Execute the sample code that ApsaraMQ for MQTT provides for the client and backend application to receive and send messages in different scenarios.
The following items describe the download URLs for sample code:
NoteConfigure parameters in the code based on the comments.