Command (Request) Message

Introduction

  • Command-type messages intend to ask the receiver to perform some action like CREATE_ORDER or GET_ORDER.

  • Its body should contain all the necessary information which is required by the receiver to perform the task like an HTTP request.

Types of Command

  • Write
    • it changes the state of the receiver. like CREATE_ORDER
  • Query (Read)
    • it is used to get some data from the receiver. like GET_ORDER.

Usage

  • Used in fire and forget type of communication specially the write command.

  • Additionally, it can be an alternative to synchronous HTTP request-response where the command message is a request and the document message is a response.

  • Used in orchestration-based saga.

Command Or Request?

Q: which name makes more sense?

  • Message names like CREATE_ORDER sound like a command.

  • But when we add the sender and receiver into the picture and also include the fact that the receiver can refuse to create an order based on its logic it immediately sounds like a request.

  • I like to see it from the sender’s point of view.

  • I prefer the term Command in fire and forget type of communication. since the sender assumes that the receiver will perform the intended action and hence does not expect a response.

  • And I use the term Request in request and response type of communication. since the sender is aware of the fact that the receiver can reject the request and hence expect a response (Ack).