1
0
mirror of https://github.com/taigrr/nats.docs synced 2025-01-18 04:03:23 -08:00
Stephen Asbury 9618415569 Moved tools to _tools
Broke up develoepr doc into tree
Small CSS tweak to give diagrams more room
2019-05-15 12:22:57 -07:00

42 lines
1.2 KiB
Markdown

# Explore NATS Request/Reply
NATS supports request/reply messaging. In this tutorial you explore how to exchange point-to-point messages using NATS.
## Prerequisites
Go and the NATS server should be installed.
## 1. Start the NATS server
```sh
% gnatsd
```
## 2. Start two terminal sessions
You will use these sessions to run the NATS request and reply clients.
## 3. Change to the examples directory
```sh
% cd $GOPATH/src/github.com/nats-io/nats/examples
```
## 4. In one terminal, run the reply client listener
```sh
% go run nats-rply.go foo "this is my response"
```
You should see the message `Receiver is listening`, and that the NATS receiver client is listening on the "help.please" subject. The reply client acts as a receiver, listening for message requests. In NATS, the receiver is a subscriber.
## 5. In the other terminal, run the request client
```sh
% go run nats-req.go foo "request payload"
```
The NATS requestor client makes a request by sending the message "some message" on the “help.please” subject.
The NATS receiver client receives the message, formulates the reply ("OK, I CAN HELP!!!), and sends it to the inbox of the requester.