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:
parent
b4bcfc165e
commit
e22bcf3938
@ -15,7 +15,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/go-nats"
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
|
||||
type customDialer struct {
|
||||
|
@ -15,7 +15,7 @@ nats-server
|
||||
### 2. Clone the repositories for each client examples
|
||||
|
||||
```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/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
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
@ -45,14 +45,14 @@ nats-queue foo my-queue &
|
||||
### 6. Run another Go client subscriber *without* the queue group.
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
### 7. Publish a NATS message using the Go client
|
||||
|
||||
```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!"
|
||||
```
|
||||
|
||||
|
@ -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 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/).
|
||||
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.'
|
||||
|
@ -47,18 +47,18 @@ be routing the messages so that they will be processed to the NATS Streaming clu
|
||||
```sh
|
||||
$ 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
|
||||
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'
|
||||
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'
|
||||
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'
|
||||
|
||||
# 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]
|
||||
subscribing with DeliverAllAvailable
|
||||
Listening on [hello], clientID=[17010], qgroup=[] durable=[]
|
||||
|
@ -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:
|
||||
|
||||
```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`:
|
||||
|
||||
```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%`.*
|
||||
|
@ -216,9 +216,9 @@ At minimum the server requires the `operator` JWT, which we have pointed at dire
|
||||
Let’s install some tooling:
|
||||
|
||||
```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:
|
||||
|
@ -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:
|
||||
```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"
|
||||
Listening on [help]
|
||||
@ -108,7 +108,7 @@ Listening on [help]
|
||||
|
||||
Send the request:
|
||||
```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
|
||||
Published [help] : 'me'
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user