AMQP, RabbitMQ simple explanation and great resources

AMQP, RabbitMQ simple explanation and great resources

Motivation

The need of a way for communication between modules that one module can send messages/signals to declare something, and another module receive this messages/signals and perform some actions based on that.

No alt text provided for this image


Message broker, your postman!

A message broker Is an actor that responsible for delivering messages from source to destination.

Setting Standards for generalization

As we need something that works with any technology or source or destination, there must be some sort of standards to apply so any message broker provider should follow to be acceptable.

Welcome to AMQP : Advanced Message Queuing Protocol

AMQP includes a set of standards that control the entire messaging process in AMQP message brokers. It allows two parties to communicate by sending and receiving messages between them.

AMQP components

Exchange

Exchange is the first receiver of message in AMQP and responsible for delivering the message to right queue/destination and it has 4 types:

  • Direct Exchange

No alt text provided for this image

It deliveries the message to one and only one destination based on routing key.


  • Fanout exchange

No alt text provided for this image

This exchange works like broadcasting channel that deliver the message to all associated queues.



  • Topic Exchange

No alt text provided for this image

Topic exchanges route messages to queues based on wildcard matches between the routing key and the routing pattern, which is specified by the queue binding. Messages are routed to one or many queues based on a matching between a message routing key and this pattern.

  • Header Exchange

No alt text provided for this image

This exchange deliver messages based on header values on messages.



Binding and Routing key

Binding is the connection that wires the exchange with the queue, As any queue must be bounded to exchange using a binding and routing key just a name to distinguishes between bindings.

No alt text provided for this image

Queue

No alt text provided for this image

Queue is the real holder of the messages that source sends and the messages still in queue till one consumer exists then the message broker push message to the consumer and uses FIFO mechanism in working.

Connection and Channel

Message broker is a server and any application want to use it should establish a connection between him and server, Channel is virtual connection to reuse the real connection instead of dropping and re-creating the connection.

AMQP component interaction

No alt text provided for this image

RabbitMQ , implementation of AMQP

RMQ is message broker server that implements AMQP standards so it works exactly same as explained previously.

No alt text provided for this image

As we know, Nothing is perfect !

pros

  • Modules Decoupling

By adding message broker as a way communication your modules became independent from each other one module declare the message/event and any other module can consume this and perform the action and any part of this cycle can be replaceable any time

  • Reliability

RMQ provides acknowledgment facility which that any module consume message should acknowledge that it processed successfully if not the message will return to the queue again to another processing.

Note: you have to pay attention to this as RMQ will try to push failed messages again and again till it processed , so you have you have to add try/catch block to consumer code or add dead-letter extension so that any failed message could be delivered to another queue for investigation and another way of handle

  • Durable

messages can be stored on disk for avoid any data loss during any server shutdown or failure

  • Scalability

You can scale your message broker by adding resources or server instances.

  • Multi-thread consuming

In case of hot you can multi process messages by enable multi thread consuming feature

Cons

  • A lot of components

There is a lot components regarding to this protocol which makes it somehow complex to understand or use.

  • Push Model

RMQ server pushes messages to consumers, Whenever there is a consumer send the message to it, in case of huge amount of message consumer could crash if it can not handle this number of messages.


Resources


要查看或添加评论,请登录

Sameh Muhammed的更多文章

  • The Idea Behind Quarkus

    The Idea Behind Quarkus

    Introduction If you are a Java developer and using a Spring Boot framework, you can see that a lot of videos and…

    2 条评论
  • Legacy Code: I can't get this class into test suite

    Legacy Code: I can't get this class into test suite

    ??????? ?? ?????? ???? ??? ??????? ?? ???????? ?????? ???? ???? ???????? ????? ????? feature ????? ?? ?????? ?????? ???…

  • Legacy Code: How do I add a feature

    Legacy Code: How do I add a feature

    ??????? ?? ?????? ?????? ??????? ?? ????? ??? ????????? ??? ????? ????? ??? ???????? ???? ??????? ?? ??? ???? ????? ???…

  • Legacy Code: I don't have much time and I need the change quickly

    Legacy Code: I don't have much time and I need the change quickly

    ??????? ??????? ?? ?????? ???? ??? ?? ?? Seam ??? ??? ???? ?? ?? ??????? ?? ?? legacy code ?? ?? unit tests. ?????? ???…

    4 条评论
  • Legacy Code: The Seam & Feedback Loop

    Legacy Code: The Seam & Feedback Loop

    ??????? ?? ??????? ??????? ??????? ?? ????? ??????? ?? ?????? ??? ?????? ????????? ???? ???? ???? ??? ?????? ??? ??????…

  • Legacy Code: Mechanics of change

    Legacy Code: Mechanics of change

    ??????? ?? ???? ??? ????? ????? ????? ????? ?? ??? ???????? ???? ??????? ?? ???? ????? ???? ????? ?? ?????? ??? ?? ????…

    1 条评论
  • Service Design Best Practices - Part II

    Service Design Best Practices - Part II

    Introduction By now most softwares separating the server side logic from user interface logic by developing a back end…

  • Service Design Best Practices - Part I

    Service Design Best Practices - Part I

    Introduction By now most softwares separating the server side logic from user interface logic by developing a back end…

  • ????? ????? : ????? ??????? ?????? ????

    ????? ????? : ????? ??????? ?????? ????

    ??????? ?? ????? ???? ??? ??? ??????? ??? ????? ??????? ????????? ?? ????? ??? ??? ?? ??????? ???? ?? ???? ???? ???…

  • Object-Oriented Programming : comprehensive guide

    Object-Oriented Programming : comprehensive guide

    Motivation It's very common to be asked about OOP concepts while you are still fresh graduate or junior developer, but…

社区洞察

其他会员也浏览了