Laravel asynchronous queue, choose redis or redis?

Time:2020-2-26

The original is https://www.jianshu.com/p/16c9227076c

Today, I hesitated about the choice of asynchronous queue.

RabbitMQ

Rabbitmq is a kind of message middleware to realize AMQP (Advanced message queuing protocol). It originated from financial system and used to store and forward messages in distributed system. It has good performance in ease of use, scalability, high availability, etc. Message middleware is mainly used to decouple components. The sender of message does not need to know the existence of message consumer, and vice versa.

Redis

It is a key value NoSQL database, which is very active in development and maintenance. Although it is a key value database storage system, it supports MQ function, so it can be used as a lightweight queue service.

Because rabbitmq has a natural publish and subscribe mode, but also provides other modes. Of course, you can also use rabbitmq to do thisGRPC。 But redis doesn’t have this. It needs to be implemented by itself. In other words, when consumer consumption fails, the message body is lost and needs to be handled manually.

Persistence

Redis: persist the entire redis instance to disk
Rabbitmq: queue, message, you can choose whether to persist or not

After these features, we can get an application scenario

Redis: lightweight, high concurrency, delay sensitive
Real time data analysis, seckill counter, cache, etc

Rabbitmq: heavyweight, high concurrency, asynchronous
Asynchronous processing of batch data, serialization of parallel tasks, load balancing of high load tasks, etc

For example, sending mailbox asynchronously, user behavior of browser, and other non main tasks, and sending socket messages asynchronously can all be handled by rabbitmq message queue. If it’s the main business process, consider using redis, which has high performance.

Rabbitmq + PHP tutorial 1 Hello World
This is a simple article, unused students can try to install first, you can have no business support at that time, no use.

Now there is business support, usinglaravel-queue-rabbitmqFor this extension package, please refer to the following article.

Laravel5.6 integrate rabbitmq message queue

Be careful:
Functionphp artisan queue:work rabbitmqAfter that, it runs in cli, so every time you modify the code, please make sure to run ‘PHP artican queue: work rabbitmq’ again
`
Other questions

How does rabbitmq run?

If you are not a java student, you may be in trouble
We can borrow docker, we userabbitmq:management, the default passwords areguest
Running a two-step curve

docker pull rabbitmq:management

docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq rabbitmq:management

The browser can then use theIP:15672VisitrabbitmqBackstage.

If your main program runs in dockerphpPlease fill in the IP address of your machine, for example192.168.1.1Instead of127.0.0.1