1
0
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:
Ginger Collison 2019-06-14 12:08:23 -05:00 committed by GitHub
parent 80d1c694b0
commit bc6f03625c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 ### 3. CD to the Go client examples directory
```sh ```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 ### 4. Run the client subscriber program
```sh ```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. 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: For example:
```sh ```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]* 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 ## 6. CD to the examples directory
```sh ```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 ### 7. Publish a NATS message
```sh ```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. 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: For example:
```sh ```sh
% go run nats-pub.go msg.test hello % go run nats-pub/main.go msg.test hello
``` ```
or or
```sh ```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 ### 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 ### 9. Publish another message
```sh ```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: 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 ### 11. CD to the examples directory
```sh ```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 ### 12. Subscribe to the message
```sh ```sh
% go run nats-sub.go msg.test % go run nats-sub/main.go msg.test
``` ```
### 13. Publish another message using the publisher client ### 13. Publish another message using the publisher client
```sh ```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. 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 ### 15. CD to the examples directory
```sh ```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 ### 16. Subscribe to a different message
```sh ```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. 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: Change the last subscriber the listen on msg.* and run it:
```sh ```sh
% go run nats-sub.go msg.* % go run nats-sub/main.go msg.*
``` ```
### 18. Publish another message ### 18. Publish another message