mirror of
https://github.com/taigrr/nats.docs
synced 2025-01-18 04:03:23 -08:00
Update pubsub.md
This commit is contained in:
parent
80d1c694b0
commit
bc6f03625c
@ -63,13 +63,13 @@ You will use this session to run an example NATS client subscriber program.
|
||||
### 3. CD to the Go client examples directory
|
||||
|
||||
```sh
|
||||
% cd $GOPATH/src/github.com/nats-io/nats/examples
|
||||
% cd $GOPATH/src/github.com/nats-io/nats.go/examples
|
||||
```
|
||||
|
||||
### 4. Run the client subscriber program
|
||||
|
||||
```sh
|
||||
% go run nats-sub.go <subject>
|
||||
% go run nats-sub/main.go <subject>
|
||||
```
|
||||
|
||||
Where `<subject>` is a subject to listen on. A valid subject is a string that is unique in the system.
|
||||
@ -77,7 +77,7 @@ Where `<subject>` is a subject to listen on. A valid subject is a string that is
|
||||
For example:
|
||||
|
||||
```sh
|
||||
% go run nats-sub.go msg.test
|
||||
% go run nats-sub/main.go msg.test
|
||||
```
|
||||
|
||||
You should see the message: *Listening on [msg.test]*
|
||||
@ -89,13 +89,13 @@ You will use this session to run a NATS publisher client.
|
||||
## 6. CD to the examples directory
|
||||
|
||||
```sh
|
||||
% cd $GOPATH/src/github.com/nats-io/nats/examples
|
||||
% cd $GOPATH/src/github.com/nats-io/nats.go/examples
|
||||
```
|
||||
|
||||
### 7. Publish a NATS message
|
||||
|
||||
```sh
|
||||
% go run nats-pub.go <subject> <message>
|
||||
% go run nats-pub/main.go <subject> <message>
|
||||
```
|
||||
|
||||
Where `<subject>` is the subject name and `<message>` is the text to publish.
|
||||
@ -103,13 +103,13 @@ Where `<subject>` is the subject name and `<message>` is the text to publish.
|
||||
For example:
|
||||
|
||||
```sh
|
||||
% go run nats-pub.go msg.test hello
|
||||
% go run nats-pub/main.go msg.test hello
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
% go run nats-pub.go msg.test "NATS MESSAGE"
|
||||
% go run nats-pub/main.go msg.test "NATS MESSAGE"
|
||||
```
|
||||
|
||||
### 8. Verify message publication and receipt
|
||||
@ -123,7 +123,7 @@ Note that if the receiver does not get the message, check that you are using the
|
||||
### 9. Publish another message
|
||||
|
||||
```sh
|
||||
% go run nats-pub.go msg.test "NATS MESSAGE 2"
|
||||
% go run nats-pub/main.go msg.test "NATS MESSAGE 2"
|
||||
```
|
||||
|
||||
You should see that the subscriber receive message 2. Note that the message count is incremented each time your subscribing client receives a message on that subject:
|
||||
@ -135,19 +135,19 @@ You will use this session to run a second NATS subscriber.
|
||||
### 11. CD to the examples directory
|
||||
|
||||
```sh
|
||||
% cd $GOPATH/src/github.com/nats-io/nats/examples
|
||||
% cd $GOPATH/src/github.com/nats-io/nats.go/examples
|
||||
```
|
||||
|
||||
### 12. Subscribe to the message
|
||||
|
||||
```sh
|
||||
% go run nats-sub.go msg.test
|
||||
% go run nats-sub/main.go msg.test
|
||||
```
|
||||
|
||||
### 13. Publish another message using the publisher client
|
||||
|
||||
```sh
|
||||
% go run nats-pub.go msg.test "NATS MESSAGE 3"
|
||||
% go run nats-pub/main.go msg.test "NATS MESSAGE 3"
|
||||
```
|
||||
|
||||
Verify that both subscribing clients receive the message.
|
||||
@ -159,13 +159,13 @@ You will use this session to run a third NATS subscriber.
|
||||
### 15. CD to the examples directory
|
||||
|
||||
```sh
|
||||
% cd $GOPATH/src/github.com/nats-io/nats/examples
|
||||
% cd $GOPATH/src/github.com/nats-io/nats.go/examples
|
||||
```
|
||||
|
||||
### 16. Subscribe to a different message
|
||||
|
||||
```sh
|
||||
% go run nats-sub.go msg.test.new
|
||||
% go run nats-sub/main.go msg.test.new
|
||||
```
|
||||
|
||||
All the but last subscriber receives the message. Why? Because that subscriber is not listening on the message subject used by the publisher.
|
||||
@ -177,7 +177,7 @@ NATS supports the use of wildcard characters for message subscribers. You cannot
|
||||
Change the last subscriber the listen on msg.* and run it:
|
||||
|
||||
```sh
|
||||
% go run nats-sub.go msg.*
|
||||
% go run nats-sub/main.go msg.*
|
||||
```
|
||||
|
||||
### 18. Publish another message
|
||||
|
Loading…
x
Reference in New Issue
Block a user