Message queue
lastmod 2023-08-01created 2016-04-267 edits
A message queue is a queue that converts commands the user issues with the keyboard or mouse into messages and stores them. In the Windows operating system, a message queue exists for every thread. When the user sends some command to a window, the program (or window) reads the message from that queue and handles it. For example, when you move the mouse, a message saying the mouse was moved (WM_MOUSEMOVE) is stored in the message queue, and the program handles it accordingly. In other words, the message queue makes the program (or window) convert and carry out the actions the user has taken.
Kafka vs RabbitMQ vs Redis
| RabbitMQ | Kafka | Redis Pub/Sub | |
| Event storage in Queue | Once a message is judged to have been delivered successfully, it is deleted from the queue, so reprocessing is difficult | Events are not deleted but stored in a stream, so durability is guaranteed and reprocessing is possible. Not stored. Even worse, if no subscriber of the channel exists when an event arrives at the channel, the event disappears | |
| Protocol | Supports several messaging platforms such as AMQP, MQTT, and STOMP. | Uses a TCP-based custom protocol with simple message headers, so it is hard to replace. | RESP (Redis Serialization Protocol) - TCP communication |
| Routing | Provides Direct, Fanout, Topic, and Headers routing options, allowing flexible routing. | Routing is not supported as a built-in feature. Dynamic routing can be implemented with Kafka Streams. | |
| Priority | Supports priority queues, so messages can be processed by priority. | An immutable sequence queue that guarantees time order within a single partition. However, time order is not guaranteed when multiple partitions are processed in parallel | Far from handling priority, it cannot even guarantee that an event will arrive |
| Pros |
|
|
|
| Cons | Slower than Kafka | Does not provide the many features offered by general-purpose messaging systems | Cannot guarantee event arrival |
- Use kafka when you need large-scale data processing, real-time, high performance, or high availability, or when you need to trace logs and reprocess based on stored events
- Use RabbitMQ when you need to handle complex routing flexibly, when using an Application that needs precise request-response, or when traffic is small but you need long-running, reliable background jobs.
- If event data is stored in a DB so there is no need to store events in middleware, and only sending pushes like notifications matters, without guaranteeing that the notification must reach the consumer, use Redis, which is easy to maintain