1
0
mirror of https://github.com/taigrr/nats.docs synced 2025-01-18 04:03:23 -08:00

Replace go-nats with nats.go in examples

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This commit is contained in:
Waldemar Quevedo 2019-06-05 15:06:39 -07:00
parent b4bcfc165e
commit e22bcf3938
7 changed files with 20 additions and 20 deletions

View File

@ -15,7 +15,7 @@ import (
"net" "net"
"time" "time"
"github.com/nats-io/go-nats" "github.com/nats-io/nats.go"
) )
type customDialer struct { type customDialer struct {
@ -129,4 +129,4 @@ WaitForEstablishedConnection:
} }
log.Println("Disconnected") log.Println("Disconnected")
} }
``` ```

View File

@ -15,7 +15,7 @@ nats-server
### 2. Clone the repositories for each client examples ### 2. Clone the repositories for each client examples
```sh ```sh
go get github.com/nats-io/go-nats go get github.com/nats-io/nats.go
git clone https://github.com/nats-io/node-nats.git git clone https://github.com/nats-io/node-nats.git
git clone https://github.com/nats-io/ruby-nats.git git clone https://github.com/nats-io/ruby-nats.git
``` ```
@ -23,7 +23,7 @@ git clone https://github.com/nats-io/ruby-nats.git
### 3. Run the Go client subscriber with queue group name ### 3. Run the Go client subscriber with queue group name
```sh ```sh
cd $GOPATH/src/github.com/nats-io/go-nats/examples cd $GOPATH/src/github.com/nats-io/nats.go/examples
go run nats-qsub.go foo my-queue go run nats-qsub.go foo my-queue
``` ```
@ -45,14 +45,14 @@ nats-queue foo my-queue &
### 6. Run another Go client subscriber *without* the queue group. ### 6. Run another Go client subscriber *without* the queue group.
```sh ```sh
cd $GOPATH/src/github.com/nats-io/go-nats/examples cd $GOPATH/src/github.com/nats-io/nats.go/examples
go run nats-sub.go foo go run nats-sub.go foo
``` ```
### 7. Publish a NATS message using the Go client ### 7. Publish a NATS message using the Go client
```sh ```sh
cd $GOPATH/src/github.com/nats-io/go-nats/examples cd $GOPATH/src/github.com/nats-io/nats.go/examples
go run nats-pub.go foo "Hello NATS!" go run nats-pub.go foo "Hello NATS!"
``` ```

View File

