liveBook · Manning

Channel

As explained in Microservices Patterns, Second Edition

A communication path through which messages are sent and received.

A message channel is a communication path over which senders write messages and receivers read them. It abstracts the underlying messaging infrastructure, allowing services or application modules to communicate without putting infrastructure details in their business logic. A channel can have multiple senders and receivers. section 8.3.1

A sending port separates the sender’s business logic from a message sender adapter. At the receiver, a message handler adapter invokes a receiving port implemented by business logic. Messages carry a body and headers; a header can identify a return channel for replies. section 8.3.1 section 8.3.2

Decoupling order creation from notifications

An order module can publish an order-created event to a channel, then return a response without waiting for an email service. A notification module subscribes to the event and sends the confirmation. This separates order creation from a potentially slow or unavailable external service. section 6.2.4

Define each channel’s requirements before choosing a messaging technology:

  • Choose point-to-point or publish/subscribe according to the interaction, and specify delivery guarantees such as best-effort or at-least-once. section 8.3.3
  • Decide whether messages must be ordered and whether competing consumers are needed for concurrent processing. section 8.3.3 section 8.4
  • Specify persistence across broker crashes and durability for consumers that reconnect after messages were sent. section 8.3.3
  • Set scalability and end-to-end latency requirements, then select infrastructure that supports the resulting combination. section 8.3.3

Broker terminology does not map uniformly to channel types. For example, ActiveMQ uses queues for point-to-point channels and topics for publish/subscribe, while Kafka uses topics for both. Compare the required behavior rather than selecting solely by the broker’s name for a resource. section 8.3.3

Table 8.4 Each message broker implements the message channel concept in a different way.

Point-to-point channel

Publish-subscribe channel

ActiveMQ

Queue

Topic

Apache Kafka

Topic

Topic

RabbitMQ

Exchange + Queue

Fanout exchange and a queue per consumer

AWS Kinesis

Stream

Stream

AWS SQS

Queue

-

AWS SNS

-

Topic

Compare point-to-point and publish/subscribe mappings across messaging technologies. section 8.3.3

Command and reply channels in a saga

In an orchestrated order saga, each participant reads commands from its own channel, while the orchestrator reads replies from a reply channel. A command that requires a response specifies the reply channel; the reply indicates success or failure and can include data. One-way commands are an option when an operation returns no data and cannot fail because of business-rule violations. section 10.2.4 section 11.1.2

A channel is also part of an asynchronous API contract. An AsyncAPI document can name the channels a service uses, describe send or receive operations, and specify the message types and schemas exchanged. This supports documentation, validation and tooling without limiting the contract to events. section 8.3.5

Listing 8.3 An excerpt from an AsyncAPI document that defines a service publishing events such as CustomerCreatedEvent to the com.example.Customer channel.
channels:
  com.example.Customer:
    address: com.example.Customer
    messages:
      com.example.CustomerCreatedEvent:
        $ref: "#/components/messages/com.example.CustomerCreatedEvent"
    ...
messages:
    com.example.CustomerCreatedEvent:
      headers:
        $ref: "#/components/schemas/HeadersNotDocumented"
      payload:
        schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0
        schema:
          $ref: "#/components/schemas/com.example.CustomerCreatedEvent"
      name: com.example.CustomerCreatedEvent
      title: com.example.CustomerCreatedEvent
    ...
components:
  schemas:
   com.example.CustomerCreatedEvent:
      title: CustomerCreatedEvent
      type: object
      properties:
        id:
          type: string
      examples:
        - id: string

operations:
  io.eventuate.exampleapp.events.publisher.CustomerEventPublisherImpl:
    action: send
    channel:
      $ref: "#/channels/com.example.Customer"
    messages:
      - $ref: "#/channels/com.example.Customer/messages/com.example.CustomerCreatedEvent"

See a channel declaration linked to a customer-created event and its schema. section 8.3.5

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines channel flows, develops a requirements checklist and maps channel types to broker resources.
Examples
Illustrates order-created notifications, saga command and reply channels, and an AsyncAPI customer-event declaration.
What you can do after
Evaluate and select messaging infrastructure against channel requirements, and describe channel contracts with AsyncAPI.
How it connects
Connects channels to ports and adapters, asynchronous request/response, publish/subscribe and saga orchestration.

Also explained in

Compare how 11 books explain channel →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.