ข้ามไปยังเนื้อหา

Messaging Foundations

RabbitMQ คือ message broker: infrastructure ที่วางอยู่ตรงกลางระหว่าง service ที่ ผลิต งาน กับ service ที่ ทำ งาน เพื่อให้สองฝั่งไม่ต้องคุยกันตรง ๆ producer โยน message เข้า RabbitMQ แล้วไปทำอย่างอื่นต่อ ส่วน consumer ก็หยิบไปทำเมื่อพร้อม

การมีตัวกลางคั่นตรงนี้ — buffer ตรงกลาง — คือหัวใจทั้งหมด ทำให้ระบบรับมือกับ spike ได้, ทนต่อการที่ consumer ล่ม และ scale สองฝั่งแยกจากกันได้

บทเรียนสิ่งที่คุณจะได้เรียน
What is a message queue?ปัญหาที่ async messaging แก้ — decoupling, buffering และ resilience
RabbitMQ & AMQPRabbitMQ คืออะไร และ AMQP 0-9-1 model ที่ RabbitMQ implement
Core conceptsproducer, consumer, connection, channel, exchange, queue, binding, message
Your first queuepublish และ consume message ใน Node, Python และ Go

เกือบทุก feature ของ RabbitMQ — exchange, acknowledgement, dead-letter queue, confirm — ล้วนเป็นการต่อยอดจาก flow ง่าย ๆ อันเดียว จำภาพนี้ไว้ในหัวก่อน:

flowchart LR
  prod["Producer
(ส่งงาน)"] -->|publish| ex["Exchange
(route)"]
  ex -->|binding| q["Queue
(buffer)"]
  q -->|deliver| cons["Consumer
(ทำงาน)"]
รูปร่างของทุกระบบ RabbitMQ

producer publish ไปที่ exchange จากนั้น exchange route message ไปยัง queue หนึ่งตัวหรือหลายตัว แล้ว consumer อ่านจาก queue เหล่านั้น producer ไม่เคยรู้เลยว่าใครเป็นคน consume, เมื่อไร หรือมี consumer กี่ตัว ทุกอย่างที่ตามมาคือเรื่องของการควบคุมและทำให้ flow นี้แข็งแรงขึ้น

RabbitMQ คืออะไร ในประโยคเดียว?
ประโยชน์หลักของการวาง broker คั่นระหว่างสอง service คืออะไร?
messaging ต่างจาก call แบบ synchronous (HTTP/gRPC) อย่างไร?