Skip to content

Commit

Permalink
tw editorial fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
quetzalliwrites authored Nov 16, 2023
1 parent 602f3b8 commit 20f6c6e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pages/docs/tutorials/getting-started/request-reply.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ title: Request/reply pattern
weight: 40
---

In this tutorial, you'll learn how to implement the request/reply pattern in a AsyncAPI document using a simple pong-pong example.
In this tutorial, you'll learn how to implement the request/reply pattern in an AsyncAPI document using a straightforward pong-pong example.

Before we begin, it would be beneficial and easy to follow if you have a basic understanding of AsyncAPI and event-driven architecures. If you don't or need a refresher, you can refer to the [Event-Driven architecture](/docs/tutorials/getting-started/event-driven-architectures) document.
Before we begin, it would be beneficial for you to have a basic understanding of AsyncAPI and Event-Driven Architectures (EDA). If you need a refresher, refer to our [Event-Driven Architecture](/docs/tutorials/getting-started/event-driven-architectures) document.

[Request-reply](https://www.enterpriseintegrationpatterns.com/patterns/messaging/RequestReply.html) is a common messaging pattern where we have a component known as the **requester** that sends a request message to another component known as **replier**, which receives the request and responds to the request with a reply. So, the request/reply pattern consists of majorly two components, a requester and a replier.
[Request/reply](https://www.enterpriseintegrationpatterns.com/patterns/messaging/RequestReply.html) is a messaging pattern involving two key components: the **requester**, which sends a request message, and the **replier**, responsible for receiving this request and responding with a reply. This pattern fundamentally revolves around these two roles, requester and replier.

## Static Reply Address
## Static reply address

Here's how you can implement the request/reply pattern when the address of the response is known at the compile time or at the time of design.
Here's how you can implement the request/reply pattern when the response address is known at the compile or design time.

You can define a requester using the `send` operation that sends a message to the `ping` channel and expects a reply over the `pong` channel.
A requester can be configured with the `send` operation, where it dispatches a message to the `ping` channel and anticipates receiving a response through the `pong` channel.

In the below example, the `Operation Reply` object in the `pingRequest` operation describes the necessary information such as **where to** reply is sent. Reply goes to `pong` channel. There is no need to specify exactly what is the reply message because `pong` channel has only one message defined. In below example there is also no need to specify inside operation what message is send in the request, because `ping` channel has just one message defined.
In the below example, the `Operation Reply` object within the `pingRequest` operation provides essential details, like the destination for the reply, which is the `pong` channel. Since the `pong` channel is configured with only one message, there's no need to explicitly define the reply message. Similarly, the `ping` channel has just one message, eliminating the need to specify the message sent in the request.

<CodeBlock highlightedLines={[6,7,8,9,10,11,18,19,20,21,22,23,24]}>
{`asyncapi: 3.0.0
info:
title: Ping/pong example with static reply channel
version: 1.0.0
description: Example with a requester that initiates the request/reply pattern on a different channel than the reply is using.
description: Requester example that initiates the request/reply pattern on a different channel than the reply is using
channels:
ping:
address: /ping
Expand Down Expand Up @@ -60,20 +60,20 @@ components:
const: pong`}
</CodeBlock>

## Dynamic Reply Address
## Dynamic reply address

Sometimes, you do not know where the reply needs to be sent at the time of design or compile time. Instead the address of the reply is determined dynamically at runtime.
Occasionally, the destination for a reply cannot be predetermined during the design or compile phase. In such cases, the address for the reply is dynamically determined at runtime, allowing for more flexible and adaptive communication.

In the below example, when you don't know the address or the reply channel at the design time, you can set the `address` property to `null` or you can choose to omit `address` field entirely. You can use the `Operation Reply Address` object to define reply address using a runtime expression. You can describe that `requester` specifies where `replier` delivers reply, where is the address located, in what part of the request.
In scenarios where the address or reply channel is unknown at design time, the `address` property can either be set to `null` or omitted entirely. To define the reply address dynamically, the `Operation Reply Address` object can be used, allowing for runtime expressions. That enables the `requester` to specify where the `replier` should send the reply, detailing the address's location and its specific position within the request.

In this case, we use `$message.header#/replyTo` as the value of the `location` property which is a runtime expression and determines that reply address is located in the header of the request, under `replyTo` field.
In this situation, the `location` property is assigned the runtime expression `$message.header#/replyTo`. Such an expression indicates that the address for the reply is located within the header of the request, specifically in the `replyTo` field. This method dynamically determines the reply address based on the content of the request header.

<CodeBlock highlightedLines={[13,14,15,16,22,23,24,25,26,27,30,31,32,33,34,35]}>
{`asyncapi: 3.0.0
info:
title: Ping/pong example with reply specified as dynamic information provided in the runtime
version: 1.0.0
description: Example document for an application that accepts ping requests and responds to the address that was specified in runtime by the requestor, in the message header
description: Example document for an application that processes ping requests and replies to the address dynamically specified by the requestor in the message header
channels:
ping:
address: /ping
Expand Down Expand Up @@ -138,4 +138,4 @@ components:
location: '$message.header#/requestId'`}
</CodeBlock>

While the above examples are a simple implementation of request/reply pattern, in an protocol-agnostic world there are many different ways to represent the request/reply pattern. All of which are supported by AsyncAPI.
While the above examples are a simple implementation of the request/reply pattern, in a protocol-agnostic world there are many different ways to represent the request/reply pattern. All of which are supported by AsyncAPI.

0 comments on commit 20f6c6e

Please sign in to comment.