@ -34,7 +34,7 @@ Let's get one client, so we can observe it moving between servers as servers get
nats-sub -s nats://localhost:4222 ">" nats-sub -s nats://localhost:4222 ">"
``` ```
Nats-sub is a subscriber sample included with all NATS clients. Nats-sub subscribes to a subject and prints out any messages received. You can find the source code to the go version of nats-sub [here)(https://github.com/nats-io/go-nats/tree/master/examples). After starting the subscriber you should see a message on 'A' that a new client connected. `nats-sub` is a subscriber sample included with all NATS clients. `nats-sub` subscribes to a subject and prints out any messages received. You can find the source code to the go version of `nats-sub` [here)(https://github.com/nats-io/nats.go/tree/master/examples). After starting the subscriber you should see a message on 'A' that a new client connected.
We have two servers and a client. Time to simulate our rolling upgrade. But wait, before we upgrade 'A,' let's introduce a new server 'T.' Server 'T' will join the existing cluster while we perform the upgrade. Its sole purpose is to provide an additional place where clients can go besides 'A.' and ensure we don't end up with a single server serving all the clients after the upgrade procedure. Clients will randomly select a server when connecting unless a special option is provided that disables that functionality (usually called 'DontRandomize' or 'noRandomize'). You can read more about ["Avoiding the Thundering Herd"](/developer/reconnect/random.md/). We have two servers and a client. Time to simulate our rolling upgrade. But wait, before we upgrade 'A,' let's introduce a new server 'T.' Server 'T' will join the existing cluster while we perform the upgrade. Its sole purpose is to provide an additional place where clients can go besides 'A.' and ensure we don't end up with a single server serving all the clients after the upgrade procedure. Clients will randomly select a server when connecting unless a special option is provided that disables that functionality (usually called 'DontRandomize' or 'noRandomize'). You can read more about ["Avoiding the Thundering Herd"](/developer/reconnect/random.md/).
Suffice it to say that clients redistribute themselves about evenly between all servers in the cluster. In our case 1/2 of the clients on 'A' will jump over to 'B' and the remaining half to 'T.' Suffice it to say that clients redistribute themselves about evenly between all servers in the cluster. In our case 1/2 of the clients on 'A' will jump over to 'B' and the remaining half to 'T.'
@ -83,4 +83,4 @@ nats-server -D -p 4333 -cluster nats://localhost:6333 -routes nats://localhost:6
nats-server -D -p 4444 -cluster nats://localhost:6444 -routes nats://localhost:6222 nats-server -D -p 4444 -cluster nats://localhost:6444 -routes nats://localhost:6222
``` ```
Once they connect to the 'seed server', the will learn about all the other servers and connect to each other forming the full mesh. Once they connect to the 'seed server', the will learn about all the other servers and connect to each other forming the full mesh.

View File

@ -47,18 +47,18 @@ be routing the messages so that they will be processed to the NATS Streaming clu
```sh ```sh
$ sudo docker run --network nats-streaming-example -it golang:latest $ sudo docker run --network nats-streaming-example -it golang:latest
root@d12f9f3fcdde:/go# cd src/github.com/nats-io/go-nats-streaming/ root@d12f9f3fcdde:/go# cd src/github.com/nats-io/stan.go/
# Publishing 3 messages # Publishing 3 messages
root@d12f9f3fcdde:/go/src/github.com/nats-io/go-nats-streaming# go run examples/stan-pub/main.go -s nats://nats-cluster-node-1:4222 --cluster swarm hello world root@d12f9f3fcdde:/go/src/github.com/nats-io/stan.go# go run examples/stan-pub/main.go -s nats://nats-cluster-node-1:4222 --cluster swarm hello world
Published [hello] : 'world' Published [hello] : 'world'
root@d12f9f3fcdde:/go/src/github.com/nats-io/go-nats-streaming# go run examples/stan-pub/main.go -s nats://nats-cluster-node-1:4222 --cluster swarm hello world root@d12f9f3fcdde:/go/src/github.com/nats-io/stan.go# go run examples/stan-pub/main.go -s nats://nats-cluster-node-1:4222 --cluster swarm hello world
Published [hello] : 'world' Published [hello] : 'world'
root@d12f9f3fcdde:/go/src/github.com/nats-io/go-nats-streaming# go run examples/stan-pub/main.go -s nats://nats-cluster-node-1:4222 --cluster swarm hello world root@d12f9f3fcdde:/go/src/github.com/nats-io/stan.go# go run examples/stan-pub/main.go -s nats://nats-cluster-node-1:4222 --cluster swarm hello world
Published [hello] : 'world' Published [hello] : 'world'
# Replaying the messages from the beginning # Replaying the messages from the beginning
root@d12f9f3fcdde:/go/src/github.com/nats-io/go-nats-streaming# go run examples/stan-sub/main.go -s nats://nats-cluster-node-1:4222 --cluster swarm -id $RANDOM --all hello root@d12f9f3fcdde:/go/src/github.com/nats-io/stan.go# go run examples/stan-sub/main.go -s nats://nats-cluster-node-1:4222 --cluster swarm -id $RANDOM --all hello
Connected to nats://nats-cluster-node-1:4222 clusterID: [swarm] clientID: [17010] Connected to nats://nats-cluster-node-1:4222 clusterID: [swarm] clientID: [17010]
subscribing with DeliverAllAvailable subscribing with DeliverAllAvailable
Listening on [hello], clientID=[17010], qgroup=[] durable=[] Listening on [hello], clientID=[17010], qgroup=[] durable=[]

View File

@ -29,13 +29,13 @@ The NATS benchmark can be installed and run via Go. Ensure your golang environm
There are two approaches; you can either install the `nats-bench` utility in the directory specified in your `GOBIN` environment variable: There are two approaches; you can either install the `nats-bench` utility in the directory specified in your `GOBIN` environment variable:
```sh ```sh
% go install $GOPATH/src/github.com/nats-io/go-nats/examples/nats-bench.go % go install $GOPATH/src/github.com/nats-io/nats.go/examples/nats-bench.go
``` ```
... or you can simply run it via `go run`: ... or you can simply run it via `go run`:
```sh ```sh
% go run $GOPATH/src/github.com/nats-io/go-nats/examples/nats-bench.go % go run $GOPATH/src/github.com/nats-io/nats.go/examples/nats-bench.go
``` ```
*On windows use the % environment variable syntax, replacing `$GOPATH` with `%GOPATH%`.* *On windows use the % environment variable syntax, replacing `$GOPATH` with `%GOPATH%`.*

View File

@ -216,9 +216,9 @@ At minimum the server requires the `operator` JWT, which we have pointed at dire
Lets install some tooling: Lets install some tooling:
```text ```text
> go get github.com/nats-io/go-nats/examples/nats-pub > go get github.com/nats-io/nats.go/examples/nats-pub
> go get github.com/nats-io/go-nats/examples/nats-sub > go get github.com/nats-io/nats.go/examples/nats-sub
``` ```
Create a subscriber: Create a subscriber:

View File

@ -100,7 +100,7 @@ To test the service, we can install the `nats-req` and `nats-rply` tools:
Set up a process to handle the request: Set up a process to handle the request:
```text ```text
> go get github.com/nats-io/go-nats/examples/nats-rply > go get github.com/nats-io/nats.go/examples/nats-rply
> nats-rply -creds ~/.nkeys/Test/accounts/AccountB/users/userb.creds "help" "I will help" > nats-rply -creds ~/.nkeys/Test/accounts/AccountB/users/userb.creds "help" "I will help"
Listening on [help] Listening on [help]
@ -108,7 +108,7 @@ Listening on [help]
Send the request: Send the request:
```text ```text
> go get github.com/nats-io/go-nats/examples/nats-req > go get github.com/nats-io/nats.go/examples/nats-req
> nats-req -creds ~/.nkeys/Test/accounts/AccountB/users/userb.creds help me > nats-req -creds ~/.nkeys/Test/accounts/AccountB/users/userb.creds help me
Published [help] : 'me' Published [help] : 'me'
``` ```
@ -290,4 +290,4 @@ The service receives the message:
The requester receives its response: The requester receives its response:
```text ```text
Received [_INBOX.N3IiqWbiAQfPoINCBpBrUM.ZjBNtkB3] : 'I will help' Received [_INBOX.N3IiqWbiAQfPoINCBpBrUM.ZjBNtkB3] : 'I will help'
``` ```