Asynchronous message-based communication pattern

Asynchronous message-based communication pattern

When the message-based communication between the micro-services using asynchronous exchange of messages is accomplished. Usually the message broker mechanism for message-based applications, it acts as an intermediary between the service.

News

Message from the message header and a message body composition.

  • The head includes: a set of (metadata of the data being transmitted is described) + the names and values ​​of other data (e.g., a unique message ID, optional return address).
  • The body comprising: transmitting data in text or binary format.

The type of message

  1. Documentation: contains only generic message data. Recipients decide how to interpret it. Reply to the imperative message is a message usage scenario document.
  2. Command: equivalent to an RPC request message. It specifies its operating parameters to be invoked.
  3. Event: Indicates important event took place this side of the sender. Events are usually field event, it represents the state of the object field of rectification.

Message channel - communication mechanism services

Messages are exchanged via message channel.
Any number of the sender can send a message to the channel, any number of the recipient may receive a message from the channel.

Here Insert Picture Description

Type of message channels

  1. Point Tunneling: pass it to a consumer is reading messages from the channel, and only that a consumer can consume the message, the message is not real-time, can be persistent. Type command message, typically through point channel.
  2. Publish - subscribe to channels: A message will be sent to all recipients subscribed, all online just received this message can receive real-time news, not persistent. Event-based messages are usually posted by - sending a subscription channel.

Message-based interactive way

1. The request / response and asynchronous request / response

The client and server to interact asynchronous request / response mode by exchanging one pair of messages.

Here Insert Picture Description

The client sends a command reply message having the formula channel head. Write reply message server reply channel, the reply message comprising the correlation ID and the message identifier has the same worth. The client uses the correlation ID reply message to match the request.

2. The one-way notification

Client message (usually command type message) sent to the server owned point channel. Subscribe to the channel and server processes the message, but the server will not send back a reply.

3. Publish / Subscribe

Message to the client Post published read by the plurality of receiver / subscription channel. Server for event-specific domain objects of interest only need to subscribe to the appropriate channel.

4. Publish / asynchronous response

Post / asynchronous response by the publish / subscribe, and request / response element binding ways maybe implemented together.
Client issues a message, reply channel designated in the header of the message, the channel is also a publication - subscription channel. Consumers reply message including the correlation ID is written reply channel. Collecting responses to the client by using a correlation ID, reply message in order to match the request.

Published 32 original articles · won praise 13 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_43519048/article/details/104483155