In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what is the difference between RabbitMQ and Redis about MQ comparison. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Message queue selection: RabbitMQ & Redis
RabbitMQ
RabbitMQ is an open source implementation of AMQP (Advanced Message Queue) developed by erlang. RabbitMQ is a message broker that receives messages from "producers" and delivers them to "consumers", during which messages can be routed, cached, and persisted according to rules. " The "producer" is the sender of message hereinafter referred to as P, and the corresponding "consumer" is the message receiver. CMagi message exists in the RabbitMQ from P to C Magi queue through queue. It can store as many message as possible, multiple P can send message to the same queue, and multiple C can receive message from the same queue.
RabbitMQ architecture:
Components:
Message (message): binary objects forwarded by RabbitMQ, including Headers (header), Properties (attribute), and Data (data), in which the data part is not necessary
Producer (producer): the producer of messages, applications responsible for generating messages and sending messages to switch Exhange: Consumer (consumers): applications that use queue Queue to get messages from Exchange
Exchange (switch): responsible for receiving a message from the producer and transferring it to the appropriate queue
Queue (queue): a buffer that stores messages sent by Exchange and actively sends messages to Consumer, or Consumer actively to get messages.
Binding (binding): the relationship between the queue and the switch. Exchange forwards messages based on the properties of the message and the properties of the Binding. An important attribute of the binding is binding_key.
Connection (connection) and Channel (channel): producers and consumers need to establish a TCP connection with RabbitMQ. Some applications require multiple connection, and to save TCP connections, you can use Channel, which can be considered a lightweight connection that shares TCP connections. The connection requires user authentication and supports TLS (SSL). The connection needs to be explicitly closed.
Redis
Redis is completely open source and free, complies with the BSD protocol, and is a high-performance key-value database.
Redis and other key-value cache products have the following three features:
Redis supports data persistence. You can save the data in memory on disk and load it again when you restart it.
Redis not only supports simple key-value type data, but also provides storage of data structures such as list,set,zset,hash.
Redis supports data backup, that is, data backup in master-slave mode.
Redis advantage
Extremely high performance-Redis can read at a speed of 110000 times per second and write at a speed of 81000 times per second.
Rich data types-Redis supports Strings, Lists, Hashes, Sets and Ordered Sets data type operations for binary cases.
Atom-all operations of Redis are atomic, meaning either successful execution or failure to execute at all. A single operation is atomic. Multiple operations also support transactions, that is, atomicity, wrapped by MULTI and EXEC instructions.
Rich features-Redis also supports publish/subscribe, notification, key expiration, and so on.
First of all, Redis is designed for caching, but because of its own characteristics, it can be used as a message queue (Redis's List data structure is more suitable for MQ). It has several blocking API available, and it is these blocking API that give him the ability to do message queues. In addition, other features of message queuing, such as FIFO, are also easy to implement, with only a list object fetching data from the header and stuffing the data from the tail. Redis can do message queuing thanks to its list object blpop brpop interface and some interfaces to Pub/Sub (publish / subscribe). They are all blocking versions, so they can be used as message queues.
A simple comparison between RabbitMQ and Redis
Both RabbitMQ and Redis can be queues, but there are differences between them. For example, in the message queue of Redis, if the worker processing fails when you pop out of the queue, the data will not be returned to the queue, and you need to manually push the failed processing data from the business to the queue; while RabbitMQ can automatically handle the failed worker so that the data is not lost; RabbitMQ can also ensure that the data is persisted during transmission, and the data in the channel and queue can be set to persistent. First of all, Redis is not strictly a message queue, it is an in-memory database, but because some of its features are suitable for acting as a queue, it is also mostly used to do simple mq. The father of Redis has developed a real message queue disque, which you can take a look at if you are interested.
Compared with Redis,RabbitMQ, there is a more sophisticated MQ mechanism. Here we only discuss the durable (persistence) of messages, and a series of other mechanisms have time to communicate.
RabbitMQ has a message acknowledgement mechanism to ensure that messages are not lost: after the client fetches the message from the queue, it may take some time to process it. If, in the process, the client makes a mistake and exits abnormally, and the data is not yet processed, then unfortunately, this data is lost, because RabbitMQ marks the message as completed by default and then removes it from the queue. Message acknowledgement is when the client fetches the message from the RabbitMQ and the processing is completed, it sends an ack to tell the RabbitMQ that the message processing is complete, when the RabbitMQ receives the request from the client to obtain the message, or marks it as being processed, and when the ack is received again, it will be marked as completed and then deleted from the queue. When RabbitMQ detects that the client is disconnected from itself and has not received the ack, it will put the message back in the message queue and give it to the next client for processing to ensure that the message is not lost. In other words, RabbitMQ gives the client enough time to process the data.
Producers, consumers, producers of RabbitMQ demo
Consumer (does not send ack, simulator interrupts)
No-ack = False, if the consumer fails in a situation (its channel is closed, connection is closed, or TCP connection is lost), RabbitMQ will re-add the task to the queue.
Consumers who send ack normally:
Sending ack is considered to be the consumer that normally consumes message, then RabbitMQ removes the message from the queue. At this point, there are no messages in the queue.
For other features of RabbitMQ, such as Publish/Subscribe, Routing, Topics and RPC, you can Google if you are interested. In addition to RabbitMQ in addition to the practice of Python, you can also consider the practice of other languages, here is another choice of language golang, you can refer to the best practices of Ubuntu14.04+RabbitMQ3.6.3+Golang, this article is very detailed, practical significance is of reference value, if you are interested, you can read it.
This is the end of the article on "what is the difference between RabbitMQ and Redis in MQ comparison". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.