Module W5.4 Communication Technologies-AMQP

Communication Technologies
--- AMQP


1 / 12
next
Slide 1: Slide
New lesson editor

This lesson contains 12 slides, with text slides.

Report this lesson

Items in this lesson

Communication Technologies
--- AMQP


Module Outline

Objectives

On completing this module, you will be able to:

  • Identify the communication patterns which are suitable for a given scenario

  • Implement the communication patterns in a given scenario by using different communication technologies


Topics

  • Implementation of communication patterns

    • AMQP

Bookstore Scenario

Order

Shipping Record

5. Send the newly created order

{ order }

1. Send the order information

{cart items}

4. Send the ordering activity

Example: Microservice Interaction Diagram
– A customer places an order: Communication via HTTP & Messaging

Activity Log

Error

6. Return the created shipping record or error

4

Select the books to order and see the ordering results

Place an Order

7. Return the created order and shipping record and/or error

2. Send the order information

{cart items}

3. Return the newly created order

{ order }

3. or 6. If error from any service, send error

Producer/sender of request data

Consumer/receiver of request data

HTTP

HTTP

HTTP

Messaging

Choices of Communication Technologies

  • P1 – If a process or a user needs an immediate response, then the communication with all the relevant underlying microservices should use invocation-based, synchronous communication.

    • To make it straightforward in receiving a response and avoid the perception of no reaction or slow performance

  • P2 – If a process or a user does not need an immediate response (i.e., the process may be long-running or the user may interact at later time), then the communication with all the relevant underlying microservices should use message-based, asynchronous communication.


Order

Shipping Record

5. Send the newly created order

{ order }

1. Send the order information

{cart items}

4. Send the ordering activity

Example: Microservice Interaction Diagram
– A customer places an order: Communication via HTTP & AMQP

Activity Log

Error

6. Return the created shipping record or error

6

Select the books to order and see the ordering results

Place an Order

7. Return the created order and shipping record and/or error

2. Send the order information

{cart items}

3. Return the newly created order

{ order }

3. or 6. If error from any service, send error

Producer/sender of request data

Consumer/receiver of request data

HTTP

HTTP

HTTP

AMQP

AMQP

Scenario Diagram - Sample Communication Patterns

  • If Order creation succeeds and Shipping Record creation succeeds:

    • "Place an Order" -> "Activity Log": One-to-one, fire-forget

  • If Order creation succeeds and Shipping Record creation fails:

    • "Place an Order" -> "Activity Log": One-to-one, fire-forget

    • "Place an Order" -> "Error": One-to-one, fire-forget

  • If Order creation fails:

    • "Place an Order" -> "Activity Log" and "Error": One-to-two, fire-forget


Place an Order

Activity Log

Error

If error from any service, activate the error handler

4. Send the order activity for recording

AMQP

AMQP

Implementation: AMQP with Direct Exchange

Place an Order

Activity

Log

Error

Sender

Receiver

Receiver

AMQP Code

AMQP Code

AMQP Code

order.error

order.info

shipping.error

Error

Activity_Log

  • The queue(s) are bound to a direct exchange with specific binding key(s);

  • The receiver(s) connect to the broker and wait for messages from specific queue(s);

  • Data is passed in the form of AMQP messages;

  • When sending a message to the broker, the sender sets the routing key of the message according to the binding key of intended receiving queue(s);

  • After sending a message to the broker, the sender doesn't have to wait for a reply before doing other things;


connect & subscribe

connect & subscribe

connect & publish

Implementation: AMQP with Fanout Exchange

Place an Order

Activity

Log

Error

Sender

Receiver

Receiver

AMQP Code

AMQP Code

AMQP Code

  • The queue(s) are bound to a fanout exchange with no binding key;

  • The receiver(s) connect to the broker and wait for messages from specific queue(s);

  • Every queue bound to the exchange gets every message sent to the exchange;



Error

Activity_Log

connect & subscribe

connect & subscribe

connect & publish

Implementation: AMQP with Topic Exchange

Place an Order

Activity

Log

Error

Receiver

Receiver

AMQP Code

AMQP Code

AMQP Code

*.error

#

  • The queue(s) are bound to a topic exchange with binding key(s) or pattern(s);

  • The receiver(s) connect to the broker and wait for messages from specific queue(s);

  • A message is routed to the queue(s) whose binding key/pattern matches the routing key of the message.



Error

Activity_Log

connect & subscribe

connect & subscribe

connect & publish

Sender

Implementation: Load Balancing among AMQP Consumers

Place an Order

Error

Error

Error

Sender

  • All receivers subscribed to the same queue take turns to retrieve a message from the queue; this is a round-robin mode

  • The workload of receiving and processing data is thus (often) evenly distributed among all the receivers, which is known as load balancing, and the queue acts as a load balancer

AMQP Code

AMQP Code

AMQP Code

AMQP Code

load balancing

Receiver (instance 1)

Receiver (instance 2)

Receiver (instance …)

*.error

Error


Order

Shipping Record

5. Send the newly created order

{ order }

1. Send the order information

{cart items}

Example: Microservice Interaction Diagram
– A customer places an order: Communication via HTTP & AMQP

Activity Log

Error

6. Return the created shipping record or error

12

Place an Order

7. Return the created order and shipping record and/or error

2. Send the order information

{cart items}

3. Return the newly created order

{ order }

Producer/sender of request data

Consumer/receiver of request data

HTTP

HTTP

HTTP

4. Send the ordering activity

3. or 6. If error from any service, send error

key = *.error

key = order.*