The essential audio and video WebRTC real-time interactive live broadcast technology entry and actual combat in the 5G era

download: A must-have audio and video WebRTC real-time interactive live broadcast technology entry and actual combat in the 5G era

In the 5G era, the audio and video industry will experience unprecedented vigorous development, and audio and video talents will become the new darling. This course will systematically explain WebRTC real-time interactive live broadcast technology [core technology in the audio and video field] from introductory to actual combat, allowing you to enter the audio and video industry with a low threshold, and quickly become an audio and video engineer urgently needed by enterprises. Let you have a very in-depth grasp of the use of the entire WebRTC technology, and have the ability to implement a one-to-one audio and video real-time interactive live broadcast system, and can be interconnected with other terminals. These capabilities are exactly what companies urgently need today. What are you waiting for, hurry up and learn!

Suitable for the crowd
Web front-end, Android, iOS, Windows, Mac front-end development engineers are
interested in audio and video technology

Technical reserve requires
understanding of JS programming syntax;
understanding of
simple examples of development tools such as AndroidStudio, Xcode, etc.
Foreword
In today's microservices are blooming , the application of audio queues is particularly common, but before that, my understanding of message queues only stays at what and I have no knowledge of what it can do. I have not used any audio queues, nor have any knowledge of its practical applications. However, from the current state of the market, audio queues used to be one of the central components that must be controlled for web back-end development. One, so I will use my free time to understand. Today we are sharing rocketMQ, which is also a component of Alibaba's open source. In 2016, Alibaba donated it to the Apache Open Source Foundation, which is currently the top project of the foundation. one.

Text
before the beginning of the text, let's look at some of the learning audio queue.

What is an audio queue?
Simply speaking, an audio queue is similar to a container for storing audio. The audio consumer puts the audio into the audio queue, and the consumer takes out the audio from the audio queue to stop consumption (for example, write an order). The audio queue is an important component in the distributed system. The use of the audio queue is mainly to improve system performance and peak clipping and reduce system coupling through asynchronous processing. Currently, the most widely used audio queues are ActiveMQ, RabbitMQ, Kafka, RocketMQ.

Why is the demand for audio queues to
cut peaks and
fill valleys and reduce the instantaneous peak concurrency of the system? With the development of Internet business requirements from time to time, traditional architectures used to be unable to meet the needs, especially in the current e-commerce business development. In order to deal with this kind of concurrency of millions, tens of millions, or even hundreds of millions, the characteristic of this form of concurrency is that the amount of concurrency is concentrated in a certain period of time, such as double eleven, double twelve, or promotion or discount days. The concurrency at other times is a very one-half of the peak concurrency, or even one percent. If the system architecture is designed according to the peak concurrency, not only the initial investment will cost a lot of money, but also the daily operation and maintenance will also burn money. In order to balance the amount of concurrency under these two conditions and reduce the cost of system establishment, system components such as audio queues came into being.

Simply put, the audio queue is a system component that equalizes the concurrency of the system, and its main function is to cut peaks and fill valleys. We assume that the red in this picture indicates the concurrent sequence diagram of the system that does not participate in the audio queue component (the diagram here is drawn at random, just to clarify the problem), and the blue indicates that the audio queue component is participated in the architecture:

![]()

After comparison, we will find that we find that the introduction of the audio queue component reduces the peak concurrency of the order system, which is equivalent to handling a part of the business requested by the peak and putting the system under pressure to deal with it. Of course, we will order in the course of practice. The single system continues to dispose of the order information in the audio queue in a disorderly manner until all the order processing is completed. Of course, it is mainly aimed at some services that have low real-time requests but a large amount of concurrency, such as ticket purchases, rush orders, and other services that allow the processing results to be pushed later.

Reduce the coupling between the systems and improve the user experience.
Let’s imagine an application scenario. We want to make a ticket purchase system. After the ticket purchase is successful, the user will be notified of the ticket purchase result by SMS. If the serial method (that is, the same pace is used) ), our calling method is like this: after the user submits the ticket purchase order, the order system accepts the ticket purchase order and calls the SMS system to send the ticket purchase result. Here we put a picture, everyone is more clear:

