This is the 27th day of my participation in Gwen Challenge

Why use messaging middleware?

The great advantage of MQ is decoupling and peak clipping.

Decoupling: Mainly solve the problem of coupling between the system, such as ABC now have A system, A userid is created that needs to be passed on to B (SMS), the need to increase interface to solve in system B, the system C also need this userid, and to increase the interface, the system coupling between high, not their separation, the mechanism through the message consumption, Placing the UserID in the message information, with other systems as consumers, allows systems to be independent of each other.

Peak clipping: mainly to solve the high concurrency million requests will be broken server

For example, at the time of a hot request, the number of requests reaches the peak value. If the request is made directly through the interface, it will fall to the server, and the pressure will explode. With message queuing, requests are queued first and processed by 2000 at a time so that the server does not get crushed.

Asynchronous: The result of decoupling is very similar, asynchronous is that each upstream and downstream systems can manage their own logical processing, do not need to wait for the results of other systems back. For example, in system ABC, A needs to send userID to B, and as long as it sends A message, it can return the result to tell the user that it is successful. System B then consumes the message to obtain the logic of the userID processing. A does not need to wait for THE completion of B’s processing before sending back to the user, which can not only respond quickly, but also reduce the request time.

But MQ also has disadvantages, such as consistency problems. After A gives userID to B, A returns success to the user, but system B fails to write userID.

rocketmq

RocketMQ is an open source product from Alibaba. It is especially suitable for use in the Internet e-commerce industry, widely used in orders, transactions, recharge and other businesses, and plays a very big role in peak traffic clipping when high concurrent requests are made.

Advantages:

Single-machine throughput: 100,000 levels

Availability: Very high, distributed architecture

Message reliability: Zero message loss can be achieved after optimized parameter configuration.

kafka

Ultra high performance, with throughput of millions of TPS, is the darling of the field of big data, in the process of data collection, transmission, storage plays a pivotal role, and is widely used in the field of big data message transmission.

Timeliness: Ms class

Availability: Very high, Kafka is distributed, multiple copies of a single data, few machines go down, no data loss, no unavailability

Orderly message consumption ensures that all messages are consumed only once.

rabbitmq

As one of the current mainstream message middleware, it is an open source framework that implements advanced Message Queue Protocol (AMQP).

Support a variety of APIS, languages, ease of use, and integration of a variety of cluster construction modes, is the first choice of many small and medium-sized enterprises.

Throughput to ten thousand levels, MQ function is relatively complete.

Good performance, high concurrency.

As mentioned above, message consumption is ordered. How do you ensure that messages are ordered?

1. An algorithm that places messages in the same order (partition in Kafka, queue in rabbitMq). The queue is then consumed by only one consumer.

2. This can be done by adding a global ordered identity to the message body.

Like message middleware, many companies will use it now. If you have experience in using it, it will be more helpful to enter big factories.

RocketMQ practice

rocket-mq-config.xml

<! --test--> <bean id="testProcessor"

    class="com.test.processor.testProcessor">

   <property name="testmqConfig">

​        <list>

​            <bean class="com.test.dto.MqConfigDTO">

​                <property name="topic" value="testTopic"/>

​                <property name="tag" value="testTag"/>

​                <property name="className"

​                          value="com.test.producer.TestDTO"/>

​            </bean>

​        </list>

​    </property>

</bean>
Copy the code
<! -- Inject RocketMQ producer --> <bean id="DemoProducer" class="com.test.producer.DemoProducer" init-method="tin"


​    <property name="groupId" value="testGroupID"/>

​    <property name="env" value="dev"/>

​    <property name="acsKey" value="xxxxx"/>

​    <property name="srtKey" value="xxxxx"/>

​    <property name="Addr" value="xxxx"/>

</bean>
Copy the code