Step 5: Try a Request-Reply Message Exchange Pattern
You've now completed Step 4: Try a Publish-Subscribe / Fan-Out Message Exchange Pattern.
In step 5, you'll expand your EDA by setting up a request-reply message exchange.
With request-reply messaging, applications achieve two-way communication using separate point-to-point channels: one for requests, and another for replies. In a request-reply pattern, the applications are both producers and consumers.
In the Solly's Coffee OMS we introduced in step 3, a Third-Party App sends a new order event as a request to the Order Management application whenever a user places an order. Upon receiving the request, the Order Management application replies with the order-id
in the response. This interaction uses a request-reply message exchange, ensuring that the order confirmation is received synchronously.
Set Up a Request-Reply Message Exchange
In this exercise we'll set up two applications, Order Management and Third-Party App. After you complete these steps you'll have a message exchange pattern like the following animation:
To set up a request-reply message exchange, perform these steps:
- Open two command-line terminal windows, one for each application.
- In terminal 1, set up the Order Management application with a subscription to the topic,
coffeeshop/order/details/v1/*/ca/>
that replies to requests with a payload containing a status and orderId.{ status: 'Accepted', orderID: '12738' }
. Enter the following command: - In terminal 2, set up the Third-Party App to send a request message with the topic,
coffeeshop/order/new/v1/mobile/ca/437/4334
. The application waits for a default time of 10 seconds to receive a reply before generating a time-out error. - Press Control+C (on Windows and Linux) or Command+C (on Mac), to stop the applications.
stm reply --topic "coffeeshop/order/new/v1/*/ca/>" --client-name "Order Management" --message "{status: 'Accepted', orderId: '12738'}"
You should see the following result:
ℹ info info: loading 'reply' command from configuration 'stm-cli-config.json' … waiting connecting to broker [ws://localhost:8008, vpn: default, username: default, password: ******] ℹ info info: client name: Order Management ✔ success success: === Order Management successfully connected and ready to subscribe to request topic. === ℹ info info: subscribing to coffeeshop/order/new/v1/*/ca/> ℹ info info: press Ctrl-C to exit ✔ success success: successfully subscribed to request topic: coffeeshop/order/new/v1/*/ca/> … waiting === ready to receive requests. ===
stm request --topic "coffeeshop/order/new/v1/mobile/ca/437/4334" --client-name "Third Party App" --file order.json
You should see the following result:
ℹ info info: loading 'request' command from configuration 'stm-cli-config.json' … waiting connecting to broker [ws://localhost:8008, vpn: default, username: default, password: ******] ℹ info info: client name: Third Party App ✔ success success: === Third Party App successfully connected and ready to send requests. === … waiting requesting... ✔ success success: request sent on topic coffeeshop/order/new/v1/mobile/ca/437/4334 ℹ info info: Message Properties Destination: [Topic coffeeshop/order/new/v1/mobile/ca/437/4334] Class Of Service: COS1 DeliveryMode: DIRECT ℹ info info: Message Payload (bytes): 659 ✔ success success: reply Received - [Topic coffeeshop/order/new/v1/mobile/ca/437/4334], type - TEXT ℹ info info: Message Properties Destination: [Topic #P2P/v:solbroker/mPuoLl8m/3rd Party App/_] CorrelationId: #REQ1 Class Of Service: COS1 DeliveryMode: DIRECT Reply Message Binary Attachment: len=41 ℹ info info: Message Payload (bytes): 38 ✔ success success: disconnecting from Solace PubSub+ Event Broker... ✔ success success: disconnected. ✔ success success: exiting...
Third Party App sends a request message to Order Management with a new order. Order Management replies to the request with a message of { status: 'Accepted', orderID: '12738' }
.
Tutorial Steps
You've completed the fifth step in the tutorial. Click Next Steps for suggestions to continue your Solace journey.
Step | Description |
---|---|
|
Set up Your First Event Broker - Complete |
|
Solace EDA Basics - Complete |
|
Set up the Solace Try-Me CLI Tool - Complete |
|
Try a Publish-Subscribe Message Exchange Pattern - Complete |
|
Try a Request-Reply Message Exchange Pattern - Complete |
|
Explore Consumer Scaling Patterns - Next Lesson |
|
Next Steps |
You can return to the main Tutorial page at any time.