![]()

The response time of the system under the serial architecture is 150ms + 150ms, and the requirement is 300ms. From the perspective of business process, the ticket purchase result is sent after the order is accepted. There is no problem, but if the SMS system is down for a certain period of time , SMS service is unavailable, and ticket purchase SMS cannot be sent. The final result is that users cannot place orders, which not only affects the user experience, but also affects the company's business benefits.

And if you further analyze this business process, you will find that whether the SMS can be sent has nothing to do with the operation of the user submitting the order. What the user needs to know is whether the order can be processed successfully, as for sending the SMS that the ticket purchase is the result. , For the entire business, the concurrent center business, even if the SMS fails to send, it should not affect the ticket purchase business.

Therefore, our more reasonable business disposal method is to directly return the acceptance result to the user after the order system accepts the victory. As for the order disposal result, it can be generated after the entire business is completed, and then the order system sends the order to the SMS system. For the audio of the processing result, the SMS system will send the user the result of the ticket after receiving the audio. The container where we store the audio is the audio queue. At this time, our system structure is like this:

![]()

In the above architecture, our SMS sending business is asynchronous, which can not only reduce the waiting time of users, but also improve the response efficiency of the service. If the processing time of the SMS system is omitted, the final business response time will be reduced to 150ms , And the coupling of the system under this architecture is lower. For example, if the business requirements change in the future, not only need to send short messages to the user, but also push the results to the WeChat official account. The business takes 100ms, and even the results need to be emailed It takes 150ms for the service to be sent to the user in the form of the first architecture. If it is the first architecture, the response time that the user has to wait is 150ms + 150ms + 100ms + 150ms, but for the second architecture, the user's response time is always 150ms :

Click on the address in the above picture, the address in the red box is the recommended domestic mirror address, and the download is faster

The device
decompresses the downloaded zip file

Windows
can directly compress the software and decompress it

linux

unzip rocketmq-all-4.8.0-source-release.zip
cd rocketmq-all-
4.8.0 / mvn -Prelease-all -DskipTests clean install -U
cd distribution/target/rocketmq-4.8.0/rocketmq-4.8.0
Setting environment variables
. Windows needs to be set here, but Linux is not required. Of course, I have not tested it in the Linux environment. Interested little companions will experiment by themselves. Add the following environment variables in windows:

ROCKETMQ_HOME="D:\workspace\tools\rocketmq-all-4.8.0-bin-release"
NAMESRV_ADDR="localhost:9876"
![]()

![image-20210310230651594]()

Or set it in the powershell window before startup. This is for the time being. You have to set it every time. It is too troublesome to set the eternal one directly:

Env $: ROCKETMQ_HOME = "D: \ Workspace \ Tools \ rocketmq-All-bin-4.8.0-Release"
$ Env: NAMESRV_ADDR = "localhost: 9876"
to start
start Name service
linux

nohup sh bin/mqnamesrv &
tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...
windows

Open the powershell, if the environment variable is not set, you need to perform the following operations first, and stop the environment variable setting

$Env:ROCKETMQ_HOME="D:\workspace\tools\rocketmq-all-4.8.0-bin-release"
$Env:NAMESRV_ADDR="localhost:9876"
Then enter the rocketMQ device directory and perform the following operations

cd D:\workspace\tools\rocketmq-all-4.8.0-bin-release
.\bin\mqnamesrv.cmd
![]()

![]()

Start proxy service
Linux

nohup sh bin/mqbroker -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log
The broker[%s, 172.30.30.233:10911] boot success...
windows

Like starting the Name service above, perform the operation of setting the environment variables in the first two lines without setting the environment requirements

$Env:ROCKETMQ_HOME="D:\workspace\tools\rocketmq-all-4.8.0-bin-release"
$Env:NAMESRV_ADDR="localhost:9876"
Then perform the startup operation

cd D:\workspace\tools\rocketmq-all-4.8.0-bin-release
.\bin\mqbroker.cmd -n localhost:9876 autoCreateTopicEnable=true
Before operation, be sure to enter the rocketMQ device directory, otherwise the following red error will be returned

![]()

Accept & Send Audio
Send Audio
Linux

