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

Merge pull request #24 from nats-io/nats-deps

Replace go-nats with nats.go in examples
This commit is contained in:
Ginger Collison 2019-06-05 17:30:16 -05:00 committed by GitHub
commit 3e7182270b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 28 deletions

View File

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

View File

@ -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!"
```

View File

@ -1,6 +1,6 @@
## Cluster Upgrading
The basic strategy for upgrading a cluster revolves around the server's ability to gossip cluster configuration to clients and other servers. When cluster configuration changes, clients become aware of new servers automatically. In case of a disconnect, a client has a list of servers that joined the cluster in addition to the ones it knew about from its connection settings.
The basic strategy for upgrading a cluster revolves around the server's ability to gossip cluster configuration to clients and other servers. When cluster configuration changes, clients become aware of new servers automatically. In the case of a disconnect, a client has a list of servers that joined the cluster in addition to the ones it knew about from its connection settings.
Note that since each server stores it's own permission and authentication configuration, new servers added to a cluster should provide the same users and authorization to prevent clients from getting rejected or gaining unexpected privileges.
@ -27,17 +27,17 @@ Let's fix that, by starting the second server:
```bash
nats-server -D -p 4333 -cluster nats://localhost:6333 -routes nats://localhost:6222,nats://localhost:6333
```
The second server was started on port 4333 with its cluster port on 6333. Otherwise the same as 'A.'
The second server was started on port 4333 with its cluster port on 6333. Otherwise the same as 'A'.
Let's get one client, so we can observe it moving between servers as servers get removed:
```bash
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.'
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 'C'. Server 'C' will join the existing cluster while we perform the upgrade. Its sole purpose is to provide an additional place where clients can go other than '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 'C'.
Let's start our temporary server:
@ -45,9 +45,9 @@ Let's start our temporary server:
nats-server -D -p 4444 -cluster nats://localhost:6444 -routes nats://localhost:6222,nats://localhost:6333
```
After an instant or so, clients on 'A' learn of the new cluster member that joined. On our hands-on tutorial, `nats-sub` is now aware of 3 possible servers, 'A' (specified when we started the tool) and 'B' and 'T' learned from the cluster gossip.
After an instant or so, clients on 'A' learn of the new cluster member that joined. On our hands-on tutorial, `nats-sub` is now aware of 3 possible servers, 'A' (specified when we started the tool) and 'B' and 'C' learned from the cluster gossip.
We invoke our admin powers and turn off 'A' by issuing a `CTRL+C` to the terminal on 'A,' and observe that either 'B' or 'T' reports that a new client connected. That is our `nats-sub` client.
We invoke our admin powers and turn off 'A' by issuing a `CTRL+C` to the terminal on 'A' and observe that either 'B' or 'C' reports that a new client connected. That is our `nats-sub` client.
We perform the upgrade process, update the binary for 'A', and restart 'A':
@ -55,13 +55,13 @@ We perform the upgrade process, update the binary for 'A', and restart 'A':
nats-server -D -p 4222 -cluster nats://localhost:6222 -routes nats://localhost:6222,nats://localhost:6333
```
We move on to upgrade 'B'. Notice that clients from 'B' reconnect to 'A' and 'T'. We upgrade and restart 'B':
We move on to upgrade 'B'. Notice that clients from 'B' reconnect to 'A' and 'C'. We upgrade and restart 'B':
```bash
nats-server -D -p 4333 -cluster nats://localhost:6333 -routes nats://localhost:6222,nats://localhost:6333
```
If we had more servers, we would continue the stop, update, restart rotation as we did for 'A' and 'B.' After restarting the last server, we can go ahead and turn off 'T.' Any clients on 'T' will redistribute to our permanent cluster members.
If we had more servers, we would continue the stop, update, restart rotation as we did for 'A' and 'B'. After restarting the last server, we can go ahead and turn off 'C.' Any clients on 'C' will redistribute to our permanent cluster members.
### Seed Servers
@ -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
```
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', they 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
$ 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=[]

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:
```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%`.*

View File

@ -216,9 +216,9 @@ At minimum the server requires the `operator` JWT, which we have pointed at dire
Lets 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:

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:
```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'
```
@ -290,4 +290,4 @@ The service receives the message:
The requester receives its response:
```text
Received [_INBOX.N3IiqWbiAQfPoINCBpBrUM.ZjBNtkB3] : 'I will help'
```
```