export NAMESRV_ADDR=localhost:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...
windows

Similarly, if you haven’t set the environment variable, remember to set it first. If it’s too much trouble, just set the eternal environment variable directly, refer to the setting of environment variable.

cd D:\workspace\tools\rocketmq-all-4.8.0-bin-release
.\bin\tools.cmd org.apache.rocketmq.example.quickstart.Producer After
executing the command, you will see us send to the audio queue A lot of audio

![]()

Adopt audio
Linux

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...
windows

Similarly, if you haven’t set the environment variable, remember to set it first

cd D:\workspace\tools\rocketmq-all-4.8.0-bin-release
.\bin\tools.cmd org.apache.rocketmq.example.quickstart.Consumer After
executing the above command, you can see that the console is accepted Audio sent

![]()

Java simple demo The demos
here can be seen on the official website, and they are all very simple. I will stop to explain if I need to add clarification. Before starting the project, first introduce the following dependencies:

org.apache.rocketmq
rocketmq-client
4.3.0

發送同步音訊
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
/**

  • @program: rocketmq-demo
  • @description: Send synchronous audio
  • @author: syske
  • @create: 2021-03-09 20:24
    /
    public class SyncProducer {
    public static void main(String[] args) throws Exception {
    // Instantiate audio consumer Producer
    DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
    // Set the address of the NameServer
    producer.setNamesrvAddr("localhost:9876");
    // Start the Producer instance
    producer.start();
    for (int i = 0; i <100; i++) {
    // Create audio and specify Topic, Tag And the audio body
    Message msg = new Message("TopicTest" /
    Topic /,
    "TagA" /
    Tag /,
    ("Hello RocketMQ "+ i).getBytes(RemotingHelper.DEFAULT_CHARSET) /
    Message body */
    );
    // Send audio to A broker
    SendResult sendResult = producer.send(msg);
    // After sendResult returns whether the audio can be delivered successfully
    System.out.printf("%s%n", sendResult);
    }
    // If the audio is no longer sent, close the Producer instance.
    producer.shutdown();
    }
    }
    send asynchronous audio
    import org.apache.rocketmq.client.producer.DefaultMQProducer;
    import org.apache.rocketmq.client.producer.SendCallback;
    import org.apache.rocketmq.client.producer.SendResult;
    import org.apache.rocketmq.common.CountDownLatch2;
    import org.apache.rocketmq.common.message.Message;
    import org.apache.rocketmq.remoting.common.RemotingHelper;
    import java.util.concurrent.TimeUnit;
    /**
  • @program: rocketmq-demo
  • @description: Asynchronous audio consumer
  • @author: syske
  • @create: 2021-03-09 20:28
    */
    public class AsyncProducer {
    public static void main(String[] args) throws Exception {
    // Instantiate audio consumer Producer
    DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
    / / Set the address of the NameServer
    producer.setNamesrvAddr("localhost:9876");
    // start the Producer instance
    producer.start();
    producer.setRetryTimesWhenSendAsyncFailed(0);
    int messageCount = 100;
    // instantiate a countdown calculator
    final based on the number of messages CountDownLatch2 countDownLatch = new CountDownLatch2(messageCount);
    for (int i = 0; i <messageCount; i++) {
    final int index = i;
    // Create audio, and specify Topic, Tag and audio body
    Message msg = new Message("TopicTest ",
    "TagA",
    "OrderID188",
    "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
    // SendCallback accepts asynchronous return result callback
    producer.send(msg, new SendCallback() { br/>@Override
    public void onSuccess(SendResult sendResult) {
    System.out.printf("%-10d OK %s %n", index,
    br/>sendResult.getMsgId());
    }
    @Override
    public void onException(Throwable e) {
    System.out.printf("%-10d Exception %s %n", index, e);
    e.printStackTrace();
    }
    });
    }
    // Wait for 5s
    countDownLatch.await(5, TimeUnit.SECONDS);
    // If no more audio is sent, close the Producer instance.
    producer.shutdown();
    }
    } To
    send one-way audio
    One-way audio is audio without return value

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
/**

![]()

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**

Guess you like

Origin blog.51cto.com/15101022/2661057
Recommended