├── .gitignore ├── api-examples ├── connect_default │ └── main.go ├── connect_creds │ └── main.go ├── connect_token_url │ └── main.go ├── no_echo │ └── main.go ├── connect_name │ └── main.go ├── reconnect_10x │ └── main.go ├── reconnect_none │ └── main.go ├── connect_token │ └── main.go ├── connect_userpass_url │ └── main.go ├── connect_options │ └── main.go ├── max_payload │ └── main.go ├── connect_userpass │ └── main.go ├── reconnect_5mb │ └── main.go ├── publish_bytes │ └── main.go ├── reconnect_10s │ └── main.go ├── connect_nkey │ └── main.go ├── ping_20s │ └── main.go ├── connect_tls_url │ └── main.go ├── connect_tls │ └── main.go ├── connect_verbose │ └── main.go ├── connect_pedantic │ └── main.go ├── notapplicable.txt ├── connect_multiple │ └── main.go ├── ping_5 │ └── main.go ├── reconnect_no_random │ └── main.go ├── connect_url │ └── main.go ├── error_listener │ └── main.go ├── request_reply │ └── main.go ├── subscribe_async │ └── main.go ├── subscribe_sync │ └── main.go ├── servers_added │ └── main.go ├── publish_json │ └── main.go ├── subscribe_star │ └── main.go ├── reconnect_event │ └── main.go ├── subscribe_queue │ └── main.go ├── connect_status │ └── main.go ├── subscribe_w_reply │ └── main.go ├── unsubscribe │ └── main.go ├── slow_listener │ └── main.go ├── subscribe_arrow │ └── main.go ├── flush │ └── main.go ├── unsubscribe_auto │ └── main.go ├── sub_pending_limits │ └── main.go ├── subscribe_json │ └── main.go ├── wildcard_tester │ └── main.go ├── publish_with_reply │ └── main.go ├── drain_conn │ └── main.go ├── drain_sub │ └── main.go └── resources │ └── certs │ ├── cert.pem │ ├── ca.pem │ └── key.pem ├── .travis.yml ├── update_samples.sh ├── go.mod ├── patterns ├── request-reply │ └── README.md ├── publish-subscribe │ └── README.md └── competing-consumer │ └── README.md ├── README.md ├── releaser.yml ├── tools ├── nats-pub │ └── nats-pub.go ├── nats-req │ └── nats-req.go ├── nats-sub │ └── nats-sub.go ├── nats-qsub │ └── nats-qsub.go ├── nats-rply │ └── nats-rply.go ├── stan-pub │ └── stan-pub.go ├── nats-echo │ └── nats-echo.go ├── nats-bench │ └── nats-bench.go └── stan-sub │ └── stan-sub.go ├── LICENSE └── go.sum /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | .DS_Store 8 | 9 | # Test binary, build with `go test -c` 10 | *.test 11 | build/ 12 | cov/ 13 | .idea/ 14 | .vscode/ 15 | 16 | # Output of the go coverage tool, specifically when used with LiteIDE 17 | *.out 18 | 19 | vendor/** 20 | !vendor/manifest 21 | 22 | 23 | -------------------------------------------------------------------------------- /api-examples/connect_default/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_default] 11 | nc, err := nats.Connect(nats.DefaultURL) 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | // Do something with the connection 18 | 19 | // [end connect_default] 20 | } 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | go: 4 | - 1.17.x 5 | before_script: 6 | - go vet -v ./... 7 | script: 8 | - go build -v ./... 9 | 10 | after_success: 11 | - git reset --hard 12 | 13 | deploy: 14 | - provider: script 15 | skip_cleanup: true 16 | script: curl -sL http://git.io/goreleaser | bash -s -- --config releaser.yml 17 | on: 18 | tags: true 19 | condition: $TRAVIS_OS_NAME = linux 20 | -------------------------------------------------------------------------------- /api-examples/connect_creds/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_creds] 11 | nc, err := nats.Connect("127.0.0.1", nats.UserCredentials("path_to_creds_file")) 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | // Do something with the connection 18 | 19 | // [end connect_creds] 20 | } 21 | -------------------------------------------------------------------------------- /api-examples/connect_token_url/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_token_url] 11 | // Token in URL 12 | nc, err := nats.Connect("mytoken@localhost") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end connect_token_url] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/no_echo/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin no_echo] 11 | // Turn off echo 12 | nc, err := nats.Connect("demo.nats.io", nats.Name("API NoEcho Example"), nats.NoEcho()) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end no_echo] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/connect_name/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_name] 11 | // Set a connection name 12 | nc, err := nats.Connect("demo.nats.io", nats.Name("API Name Example")) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end connect_name] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/reconnect_10x/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin reconnect_10x] 11 | // Set max reconnects attempts 12 | nc, err := nats.Connect("demo.nats.io", nats.MaxReconnects(10)) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end reconnect_10x] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/reconnect_none/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin reconnect_none] 11 | // Disable reconnect attempts 12 | nc, err := nats.Connect("demo.nats.io", nats.NoReconnect()) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end reconnect_none] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/connect_token/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_token] 11 | // Set a token 12 | nc, err := nats.Connect("127.0.0.1", nats.Name("API Token Example"), nats.Token("mytoken")) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end connect_token] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/connect_userpass_url/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_userpass_url] 11 | // Set a user and plain text password 12 | nc, err := nats.Connect("myname:password@127.0.0.1") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end connect_userpass_url] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/connect_options/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin connect_options] 12 | nc, err := nats.Connect("demo.nats.io", nats.Name("API Options Example"), nats.Timeout(10*time.Second)) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end connect_options] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/max_payload/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin max_payload] 11 | nc, err := nats.Connect("demo.nats.io") 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | mp := nc.MaxPayload() 18 | log.Printf("Maximum payload is %v bytes", mp) 19 | 20 | // Do something with the max payload 21 | 22 | // [end max_payload] 23 | } 24 | -------------------------------------------------------------------------------- /api-examples/connect_userpass/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_userpass] 11 | // Set a user and plain text password 12 | nc, err := nats.Connect("127.0.0.1", nats.UserInfo("myname", "password")) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end connect_userpass] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/reconnect_5mb/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin reconnect_5mb] 11 | // Set reconnect buffer size in bytes (5 MB) 12 | nc, err := nats.Connect("demo.nats.io", nats.ReconnectBufSize(5*1024*1024)) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end reconnect_5mb] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/publish_bytes/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin publish_bytes] 11 | nc, err := nats.Connect("demo.nats.io", nats.Name("API PublishBytes Example")) 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | if err := nc.Publish("updates", []byte("All is Well")); err != nil { 18 | log.Fatal(err) 19 | } 20 | // [end publish_bytes] 21 | } 22 | -------------------------------------------------------------------------------- /api-examples/reconnect_10s/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin reconnect_10s] 12 | // Set reconnect interval to 10 seconds 13 | nc, err := nats.Connect("demo.nats.io", nats.ReconnectWait(10*time.Second)) 14 | if err != nil { 15 | log.Fatal(err) 16 | } 17 | defer nc.Close() 18 | 19 | // Do something with the connection 20 | 21 | // [end reconnect_10s] 22 | } 23 | -------------------------------------------------------------------------------- /api-examples/connect_nkey/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_nkey] 11 | opt, err := nats.NkeyOptionFromSeed("seed.txt") 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | nc, err := nats.Connect("127.0.0.1", opt) 16 | if err != nil { 17 | log.Fatal(err) 18 | } 19 | defer nc.Close() 20 | 21 | // Do something with the connection 22 | 23 | // [end connect_nkey] 24 | } 25 | -------------------------------------------------------------------------------- /api-examples/ping_20s/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin ping_20s] 12 | // Set Ping Interval to 20 seconds 13 | nc, err := nats.Connect("demo.nats.io", nats.Name("API Ping Example"), nats.PingInterval(20*time.Second)) 14 | if err != nil { 15 | log.Fatal(err) 16 | } 17 | defer nc.Close() 18 | 19 | // Do something with the connection 20 | 21 | // [end ping_20s] 22 | } 23 | -------------------------------------------------------------------------------- /api-examples/connect_tls_url/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_tls_url] 11 | nc, err := nats.Connect("tls://localhost", nats.RootCAs("resources/certs/ca.pem")) // May need this if server is using self-signed certificate 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | // Do something with the connection 18 | 19 | // [end connect_tls_url] 20 | } 21 | -------------------------------------------------------------------------------- /api-examples/connect_tls/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_tls] 11 | nc, err := nats.Connect("localhost", 12 | nats.ClientCert("resources/certs/cert.pem", "resources/certs/key.pem"), 13 | nats.RootCAs("resources/certs/ca.pem")) 14 | if err != nil { 15 | log.Fatal(err) 16 | } 17 | defer nc.Close() 18 | 19 | // Do something with the connection 20 | 21 | // [end connect_tls] 22 | } 23 | -------------------------------------------------------------------------------- /api-examples/connect_verbose/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_verbose] 11 | opts := nats.GetDefaultOptions() 12 | opts.Url = "demo.nats.io" 13 | // Turn on Verbose 14 | opts.Verbose = true 15 | nc, err := opts.Connect() 16 | if err != nil { 17 | log.Fatal(err) 18 | } 19 | defer nc.Close() 20 | 21 | // Do something with the connection 22 | 23 | // [end connect_verbose] 24 | } 25 | -------------------------------------------------------------------------------- /api-examples/connect_pedantic/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_pedantic] 11 | opts := nats.GetDefaultOptions() 12 | opts.Url = "demo.nats.io" 13 | // Turn on Pedantic 14 | opts.Pedantic = true 15 | nc, err := opts.Connect() 16 | if err != nil { 17 | log.Fatal(err) 18 | } 19 | defer nc.Close() 20 | 21 | // Do something with the connection 22 | 23 | // [end connect_pedantic] 24 | } 25 | -------------------------------------------------------------------------------- /api-examples/notapplicable.txt: -------------------------------------------------------------------------------- 1 | [begin control_2k] 2 | // This does not apply to the NATS Go Client 3 | [end control_2k] 4 | 5 | [begin connection_listener] 6 | // There is not a single listener for connection events in the NATS Go Client. 7 | // Instead, you can set individual event handlers using: 8 | 9 | DisconnectHandler(cb ConnHandler) 10 | ReconnectHandler(cb ConnHandler) 11 | ClosedHandler(cb ConnHandler) 12 | DiscoveredServersHandler(cb ConnHandler) 13 | ErrorHandler(cb ErrHandler) 14 | [end connection_listener] -------------------------------------------------------------------------------- /api-examples/connect_multiple/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "strings" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin connect_multiple] 12 | servers := []string{"nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"} 13 | 14 | nc, err := nats.Connect(strings.Join(servers, ",")) 15 | if err != nil { 16 | log.Fatal(err) 17 | } 18 | defer nc.Close() 19 | 20 | // Do something with the connection 21 | 22 | // [end connect_multiple] 23 | } 24 | -------------------------------------------------------------------------------- /update_samples.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | nats_tools=(nats-bench nats-echo nats-pub nats-qsub nats-req nats-rply nats-sub) 4 | for i in "${nats_tools[@]}" 5 | do 6 | echo "downloading ${i}" 7 | curl "https://raw.githubusercontent.com/nats-io/nats.go/main/examples/${i}/main.go" -o "tools/${i}/${i}.go" 8 | done 9 | 10 | stan_tools=(stan-pub stan-sub) 11 | for i in "${stan_tools[@]}" 12 | do 13 | echo "downloading ${i}" 14 | curl "https://raw.githubusercontent.com/nats-io/stan.go/main/examples/${i}/main.go" -o "tools/${i}/${i}.go" 15 | done 16 | -------------------------------------------------------------------------------- /api-examples/ping_5/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin ping_5] 11 | 12 | // Set maximum number of PINGs out without getting a PONG back 13 | // before the connection will be disconnected as a stale connection. 14 | nc, err := nats.Connect("demo.nats.io", nats.Name("API MaxPing Example"), nats.MaxPingsOutstanding(5)) 15 | if err != nil { 16 | log.Fatal(err) 17 | } 18 | defer nc.Close() 19 | 20 | // Do something with the connection 21 | 22 | // [end ping_5] 23 | } 24 | -------------------------------------------------------------------------------- /api-examples/reconnect_no_random/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "strings" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin reconnect_no_random] 12 | servers := []string{"nats://127.0.0.1:1222", 13 | "nats://127.0.0.1:1223", 14 | "nats://127.0.0.1:1224", 15 | } 16 | 17 | nc, err := nats.Connect(strings.Join(servers, ","), nats.DontRandomize()) 18 | if err != nil { 19 | log.Fatal(err) 20 | } 21 | defer nc.Close() 22 | 23 | // Do something with the connection 24 | 25 | // [end reconnect_no_random] 26 | } 27 | -------------------------------------------------------------------------------- /api-examples/connect_url/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_url] 11 | // If connecting to the default port, the URL can be simplified 12 | // to just the hostname/IP. 13 | // That is, the connect below is equivalent to: 14 | // nats.Connect("nats://demo.nats.io:4222") 15 | nc, err := nats.Connect("demo.nats.io") 16 | if err != nil { 17 | log.Fatal(err) 18 | } 19 | defer nc.Close() 20 | 21 | // Do something with the connection 22 | 23 | // [end connect_url] 24 | } 25 | -------------------------------------------------------------------------------- /api-examples/error_listener/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin error_listener] 11 | // Set the callback that will be invoked when an asynchronous error occurs. 12 | nc, err := nats.Connect("demo.nats.io", 13 | nats.ErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, err error) { 14 | log.Printf("Error: %v", err) 15 | })) 16 | if err != nil { 17 | log.Fatal(err) 18 | } 19 | defer nc.Close() 20 | 21 | // Do something with the connection 22 | 23 | // [end error_listener] 24 | } 25 | -------------------------------------------------------------------------------- /api-examples/request_reply/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin request_reply] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Send the request 19 | msg, err := nc.Request("time", nil, time.Second) 20 | if err != nil { 21 | log.Fatal(err) 22 | } 23 | 24 | // Use the response 25 | log.Printf("Reply: %s", msg.Data) 26 | 27 | // Close the connection 28 | nc.Close() 29 | // [end request_reply] 30 | } 31 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/nats-io/go-nats-examples 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/nats-io/nats.go v1.12.1 7 | github.com/nats-io/stan.go v0.10.0 8 | ) 9 | 10 | require ( 11 | github.com/gogo/protobuf v1.3.2 // indirect 12 | github.com/golang/protobuf v1.5.2 // indirect 13 | github.com/nats-io/nats-server/v2 v2.5.0 // indirect 14 | github.com/nats-io/nats-streaming-server v0.22.1 // indirect 15 | github.com/nats-io/nkeys v0.3.0 // indirect 16 | github.com/nats-io/nuid v1.0.1 // indirect 17 | golang.org/x/crypto v0.1.0 // indirect 18 | google.golang.org/protobuf v1.27.1 // indirect 19 | ) 20 | -------------------------------------------------------------------------------- /api-examples/subscribe_async/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "sync" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin subscribe_async] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Use a WaitGroup to wait for a message to arrive 19 | wg := sync.WaitGroup{} 20 | wg.Add(1) 21 | 22 | // Subscribe 23 | if _, err := nc.Subscribe("updates", func(m *nats.Msg) { 24 | wg.Done() 25 | }); err != nil { 26 | log.Fatal(err) 27 | } 28 | 29 | // Wait for a message to come in 30 | wg.Wait() 31 | 32 | // [end subscribe_async] 33 | } 34 | -------------------------------------------------------------------------------- /api-examples/subscribe_sync/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin subscribe_sync] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Subscribe 19 | sub, err := nc.SubscribeSync("updates") 20 | if err != nil { 21 | log.Fatal(err) 22 | } 23 | 24 | // Wait for a message 25 | msg, err := sub.NextMsg(10 * time.Second) 26 | if err != nil { 27 | log.Fatal(err) 28 | } 29 | 30 | // Use the response 31 | log.Printf("Reply: %s", msg.Data) 32 | 33 | // [end subscribe_sync] 34 | } 35 | -------------------------------------------------------------------------------- /api-examples/servers_added/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin servers_added] 11 | // Be notified if a new server joins the cluster. 12 | // Print all the known servers and the only the ones that were discovered. 13 | nc, err := nats.Connect("demo.nats.io", 14 | nats.DiscoveredServersHandler(func(nc *nats.Conn) { 15 | log.Printf("Known servers: %v\n", nc.Servers()) 16 | log.Printf("Discovered servers: %v\n", nc.DiscoveredServers()) 17 | })) 18 | if err != nil { 19 | log.Fatal(err) 20 | } 21 | defer nc.Close() 22 | 23 | // Do something with the connection 24 | 25 | // [end servers_added] 26 | } 27 | -------------------------------------------------------------------------------- /api-examples/publish_json/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin publish_json] 11 | nc, err := nats.Connect("demo.nats.io") 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | ec, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER) 18 | if err != nil { 19 | log.Fatal(err) 20 | } 21 | defer ec.Close() 22 | 23 | // Define the object 24 | type stock struct { 25 | Symbol string 26 | Price int 27 | } 28 | 29 | // Publish the message 30 | if err := ec.Publish("updates", &stock{Symbol: "GOOG", Price: 1200}); err != nil { 31 | log.Fatal(err) 32 | } 33 | // [end publish_json] 34 | } 35 | -------------------------------------------------------------------------------- /api-examples/subscribe_star/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "sync" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin subscribe_star] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Use a WaitGroup to wait for 2 messages to arrive 19 | wg := sync.WaitGroup{} 20 | wg.Add(2) 21 | 22 | // Subscribe 23 | if _, err := nc.Subscribe("time.*.east", func(m *nats.Msg) { 24 | log.Printf("%s: %s", m.Subject, m.Data) 25 | wg.Done() 26 | }); err != nil { 27 | log.Fatal(err) 28 | } 29 | 30 | // Wait for the 2 messages to come in 31 | wg.Wait() 32 | 33 | // [end subscribe_star] 34 | } 35 | -------------------------------------------------------------------------------- /api-examples/reconnect_event/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin reconnect_event] 11 | // Connection event handlers are invoked asynchronously 12 | // and the state of the connection may have changed when 13 | // the callback is invoked. 14 | nc, err := nats.Connect("demo.nats.io", 15 | nats.DisconnectHandler(func(nc *nats.Conn) { 16 | // handle disconnect event 17 | }), 18 | nats.ReconnectHandler(func(nc *nats.Conn) { 19 | // handle reconnect event 20 | })) 21 | if err != nil { 22 | log.Fatal(err) 23 | } 24 | defer nc.Close() 25 | 26 | // Do something with the connection 27 | 28 | // [end reconnect_event] 29 | } 30 | -------------------------------------------------------------------------------- /api-examples/subscribe_queue/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "sync" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin subscribe_queue] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Use a WaitGroup to wait for 10 messages to arrive 19 | wg := sync.WaitGroup{} 20 | wg.Add(10) 21 | 22 | // Create a queue subscription on "updates" with queue name "workers" 23 | if _, err := nc.QueueSubscribe("updates", "worker", func(m *nats.Msg) { 24 | wg.Done() 25 | }); err != nil { 26 | log.Fatal(err) 27 | } 28 | 29 | // Wait for messages to come in 30 | wg.Wait() 31 | 32 | // [end subscribe_queue] 33 | } 34 | -------------------------------------------------------------------------------- /api-examples/connect_status/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin connect_status] 11 | nc, err := nats.Connect("demo.nats.io", nats.Name("API Example")) 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | getStatusTxt := func(nc *nats.Conn) string { 18 | switch nc.Status() { 19 | case nats.CONNECTED: 20 | return "Connected" 21 | case nats.CLOSED: 22 | return "Closed" 23 | default: 24 | return "Other" 25 | } 26 | } 27 | log.Printf("The connection is %v\n", getStatusTxt(nc)) 28 | 29 | nc.Close() 30 | 31 | log.Printf("The connection is %v\n", getStatusTxt(nc)) 32 | 33 | // [end connect_status] 34 | } 35 | -------------------------------------------------------------------------------- /api-examples/subscribe_w_reply/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin subscribe_w_reply] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Subscribe 19 | sub, err := nc.SubscribeSync("time") 20 | if err != nil { 21 | log.Fatal(err) 22 | } 23 | 24 | // Read a message 25 | msg, err := sub.NextMsg(10 * time.Second) 26 | if err != nil { 27 | log.Fatal(err) 28 | } 29 | 30 | // Get the time 31 | timeAsBytes := []byte(time.Now().String()) 32 | 33 | // Send the time as the response. 34 | msg.Respond(timeAsBytes) 35 | 36 | // [end subscribe_w_reply] 37 | } 38 | -------------------------------------------------------------------------------- /api-examples/unsubscribe/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin unsubscribe] 11 | nc, err := nats.Connect("demo.nats.io") 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | // Sync Subscription 18 | sub, err := nc.SubscribeSync("updates") 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | if err := sub.Unsubscribe(); err != nil { 23 | log.Fatal(err) 24 | } 25 | 26 | // Async Subscription 27 | sub, err = nc.Subscribe("updates", func(_ *nats.Msg) {}) 28 | if err != nil { 29 | log.Fatal(err) 30 | } 31 | if err := sub.Unsubscribe(); err != nil { 32 | log.Fatal(err) 33 | } 34 | 35 | // [end unsubscribe] 36 | } 37 | -------------------------------------------------------------------------------- /api-examples/slow_listener/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin slow_listener] 11 | // Set the callback that will be invoked when an asynchronous error occurs. 12 | nc, err := nats.Connect("demo.nats.io", nats.ErrorHandler(logSlowConsumer)) 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Do something with the connection 19 | 20 | // [end slow_listener] 21 | } 22 | 23 | func logSlowConsumer(nc *nats.Conn, sub *nats.Subscription, err error) { 24 | if err == nats.ErrSlowConsumer { 25 | dropped, _ := sub.Dropped() 26 | log.Printf("Slow consumer on subject %q: dropped %d messages\n", 27 | sub.Subject, dropped) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /api-examples/subscribe_arrow/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "sync" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin subscribe_arrow] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Use a WaitGroup to wait for 4 messages to arrive 19 | wg := sync.WaitGroup{} 20 | wg.Add(4) 21 | 22 | // Subscribe 23 | if _, err := nc.Subscribe("time.>", func(m *nats.Msg) { 24 | log.Printf("%s: %s", m.Subject, m.Data) 25 | wg.Done() 26 | }); err != nil { 27 | log.Fatal(err) 28 | } 29 | 30 | // Wait for the 4 messages to come in 31 | wg.Wait() 32 | 33 | // Close the connection 34 | nc.Close() 35 | // [end subscribe_arrow] 36 | } 37 | -------------------------------------------------------------------------------- /api-examples/flush/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin flush] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Just to not collide using the demo server with other users. 19 | subject := nats.NewInbox() 20 | 21 | if err := nc.Publish(subject, []byte("All is Well")); err != nil { 22 | log.Fatal(err) 23 | } 24 | // Sends a PING and wait for a PONG from the server, up to the given timeout. 25 | // This gives guarantee that the server has processed the above message. 26 | if err := nc.FlushTimeout(time.Second); err != nil { 27 | log.Fatal(err) 28 | } 29 | // [end flush] 30 | } 31 | -------------------------------------------------------------------------------- /api-examples/unsubscribe_auto/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin unsubscribe_auto] 11 | nc, err := nats.Connect("demo.nats.io") 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | // Sync Subscription 18 | sub, err := nc.SubscribeSync("updates") 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | if err := sub.AutoUnsubscribe(1); err != nil { 23 | log.Fatal(err) 24 | } 25 | 26 | // Async Subscription 27 | sub, err = nc.Subscribe("updates", func(_ *nats.Msg) {}) 28 | if err != nil { 29 | log.Fatal(err) 30 | } 31 | if err := sub.AutoUnsubscribe(1); err != nil { 32 | log.Fatal(err) 33 | } 34 | 35 | // [end unsubscribe_auto] 36 | } 37 | -------------------------------------------------------------------------------- /api-examples/sub_pending_limits/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/nats-io/nats.go" 7 | ) 8 | 9 | func main() { 10 | // [begin slow_pending_limits] 11 | nc, err := nats.Connect("demo.nats.io") 12 | if err != nil { 13 | log.Fatal(err) 14 | } 15 | defer nc.Close() 16 | 17 | // Subscribe 18 | sub1, err := nc.Subscribe("updates", func(m *nats.Msg) {}) 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | 23 | // Set limits of 1000 messages or 5MB, whichever comes first 24 | sub1.SetPendingLimits(1000, 5*1024*1024) 25 | 26 | // Subscribe 27 | sub2, err := nc.Subscribe("updates", func(m *nats.Msg) {}) 28 | if err != nil { 29 | log.Fatal(err) 30 | } 31 | 32 | // Set no limits for this subscription 33 | sub2.SetPendingLimits(-1, -1) 34 | 35 | // Close the connection 36 | nc.Close() 37 | // [end slow_pending_limits] 38 | } 39 | -------------------------------------------------------------------------------- /api-examples/subscribe_json/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "sync" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin subscribe_json] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | ec, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER) 18 | if err != nil { 19 | log.Fatal(err) 20 | } 21 | defer ec.Close() 22 | 23 | // Define the object 24 | type stock struct { 25 | Symbol string 26 | Price int 27 | } 28 | 29 | wg := sync.WaitGroup{} 30 | wg.Add(1) 31 | 32 | // Subscribe 33 | if _, err := ec.Subscribe("updates", func(s *stock) { 34 | log.Printf("Stock: %s - Price: %v", s.Symbol, s.Price) 35 | wg.Done() 36 | }); err != nil { 37 | log.Fatal(err) 38 | } 39 | 40 | // Wait for a message to come in 41 | wg.Wait() 42 | 43 | // [end subscribe_json] 44 | } 45 | -------------------------------------------------------------------------------- /api-examples/wildcard_tester/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin wildcard_tester] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | zoneID, err := time.LoadLocation("America/New_York") 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | now := time.Now() 23 | zoneDateTime := now.In(zoneID) 24 | formatted := zoneDateTime.String() 25 | 26 | nc.Publish("time.us.east", []byte(formatted)) 27 | nc.Publish("time.us.east.atlanta", []byte(formatted)) 28 | 29 | zoneID, err = time.LoadLocation("Europe/Warsaw") 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | zoneDateTime = now.In(zoneID) 34 | formatted = zoneDateTime.String() 35 | 36 | nc.Publish("time.eu.east", []byte(formatted)) 37 | nc.Publish("time.eu.east.warsaw", []byte(formatted)) 38 | 39 | // [end wildcard_tester] 40 | } 41 | -------------------------------------------------------------------------------- /api-examples/publish_with_reply/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "time" 6 | 7 | "github.com/nats-io/nats.go" 8 | ) 9 | 10 | func main() { 11 | // [begin publish_with_reply] 12 | nc, err := nats.Connect("demo.nats.io") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | defer nc.Close() 17 | 18 | // Create a unique subject name for replies. 19 | uniqueReplyTo := nats.NewInbox() 20 | 21 | // Listen for a single response 22 | sub, err := nc.SubscribeSync(uniqueReplyTo) 23 | if err != nil { 24 | log.Fatal(err) 25 | } 26 | 27 | // Send the request. 28 | // If processing is synchronous, use Request() which returns the response message. 29 | if err := nc.PublishRequest("time", uniqueReplyTo, nil); err != nil { 30 | log.Fatal(err) 31 | } 32 | 33 | // Read the reply 34 | msg, err := sub.NextMsg(time.Second) 35 | if err != nil { 36 | log.Fatal(err) 37 | } 38 | 39 | // Use the response 40 | log.Printf("Reply: %s", msg.Data) 41 | 42 | // [end publish_with_reply] 43 | } 44 | -------------------------------------------------------------------------------- /patterns/request-reply/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | [Request-Reply](http://www.enterpriseintegrationpatterns.com/patterns/messaging/RequestReply.html) 3 | 4 | When an application sends a request and expects a response from a receiver, create two channels one for the request and one for the response. 5 | 6 | # Request-Reply 7 | To demonstrate NATS request/reply. 8 | 9 | 1. Get and run nats-rply: 10 | ``` 11 | go get github.com/nats-io/go-nats-examples/tools/nats-rply 12 | nats-rply -s demo.nats.io subject "my response" 13 | ``` 14 | 1. Get and run nats-req: 15 | ``` 16 | go get github.com/nats-io/go-nats-examples/tools/nats-req 17 | nats-req -s demo.nats.io subject "my request" 18 | ``` 19 | 1. Verify requester output: 20 | ``` 21 | Published [subject] : 'my request' 22 | Received [_INBOX.5cE7rtqAFLWkhaLEawkBqL] : 'my response' 23 | ``` 24 | 1. Verify queue reply output: 25 | ``` 26 | Listening on [subject] 27 | [#1] Received on [subject]: 'my request' 28 | ``` 29 | 30 | Now that you've seen how it works, try running multiple `nats-rply` and sending multiple messages. For each request, a random queue responder will be selected and at most one response will be sent back to the client. 31 | -------------------------------------------------------------------------------- /patterns/publish-subscribe/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | [Publish Subscribe Channel](http://www.enterpriseintegrationpatterns.com/patterns/messaging/PublishSubscribeChannel.html) 3 | 4 | "A Publish-Subscribe Channel works like this: It has one input channel 5 | that splits into multiple output channels, one for each subscriber. 6 | When an event is published into the channel, the Publish-Subscribe 7 | Channel delivers a copy of the message to each of the output channels. 8 | Each output channel has only one subscriber, which is only allowed to 9 | consume a message once. In this way, each subscriber only gets the 10 | message (at-most in the case of gnatsd) once and consumed copies disappear from their channels. 11 | " 12 | 13 | # Publish / Subscribe 14 | To demonstrate NATS publish/subscribe. 15 | 16 | 1. Get and run nats-sub: 17 | ``` 18 | go get github.com/nats-io/go-nats-examples/tools/nats-sub 19 | nats-sub -s demo.nats.io some_subject 20 | ``` 21 | 2. Get and run nats-pub: 22 | ``` 23 | go get github.com/nats-io/go-nats-examples/tools/nats-pub 24 | nats-pub -s demo.nats.io some_subject message 25 | ``` 26 | 3. Verify publisher output: 27 | ``` 28 | Published [subject_name] : 'message' 29 | ``` 30 | 4. Verify subscriber output: 31 | ``` 32 | Listening on [subject_name] 33 | [#1] Received on [channel_name]: 'message' 34 | ``` 35 | 36 | 4. Optionally install your own server: 37 | ``` 38 | go get github.com/nats-io/nats-server; nats-server & 39 | ``` 40 | -------------------------------------------------------------------------------- /api-examples/drain_conn/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "sync" 6 | "time" 7 | 8 | "github.com/nats-io/nats.go" 9 | ) 10 | 11 | func main() { 12 | // [begin drain_conn] 13 | wg := sync.WaitGroup{} 14 | wg.Add(1) 15 | 16 | errCh := make(chan error, 1) 17 | 18 | // To simulate a timeout, you would set the DrainTimeout() 19 | // to a value less than the time spent in the message callback, 20 | // so say: nats.DrainTimeout(10*time.Millisecond). 21 | 22 | nc, err := nats.Connect("demo.nats.io", 23 | nats.DrainTimeout(10*time.Second), 24 | nats.ErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, err error) { 25 | errCh <- err 26 | }), 27 | nats.ClosedHandler(func(_ *nats.Conn) { 28 | wg.Done() 29 | })) 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | 34 | // Just to not collide using the demo server with other users. 35 | subject := nats.NewInbox() 36 | 37 | // Subscribe, but add some delay while processing. 38 | if _, err := nc.Subscribe(subject, func(_ *nats.Msg) { 39 | time.Sleep(200 * time.Millisecond) 40 | }); err != nil { 41 | log.Fatal(err) 42 | } 43 | 44 | // Publish a message 45 | if err := nc.Publish(subject, []byte("hello")); err != nil { 46 | log.Fatal(err) 47 | } 48 | 49 | // Drain the connection, which will close it when done. 50 | if err := nc.Drain(); err != nil { 51 | log.Fatal(err) 52 | } 53 | 54 | // Wait for the connection to be closed. 55 | wg.Wait() 56 | 57 | // Check if there was an error 58 | select { 59 | case e := <-errCh: 60 | log.Fatal(e) 61 | default: 62 | } 63 | 64 | // [end drain_conn] 65 | } 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://raw.githubusercontent.com/nats-io/nats-site/main/src/img/large-logo.png) 2 | 3 | # NATS - Go Examples and CLI Clients 4 | 5 | [Go](http://www.golang.org) examples and CLI clients for the [NATS messaging system](https://nats.io). 6 | 7 | [![License Apache 2](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) 8 | [![Build Status](https://travis-ci.org/nats-io/go-nats-examples.svg?branch=main)](http://travis-ci.org/nats-io/go-nats-examples) 9 | 10 | # Overview 11 | This repo contains go-gettable [nats.go](www.github.com/nats-io/nats.go) examples and client code as well as api examples from the documentation. 12 | 13 | Install your own server, or optionally utilize the [demo server](http://demo.nats.io:8222) 14 | 15 | 1. Get and run nats-sub: 16 | ``` 17 | go get github.com/nats-io/go-nats-examples/tools/nats-sub 18 | nats-sub -s demo.nats.io subject_name 19 | ``` 20 | 1. Get and run nats-pub: 21 | ``` 22 | go get github.com/nats-io/go-nats-examples/tools/nats-pub 23 | nats-pub -s demo.nats.io subject_name msg 24 | ``` 25 | 1. Verify publisher output: 26 | ``` 27 | Published [subject_name] : 'message' 28 | ``` 29 | 1. Verify subscriber output: 30 | ``` 31 | Listening on [subject_name] 32 | [#1] Received on [subject_name]: 'message' 33 | ``` 34 | 35 | # Patterns 36 | The patterns directory contains a listing of example messaging patterns: 37 | 38 | 1. [Publish/Subscribe](/patterns/publish-subscribe) 39 | 1. [Request/Reply](/patterns/request-reply) 40 | 1. [Competing Consumer](/patterns/competing-consumer/) 41 | -------------------------------------------------------------------------------- /api-examples/drain_sub/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "sync" 7 | "time" 8 | 9 | "github.com/nats-io/nats.go" 10 | ) 11 | 12 | func main() { 13 | // [begin drain_sub] 14 | 15 | nc, err := nats.Connect("demo.nats.io") 16 | if err != nil { 17 | log.Fatal(err) 18 | } 19 | defer nc.Close() 20 | 21 | done := sync.WaitGroup{} 22 | done.Add(1) 23 | 24 | count := 0 25 | errCh := make(chan error, 1) 26 | 27 | msgAfterDrain := "not this one" 28 | 29 | // Just to not collide using the demo server with other users. 30 | subject := nats.NewInbox() 31 | 32 | // This callback will process each message slowly 33 | sub, err := nc.Subscribe(subject, func(m *nats.Msg) { 34 | if string(m.Data) == msgAfterDrain { 35 | errCh <- fmt.Errorf("Should not have received this message") 36 | return 37 | } 38 | time.Sleep(100 * time.Millisecond) 39 | count++ 40 | if count == 2 { 41 | done.Done() 42 | } 43 | }) 44 | 45 | // Send 2 messages 46 | for i := 0; i < 2; i++ { 47 | nc.Publish(subject, []byte("hello")) 48 | } 49 | 50 | // Call Drain on the subscription. It unsubscribes but 51 | // wait for all pending messages to be processed. 52 | if err := sub.Drain(); err != nil { 53 | log.Fatal(err) 54 | } 55 | 56 | // Send one more message, this message should not be received 57 | nc.Publish(subject, []byte(msgAfterDrain)) 58 | 59 | // Wait for the subscription to have processed the 2 messages. 60 | done.Wait() 61 | 62 | // Now check that the 3rd message was not received 63 | select { 64 | case e := <-errCh: 65 | log.Fatal(e) 66 | case <-time.After(200 * time.Millisecond): 67 | // OK! 68 | } 69 | 70 | // [end drain_sub] 71 | } 72 | -------------------------------------------------------------------------------- /patterns/competing-consumer/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | [Competing Consumers](http://www.enterpriseintegrationpatterns.com/patterns/messaging/CompetingConsumers.html) 3 | 4 | "Competing Consumers are multiple consumers that are all created to receive messages from a single Point-to-Point Channel. When the channel delivers a message, any of the consumers could potentially receive it. The messaging system's implementation determines which consumer actually receives the message, but in effect the consumers compete with each other to be the receiver. Once a consumer receives a message, it can delegate to the rest of its application to help process the message. (This solution only works with Point-to-Point Channels; multiple consumers on a Publish-Subscribe Channel just create more copies of each message.)" 5 | 6 | 7 | # Steps 8 | 9 | 1. Run a [nats-server](http://www.github.com/nats-io/nats-server) or connect the NATS programs to the [demo server](http://demo.nats.io:8222), e.g. ` nats-pub -s demo.nats.io subject msg` 10 | 11 | ``` 12 | go get github.com/nats-io/nats-server; nats-server & 13 | ``` 14 | 15 | 1. Install the queue subscriber. 16 | 17 | ``` 18 | go get github.com/nats-io/go-nats-examples/tools/nats-qsub 19 | ``` 20 | 21 | 2. Run the first queue_group subscriber. 22 | 23 | ``` 24 | nats-qsub subject group 25 | ``` 26 | 27 | 3. In a separate terminal window, run the second queue_group subscriber. 28 | 29 | ``` 30 | nats-qsub subject group 31 | ``` 32 | 33 | 4. In a 3rd terminal window, send messages to the queue group. 34 | 35 | ``` 36 | go get github.com/nats-io/go-nats-examples/tools/nats-pub 37 | nats-pub subject msg-1 38 | nats-pub subject msg-2 39 | ``` 40 | 41 | 5. The nats-qsubs will process messages one at a time. -------------------------------------------------------------------------------- /releaser.yml: -------------------------------------------------------------------------------- 1 | project_name: go-nats-examples 2 | release: 3 | github: 4 | owner: nats-io 5 | name: go-nats-examples 6 | draft: true 7 | builds: 8 | - main: ./tools/nats-bench/nats-bench.go 9 | binary: nats-bench 10 | goos: 11 | - darwin 12 | - linux 13 | - windows 14 | goarch: 15 | - amd64 16 | - main: ./tools/nats-echo/nats-echo.go 17 | binary: nats-echo 18 | goos: 19 | - darwin 20 | - linux 21 | - windows 22 | goarch: 23 | - amd64 24 | - main: ./tools/nats-pub/nats-pub.go 25 | binary: nats-pub 26 | goos: 27 | - darwin 28 | - linux 29 | - windows 30 | goarch: 31 | - amd64 32 | - main: ./tools/nats-qsub/nats-qsub.go 33 | binary: nats-qsub 34 | goos: 35 | - darwin 36 | - linux 37 | - windows 38 | goarch: 39 | - amd64 40 | - main: ./tools/nats-req/nats-req.go 41 | binary: nats-req 42 | goos: 43 | - darwin 44 | - linux 45 | - windows 46 | goarch: 47 | - amd64 48 | - main: ./tools/nats-rply/nats-rply.go 49 | binary: nats-rply 50 | goos: 51 | - darwin 52 | - linux 53 | - windows 54 | goarch: 55 | - amd64 56 | - main: ./tools/nats-sub/nats-sub.go 57 | binary: nats-sub 58 | goos: 59 | - darwin 60 | - linux 61 | - windows 62 | goarch: 63 | - amd64 64 | - main: ./tools/stan-pub/stan-pub.go 65 | binary: stan-pub 66 | goos: 67 | - darwin 68 | - linux 69 | - windows 70 | goarch: 71 | - amd64 72 | - main: ./tools/stan-sub/stan-sub.go 73 | binary: stan-sub 74 | goos: 75 | - darwin 76 | - linux 77 | - windows 78 | goarch: 79 | - amd64 80 | 81 | dist: build 82 | 83 | archive: 84 | wrap_in_directory: true 85 | name_template: '{{ .ProjectName }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' 86 | format: zip 87 | 88 | checksum: 89 | name_template: '{{ .ProjectName }}-v{{ .Version }}-checksums.txt' 90 | 91 | snapshot: 92 | name_template: 'dev' 93 | 94 | -------------------------------------------------------------------------------- /api-examples/resources/certs/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFPDCCAySgAwIBAgIJAO+k4G7bNTypMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD 3 | VQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xEzAR 4 | BgNVBAoTCkFwY2VyYSBJbmMxEDAOBgNVBAsTB25hdHMuaW8xEjAQBgNVBAMTCWxv 5 | Y2FsaG9zdDEcMBoGCSqGSIb3DQEJARYNZGVyZWtAbmF0cy5pbzAeFw0xNTExMDUy 6 | MzEwNDdaFw0xOTExMDQyMzEwNDdaMBYxFDASBgNVBAMTC25hdHMtY2xpZW50MIIC 7 | IjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEArgLxszD5/vDrDUwwIEgQx9I0 8 | J/H6MXPO0Tj9D2BnR+nwjCe9M03fsq4Il96BVzoaAiAQD1r4NyAX2adKydlnE3/m 9 | bUFiSVHErJceEi9aSs+WlLdmKEgU2qrsIal9KzthlI786qtjb7OFSCxP14R4xYA5 10 | dlZXhJ9oUuFhVTdaVmRMzWuWj8RbBx8VptSZ0f7Q+Uv8GuB0kyiVkv6GYcH/IWuI 11 | 7jnM0QcVWBmxJfWmqd0yx/FLlX/LRXqdiyoFSIlMaP0VOwto3uEhAoBk83Z+/zrZ 12 | Brymx1Nnz3qzTCf8/mdMjPuWibXDTLbo0/Kf6neHs6wxx8irb1ZfIwhn8grXTcgd 13 | rg9bfcyyUOBey7QXiedpU0xFqoH26E+Aq+CV4R56i1sJKsSYEGu8O69H8zu5dgan 14 | LZRhcCHcZhMe7Nbiu5BcuOW4r3rGDMTLXSugEX91iy5jJaYmRjtPN5imQIJtf+GK 15 | Vq7YLv4MQV6R3xRiZXaocCae1qzIMc4kxCKvZTmxuJsvIUPjNnGumwbjV/a2fLFX 16 | 9tMqUKyEmiPtFtqNH/kmkHCQ5FGYIIj3wGuD5yWfK5Tr3iHOdNJoNNPgPBg9tMRw 17 | j3+W8+uyBxc+FUEb8a9m3R4VmAYyiqgzCA0DWZBF1fOYLWfRnwS5OBKiP4OUlUEb 18 | YZUEzfvDbLOwQrb123cCAwEAAaMXMBUwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDQYJ 19 | KoZIhvcNAQELBQADggIBACNKPbvaXwl5rRTqFw37Am1r6e+LkUg9dFogSwXDnuT/ 20 | RRZJi5MHsC5MUOkHB28lTmPwkAogs+LBmKrM0Npzk6OPkT/LCgKqpVoz2Tc1nGMI 21 | Jy8jxPYogMmDCOhoEoC7zsWABMLiX5KDAuKommk61w7AwKu4kK198ngwbfF2fzdH 22 | 1DUGID7iV4fyPGI+pCU3Ullv51c5xkhqjVy1JYdYc0+s6rFyVTibSABa7PfHE2ML 23 | A+cNFWoKQhugVHQU7qYvuWvnEqZro2T6nmSmpK3oOaUgVnDuY2q4JwiMbZAtuyD7 24 | 8LFwCim49WzgYcfs/BwKlUrTV/QBYurruHWjElZzwA39/ZlbnOjJJ85j/YqxR+4S 25 | fK/KktegyrPJU3fxdl2+77zVlfgzxaQ//58vx5LgXWhl2KeHyakeD0jQFVn1R7GD 26 | bynAlHlSOr+nGkwP2WVqXKf+l/gb/gUEY7bC8fCVRCctkcK+smEl+sIKH3O9JY8l 27 | rBWjOXkMY91ZDh77hfTNni/s2/DGAoNrEft8rgu3/NPxhCTfQH3ranCryth9mF6I 28 | qsOFr5/81WGKqU+Kec8st/RSU2vBjBp41HILAEEhUiB6prhc9B3+exwkvQSPz22W 29 | PIvhkzqeOYRoEDE2bWGC1ukd818qvQp618eLBmJSvwGh4YfUcmgqHaEk2NjoPIMV 30 | -----END CERTIFICATE----- 31 | -------------------------------------------------------------------------------- /tools/nats-pub/nats-pub.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012-2019 The NATS Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | "flag" 18 | "log" 19 | "os" 20 | 21 | "github.com/nats-io/nats.go" 22 | ) 23 | 24 | // NOTE: Can test with demo servers. 25 | // nats-pub -s demo.nats.io 26 | // nats-pub -s demo.nats.io:4443 (TLS version) 27 | 28 | func usage() { 29 | log.Printf("Usage: nats-pub [-s server] [-creds file] \n") 30 | flag.PrintDefaults() 31 | } 32 | 33 | func showUsageAndExit(exitcode int) { 34 | usage() 35 | os.Exit(exitcode) 36 | } 37 | 38 | func main() { 39 | var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)") 40 | var userCreds = flag.String("creds", "", "User Credentials File") 41 | var showHelp = flag.Bool("h", false, "Show help message") 42 | 43 | log.SetFlags(0) 44 | flag.Usage = usage 45 | flag.Parse() 46 | 47 | if *showHelp { 48 | showUsageAndExit(0) 49 | } 50 | 51 | args := flag.Args() 52 | if len(args) != 2 { 53 | showUsageAndExit(1) 54 | } 55 | 56 | // Connect Options. 57 | opts := []nats.Option{nats.Name("NATS Sample Publisher")} 58 | 59 | // Use UserCredentials 60 | if *userCreds != "" { 61 | opts = append(opts, nats.UserCredentials(*userCreds)) 62 | } 63 | 64 | // Connect to NATS 65 | nc, err := nats.Connect(*urls, opts...) 66 | if err != nil { 67 | log.Fatal(err) 68 | } 69 | defer nc.Close() 70 | subj, msg := args[0], []byte(args[1]) 71 | 72 | nc.Publish(subj, msg) 73 | nc.Flush() 74 | 75 | if err := nc.LastError(); err != nil { 76 | log.Fatal(err) 77 | } else { 78 | log.Printf("Published [%s] : '%s'\n", subj, msg) 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tools/nats-req/nats-req.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012-2019 The NATS Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | "flag" 18 | "log" 19 | "os" 20 | "time" 21 | 22 | "github.com/nats-io/nats.go" 23 | ) 24 | 25 | // NOTE: Can test with demo servers. 26 | // nats-req -s demo.nats.io 27 | // nats-req -s demo.nats.io:4443 (TLS version) 28 | 29 | func usage() { 30 | log.Printf("Usage: nats-req [-s server] [-creds file] \n") 31 | flag.PrintDefaults() 32 | } 33 | 34 | func showUsageAndExit(exitcode int) { 35 | usage() 36 | os.Exit(exitcode) 37 | } 38 | 39 | func main() { 40 | var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)") 41 | var userCreds = flag.String("creds", "", "User Credentials File") 42 | var showHelp = flag.Bool("h", false, "Show help message") 43 | 44 | log.SetFlags(0) 45 | flag.Usage = usage 46 | flag.Parse() 47 | 48 | if *showHelp { 49 | showUsageAndExit(0) 50 | } 51 | 52 | args := flag.Args() 53 | if len(args) < 2 { 54 | showUsageAndExit(1) 55 | } 56 | 57 | // Connect Options. 58 | opts := []nats.Option{nats.Name("NATS Sample Requestor")} 59 | 60 | // Use UserCredentials 61 | if *userCreds != "" { 62 | opts = append(opts, nats.UserCredentials(*userCreds)) 63 | } 64 | 65 | // Connect to NATS 66 | nc, err := nats.Connect(*urls, opts...) 67 | if err != nil { 68 | log.Fatal(err) 69 | } 70 | defer nc.Close() 71 | subj, payload := args[0], []byte(args[1]) 72 | 73 | msg, err := nc.Request(subj, payload, 2*time.Second) 74 | if err != nil { 75 | if nc.LastError() != nil { 76 | log.Fatalf("%v for request", nc.LastError()) 77 | } 78 | log.Fatalf("%v for request", err) 79 | } 80 | 81 | log.Printf("Published [%s] : '%s'", subj, payload) 82 | log.Printf("Received [%v] : '%s'", msg.Subject, string(msg.Data)) 83 | } 84 | -------------------------------------------------------------------------------- /api-examples/resources/certs/ca.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | 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 37 | +Svp 38 | -----END CERTIFICATE----- 39 | -------------------------------------------------------------------------------- /api-examples/resources/certs/key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | 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 51 | -----END RSA PRIVATE KEY----- 52 | -------------------------------------------------------------------------------- /tools/nats-sub/nats-sub.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012-2019 The NATS Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | "flag" 18 | "log" 19 | "os" 20 | "runtime" 21 | "time" 22 | 23 | "github.com/nats-io/nats.go" 24 | ) 25 | 26 | // NOTE: Can test with demo servers. 27 | // nats-sub -s demo.nats.io 28 | // nats-sub -s demo.nats.io:4443 (TLS version) 29 | 30 | func usage() { 31 | log.Printf("Usage: nats-sub [-s server] [-creds file] [-t] \n") 32 | flag.PrintDefaults() 33 | } 34 | 35 | func showUsageAndExit(exitcode int) { 36 | usage() 37 | os.Exit(exitcode) 38 | } 39 | 40 | func printMsg(m *nats.Msg, i int) { 41 | log.Printf("[#%d] Received on [%s]: '%s'", i, m.Subject, string(m.Data)) 42 | } 43 | 44 | func main() { 45 | var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)") 46 | var userCreds = flag.String("creds", "", "User Credentials File") 47 | var showTime = flag.Bool("t", false, "Display timestamps") 48 | var showHelp = flag.Bool("h", false, "Show help message") 49 | 50 | log.SetFlags(0) 51 | flag.Usage = usage 52 | flag.Parse() 53 | 54 | if *showHelp { 55 | showUsageAndExit(0) 56 | } 57 | 58 | args := flag.Args() 59 | if len(args) != 1 { 60 | showUsageAndExit(1) 61 | } 62 | 63 | // Connect Options. 64 | opts := []nats.Option{nats.Name("NATS Sample Subscriber")} 65 | opts = setupConnOptions(opts) 66 | 67 | // Use UserCredentials 68 | if *userCreds != "" { 69 | opts = append(opts, nats.UserCredentials(*userCreds)) 70 | } 71 | 72 | // Connect to NATS 73 | nc, err := nats.Connect(*urls, opts...) 74 | if err != nil { 75 | log.Fatal(err) 76 | } 77 | 78 | subj, i := args[0], 0 79 | 80 | nc.Subscribe(subj, func(msg *nats.Msg) { 81 | i += 1 82 | printMsg(msg, i) 83 | }) 84 | nc.Flush() 85 | 86 | if err := nc.LastError(); err != nil { 87 | log.Fatal(err) 88 | } 89 | 90 | log.Printf("Listening on [%s]", subj) 91 | if *showTime { 92 | log.SetFlags(log.LstdFlags) 93 | } 94 | 95 | runtime.Goexit() 96 | } 97 | 98 | func setupConnOptions(opts []nats.Option) []nats.Option { 99 | totalWait := 10 * time.Minute 100 | reconnectDelay := time.Second 101 | 102 | opts = append(opts, nats.ReconnectWait(reconnectDelay)) 103 | opts = append(opts, nats.MaxReconnects(int(totalWait/reconnectDelay))) 104 | opts = append(opts, nats.DisconnectHandler(func(nc *nats.Conn) { 105 | log.Printf("Disconnected: will attempt reconnects for %.0fm", totalWait.Minutes()) 106 | })) 107 | opts = append(opts, nats.ReconnectHandler(func(nc *nats.Conn) { 108 | log.Printf("Reconnected [%s]", nc.ConnectedUrl()) 109 | })) 110 | opts = append(opts, nats.ClosedHandler(func(nc *nats.Conn) { 111 | log.Fatalf("Exiting: %v", nc.LastError()) 112 | })) 113 | return opts 114 | } 115 | -------------------------------------------------------------------------------- /tools/nats-qsub/nats-qsub.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012-2019 The NATS Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | "flag" 18 | "log" 19 | "os" 20 | "os/signal" 21 | "time" 22 | 23 | "github.com/nats-io/nats.go" 24 | ) 25 | 26 | // NOTE: Can test with demo servers. 27 | // nats-qsub -s demo.nats.io 28 | // nats-qsub -s demo.nats.io:4443 (TLS version) 29 | 30 | func usage() { 31 | log.Printf("Usage: nats-qsub [-s server] [-creds file] [-t] \n") 32 | flag.PrintDefaults() 33 | } 34 | 35 | func showUsageAndExit(exitcode int) { 36 | usage() 37 | os.Exit(exitcode) 38 | } 39 | 40 | func printMsg(m *nats.Msg, i int) { 41 | log.Printf("[#%d] Received on [%s] Queue[%s] Pid[%d]: '%s'", i, m.Subject, m.Sub.Queue, os.Getpid(), string(m.Data)) 42 | } 43 | 44 | func main() { 45 | var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)") 46 | var userCreds = flag.String("creds", "", "User Credentials File") 47 | var showTime = flag.Bool("t", false, "Display timestamps") 48 | var showHelp = flag.Bool("h", false, "Show help message") 49 | 50 | log.SetFlags(0) 51 | flag.Usage = usage 52 | flag.Parse() 53 | 54 | if *showHelp { 55 | showUsageAndExit(0) 56 | } 57 | 58 | args := flag.Args() 59 | if len(args) != 2 { 60 | showUsageAndExit(1) 61 | } 62 | 63 | // Connect Options. 64 | opts := []nats.Option{nats.Name("NATS Sample Queue Subscriber")} 65 | opts = setupConnOptions(opts) 66 | 67 | // Use UserCredentials 68 | if *userCreds != "" { 69 | opts = append(opts, nats.UserCredentials(*userCreds)) 70 | } 71 | 72 | // Connect to NATS 73 | nc, err := nats.Connect(*urls, opts...) 74 | if err != nil { 75 | log.Fatal(err) 76 | } 77 | 78 | subj, queue, i := args[0], args[1], 0 79 | 80 | nc.QueueSubscribe(subj, queue, func(msg *nats.Msg) { 81 | i++ 82 | printMsg(msg, i) 83 | }) 84 | nc.Flush() 85 | 86 | if err := nc.LastError(); err != nil { 87 | log.Fatal(err) 88 | } 89 | 90 | log.Printf("Listening on [%s]", subj) 91 | if *showTime { 92 | log.SetFlags(log.LstdFlags) 93 | } 94 | 95 | // Setup the interrupt handler to drain so we don't miss 96 | // requests when scaling down. 97 | c := make(chan os.Signal, 1) 98 | signal.Notify(c, os.Interrupt) 99 | <-c 100 | log.Println() 101 | log.Printf("Draining...") 102 | nc.Drain() 103 | log.Fatalf("Exiting") 104 | } 105 | 106 | func setupConnOptions(opts []nats.Option) []nats.Option { 107 | totalWait := 10 * time.Minute 108 | reconnectDelay := time.Second 109 | 110 | opts = append(opts, nats.ReconnectWait(reconnectDelay)) 111 | opts = append(opts, nats.MaxReconnects(int(totalWait/reconnectDelay))) 112 | opts = append(opts, nats.DisconnectHandler(func(nc *nats.Conn) { 113 | log.Printf("Disconnected: will attempt reconnects for %.0fm", totalWait.Minutes()) 114 | })) 115 | opts = append(opts, nats.ReconnectHandler(func(nc *nats.Conn) { 116 | log.Printf("Reconnected [%s]", nc.ConnectedUrl()) 117 | })) 118 | opts = append(opts, nats.ClosedHandler(func(nc *nats.Conn) { 119 | log.Fatalf("Exiting: %v", nc.LastError()) 120 | })) 121 | return opts 122 | } 123 | -------------------------------------------------------------------------------- /tools/nats-rply/nats-rply.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012-2019 The NATS Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | "flag" 18 | "log" 19 | "os" 20 | "os/signal" 21 | "time" 22 | 23 | "github.com/nats-io/nats.go" 24 | ) 25 | 26 | // NOTE: Can test with demo servers. 27 | // nats-rply -s demo.nats.io 28 | // nats-rply -s demo.nats.io:4443 (TLS version) 29 | 30 | func usage() { 31 | log.Printf("Usage: nats-rply [-s server] [-creds file] [-t] [-q queue] \n") 32 | flag.PrintDefaults() 33 | } 34 | 35 | func showUsageAndExit(exitcode int) { 36 | usage() 37 | os.Exit(exitcode) 38 | } 39 | 40 | func printMsg(m *nats.Msg, i int) { 41 | log.Printf("[#%d] Received on [%s]: '%s'\n", i, m.Subject, string(m.Data)) 42 | } 43 | 44 | func main() { 45 | var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)") 46 | var userCreds = flag.String("creds", "", "User Credentials File") 47 | var showTime = flag.Bool("t", false, "Display timestamps") 48 | var queueName = flag.String("q", "NATS-RPLY-22", "Queue Group Name") 49 | var showHelp = flag.Bool("h", false, "Show help message") 50 | 51 | log.SetFlags(0) 52 | flag.Usage = usage 53 | flag.Parse() 54 | 55 | if *showHelp { 56 | showUsageAndExit(0) 57 | } 58 | 59 | args := flag.Args() 60 | if len(args) < 2 { 61 | showUsageAndExit(1) 62 | } 63 | 64 | // Connect Options. 65 | opts := []nats.Option{nats.Name("NATS Sample Responder")} 66 | opts = setupConnOptions(opts) 67 | 68 | // Use UserCredentials 69 | if *userCreds != "" { 70 | opts = append(opts, nats.UserCredentials(*userCreds)) 71 | } 72 | 73 | // Connect to NATS 74 | nc, err := nats.Connect(*urls, opts...) 75 | if err != nil { 76 | log.Fatal(err) 77 | } 78 | 79 | subj, reply, i := args[0], args[1], 0 80 | 81 | nc.QueueSubscribe(subj, *queueName, func(msg *nats.Msg) { 82 | i++ 83 | printMsg(msg, i) 84 | msg.Respond([]byte(reply)) 85 | }) 86 | nc.Flush() 87 | 88 | if err := nc.LastError(); err != nil { 89 | log.Fatal(err) 90 | } 91 | 92 | log.Printf("Listening on [%s]", subj) 93 | if *showTime { 94 | log.SetFlags(log.LstdFlags) 95 | } 96 | 97 | // Setup the interrupt handler to drain so we don't miss 98 | // requests when scaling down. 99 | c := make(chan os.Signal, 1) 100 | signal.Notify(c, os.Interrupt) 101 | <-c 102 | log.Println() 103 | log.Printf("Draining...") 104 | nc.Drain() 105 | log.Fatalf("Exiting") 106 | } 107 | 108 | func setupConnOptions(opts []nats.Option) []nats.Option { 109 | totalWait := 10 * time.Minute 110 | reconnectDelay := time.Second 111 | 112 | opts = append(opts, nats.ReconnectWait(reconnectDelay)) 113 | opts = append(opts, nats.MaxReconnects(int(totalWait/reconnectDelay))) 114 | opts = append(opts, nats.DisconnectHandler(func(nc *nats.Conn) { 115 | log.Printf("Disconnected: will attempt reconnects for %.0fm", totalWait.Minutes()) 116 | })) 117 | opts = append(opts, nats.ReconnectHandler(func(nc *nats.Conn) { 118 | log.Printf("Reconnected [%s]", nc.ConnectedUrl()) 119 | })) 120 | opts = append(opts, nats.ClosedHandler(func(nc *nats.Conn) { 121 | log.Fatalf("Exiting: %v", nc.LastError()) 122 | })) 123 | return opts 124 | } 125 | -------------------------------------------------------------------------------- /tools/stan-pub/stan-pub.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016-2018 The NATS Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | "flag" 18 | "fmt" 19 | "log" 20 | "os" 21 | "sync" 22 | "time" 23 | 24 | "github.com/nats-io/stan.go" 25 | ) 26 | 27 | var usageStr = ` 28 | Usage: stan-pub [options] 29 | 30 | Options: 31 | -s, --server NATS Streaming server URL(s) 32 | -c, --cluster NATS Streaming cluster name 33 | -id,--clientid NATS Streaming client ID 34 | -a, --async Asynchronous publish mode 35 | ` 36 | 37 | // NOTE: Use tls scheme for TLS, e.g. stan-pub -s tls://demo.nats.io:4443 foo hello 38 | func usage() { 39 | fmt.Printf("%s\n", usageStr) 40 | os.Exit(0) 41 | } 42 | 43 | func main() { 44 | var clusterID string 45 | var clientID string 46 | var async bool 47 | var URL string 48 | 49 | flag.StringVar(&URL, "s", stan.DefaultNatsURL, "The nats server URLs (separated by comma)") 50 | flag.StringVar(&URL, "server", stan.DefaultNatsURL, "The nats server URLs (separated by comma)") 51 | flag.StringVar(&clusterID, "c", "test-cluster", "The NATS Streaming cluster ID") 52 | flag.StringVar(&clusterID, "cluster", "test-cluster", "The NATS Streaming cluster ID") 53 | flag.StringVar(&clientID, "id", "stan-pub", "The NATS Streaming client ID to connect with") 54 | flag.StringVar(&clientID, "clientid", "stan-pub", "The NATS Streaming client ID to connect with") 55 | flag.BoolVar(&async, "a", false, "Publish asynchronously") 56 | flag.BoolVar(&async, "async", false, "Publish asynchronously") 57 | 58 | log.SetFlags(0) 59 | flag.Usage = usage 60 | flag.Parse() 61 | 62 | args := flag.Args() 63 | 64 | if len(args) < 1 { 65 | usage() 66 | } 67 | 68 | sc, err := stan.Connect(clusterID, clientID, stan.NatsURL(URL)) 69 | if err != nil { 70 | log.Fatalf("Can't connect: %v.\nMake sure a NATS Streaming Server is running at: %s", err, URL) 71 | } 72 | defer sc.Close() 73 | 74 | subj, msg := args[0], []byte(args[1]) 75 | 76 | ch := make(chan bool) 77 | var glock sync.Mutex 78 | var guid string 79 | acb := func(lguid string, err error) { 80 | glock.Lock() 81 | log.Printf("Received ACK for guid %s\n", lguid) 82 | defer glock.Unlock() 83 | if err != nil { 84 | log.Fatalf("Error in server ack for guid %s: %v\n", lguid, err) 85 | } 86 | if lguid != guid { 87 | log.Fatalf("Expected a matching guid in ack callback, got %s vs %s\n", lguid, guid) 88 | } 89 | ch <- true 90 | } 91 | 92 | if !async { 93 | err = sc.Publish(subj, msg) 94 | if err != nil { 95 | log.Fatalf("Error during publish: %v\n", err) 96 | } 97 | log.Printf("Published [%s] : '%s'\n", subj, msg) 98 | } else { 99 | glock.Lock() 100 | guid, err = sc.PublishAsync(subj, msg, acb) 101 | if err != nil { 102 | log.Fatalf("Error during async publish: %v\n", err) 103 | } 104 | glock.Unlock() 105 | if guid == "" { 106 | log.Fatal("Expected non-empty guid to be returned.") 107 | } 108 | log.Printf("Published [%s] : '%s' [guid: %s]\n", subj, msg, guid) 109 | 110 | select { 111 | case <-ch: 112 | break 113 | case <-time.After(5 * time.Second): 114 | log.Fatal("timeout") 115 | } 116 | 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /tools/nats-echo/nats-echo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2019 The NATS Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | "encoding/json" 18 | "flag" 19 | "fmt" 20 | "io/ioutil" 21 | "log" 22 | "net/http" 23 | "os" 24 | "os/signal" 25 | "runtime" 26 | "syscall" 27 | "time" 28 | 29 | "github.com/nats-io/nats.go" 30 | ) 31 | 32 | // NOTE: Can test with demo servers. 33 | // nats-echo -s demo.nats.io 34 | // nats-echo -s demo.nats.io:4443 (TLS version) 35 | 36 | func usage() { 37 | log.Printf("Usage: nats-echo [-s server] [-creds file] [-t] \n") 38 | flag.PrintDefaults() 39 | } 40 | 41 | func showUsageAndExit(exitcode int) { 42 | usage() 43 | os.Exit(exitcode) 44 | } 45 | 46 | func printMsg(m *nats.Msg, i int) { 47 | log.Printf("[#%d] Echoing to [%s]: %q", i, m.Reply, m.Data) 48 | } 49 | 50 | func main() { 51 | var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)") 52 | var userCreds = flag.String("creds", "", "User Credentials File") 53 | var showTime = flag.Bool("t", false, "Display timestamps") 54 | var showHelp = flag.Bool("h", false, "Show help message") 55 | var geoloc = flag.Bool("geo", false, "Display geo location of echo service") 56 | var geo string 57 | 58 | log.SetFlags(0) 59 | flag.Usage = usage 60 | flag.Parse() 61 | 62 | if *showHelp { 63 | showUsageAndExit(0) 64 | } 65 | 66 | args := flag.Args() 67 | if len(args) != 1 { 68 | showUsageAndExit(1) 69 | } 70 | 71 | // Lookup geo if requested 72 | if *geoloc { 73 | geo = lookupGeo() 74 | } 75 | // Connect Options. 76 | opts := []nats.Option{nats.Name("NATS Echo Service")} 77 | opts = setupConnOptions(opts) 78 | 79 | // Use UserCredentials 80 | if *userCreds != "" { 81 | opts = append(opts, nats.UserCredentials(*userCreds)) 82 | } 83 | 84 | // Connect to NATS 85 | nc, err := nats.Connect(*urls, opts...) 86 | if err != nil { 87 | log.Fatal(err) 88 | } 89 | 90 | subj, i := args[0], 0 91 | 92 | nc.QueueSubscribe(subj, "echo", func(msg *nats.Msg) { 93 | i++ 94 | if msg.Reply != "" { 95 | printMsg(msg, i) 96 | // Just echo back what they sent us. 97 | if geo != "" { 98 | m := fmt.Sprintf("[%s]: %q", geo, msg.Data) 99 | nc.Publish(msg.Reply, []byte(m)) 100 | } else { 101 | nc.Publish(msg.Reply, msg.Data) 102 | } 103 | } 104 | }) 105 | nc.Flush() 106 | 107 | if err := nc.LastError(); err != nil { 108 | log.Fatal(err) 109 | } 110 | 111 | log.Printf("Echo Service listening on [%s]\n", subj) 112 | 113 | // Now handle signal to terminate so we cam drain on exit. 114 | c := make(chan os.Signal, 1) 115 | signal.Notify(c, syscall.SIGINT) 116 | 117 | go func() { 118 | // Wait for signal 119 | <-c 120 | log.Printf("") 121 | nc.Drain() 122 | }() 123 | 124 | if *showTime { 125 | log.SetFlags(log.LstdFlags) 126 | } 127 | 128 | runtime.Goexit() 129 | } 130 | 131 | func setupConnOptions(opts []nats.Option) []nats.Option { 132 | totalWait := 10 * time.Minute 133 | reconnectDelay := time.Second 134 | 135 | opts = append(opts, nats.ReconnectWait(reconnectDelay)) 136 | opts = append(opts, nats.MaxReconnects(int(totalWait/reconnectDelay))) 137 | opts = append(opts, nats.DisconnectHandler(func(nc *nats.Conn) { 138 | if !nc.IsClosed() { 139 | log.Printf("Disconnected: will attempt reconnects for %.0fm", totalWait.Minutes()) 140 | } 141 | })) 142 | opts = append(opts, nats.ReconnectHandler(func(nc *nats.Conn) { 143 | log.Printf("Reconnected [%s]", nc.ConnectedUrl()) 144 | })) 145 | opts = append(opts, nats.ClosedHandler(func(nc *nats.Conn) { 146 | if !nc.IsClosed() { 147 | log.Fatal("Exiting: no servers available") 148 | } else { 149 | log.Fatal("Exiting") 150 | } 151 | })) 152 | return opts 153 | } 154 | 155 | // We only want region, country 156 | type geo struct { 157 | // There are others.. 158 | Region string 159 | Country string 160 | } 161 | 162 | // lookup our current region and country.. 163 | func lookupGeo() string { 164 | c := &http.Client{Timeout: 2 * time.Second} 165 | resp, err := c.Get("https://ipinfo.io") 166 | if err != nil || resp == nil { 167 | log.Fatalf("Could not retrive geo location data: %v", err) 168 | } 169 | defer resp.Body.Close() 170 | body, _ := ioutil.ReadAll(resp.Body) 171 | g := geo{} 172 | if err := json.Unmarshal(body, &g); err != nil { 173 | log.Fatalf("Error unmarshalling geo: %v", err) 174 | } 175 | return g.Region + ", " + g.Country 176 | } 177 | -------------------------------------------------------------------------------- /tools/nats-bench/nats-bench.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 The NATS Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | "flag" 18 | "fmt" 19 | "io/ioutil" 20 | "log" 21 | "os" 22 | "sync" 23 | "time" 24 | 25 | "github.com/nats-io/nats.go" 26 | "github.com/nats-io/nats.go/bench" 27 | ) 28 | 29 | // Some sane defaults 30 | const ( 31 | DefaultNumMsgs = 100000 32 | DefaultNumPubs = 1 33 | DefaultNumSubs = 0 34 | DefaultMessageSize = 128 35 | ) 36 | 37 | func usage() { 38 | log.Printf("Usage: nats-bench [-s server (%s)] [--tls] [-np NUM_PUBLISHERS] [-ns NUM_SUBSCRIBERS] [-n NUM_MSGS] [-ms MESSAGE_SIZE] [-csv csvfile] \n", nats.DefaultURL) 39 | flag.PrintDefaults() 40 | } 41 | 42 | func showUsageAndExit(exitcode int) { 43 | usage() 44 | os.Exit(exitcode) 45 | } 46 | 47 | var benchmark *bench.Benchmark 48 | 49 | func main() { 50 | var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)") 51 | var tls = flag.Bool("tls", false, "Use TLS Secure Connection") 52 | var numPubs = flag.Int("np", DefaultNumPubs, "Number of Concurrent Publishers") 53 | var numSubs = flag.Int("ns", DefaultNumSubs, "Number of Concurrent Subscribers") 54 | var numMsgs = flag.Int("n", DefaultNumMsgs, "Number of Messages to Publish") 55 | var msgSize = flag.Int("ms", DefaultMessageSize, "Size of the message.") 56 | var csvFile = flag.String("csv", "", "Save bench data to csv file") 57 | var userCreds = flag.String("creds", "", "User Credentials File") 58 | var showHelp = flag.Bool("h", false, "Show help message") 59 | 60 | log.SetFlags(0) 61 | flag.Usage = usage 62 | flag.Parse() 63 | 64 | if *showHelp { 65 | showUsageAndExit(0) 66 | } 67 | 68 | args := flag.Args() 69 | if len(args) != 1 { 70 | showUsageAndExit(1) 71 | } 72 | 73 | if *numMsgs <= 0 { 74 | log.Fatal("Number of messages should be greater than zero.") 75 | } 76 | 77 | // Connect Options. 78 | opts := []nats.Option{nats.Name("NATS Benchmark")} 79 | 80 | // Use UserCredentials 81 | if *userCreds != "" { 82 | opts = append(opts, nats.UserCredentials(*userCreds)) 83 | } 84 | 85 | // Use TLS specified 86 | if *tls { 87 | opts = append(opts, nats.Secure(nil)) 88 | } 89 | 90 | benchmark = bench.NewBenchmark("NATS", *numSubs, *numPubs) 91 | 92 | var startwg sync.WaitGroup 93 | var donewg sync.WaitGroup 94 | 95 | donewg.Add(*numPubs + *numSubs) 96 | 97 | // Run Subscribers first 98 | startwg.Add(*numSubs) 99 | for i := 0; i < *numSubs; i++ { 100 | nc, err := nats.Connect(*urls, opts...) 101 | if err != nil { 102 | log.Fatalf("Can't connect: %v\n", err) 103 | } 104 | defer nc.Close() 105 | 106 | go runSubscriber(nc, &startwg, &donewg, *numMsgs, *msgSize) 107 | } 108 | startwg.Wait() 109 | 110 | // Now Publishers 111 | startwg.Add(*numPubs) 112 | pubCounts := bench.MsgsPerClient(*numMsgs, *numPubs) 113 | for i := 0; i < *numPubs; i++ { 114 | nc, err := nats.Connect(*urls, opts...) 115 | if err != nil { 116 | log.Fatalf("Can't connect: %v\n", err) 117 | } 118 | defer nc.Close() 119 | 120 | go runPublisher(nc, &startwg, &donewg, pubCounts[i], *msgSize) 121 | } 122 | 123 | log.Printf("Starting benchmark [msgs=%d, msgsize=%d, pubs=%d, subs=%d]\n", *numMsgs, *msgSize, *numPubs, *numSubs) 124 | 125 | startwg.Wait() 126 | donewg.Wait() 127 | 128 | benchmark.Close() 129 | 130 | fmt.Print(benchmark.Report()) 131 | 132 | if len(*csvFile) > 0 { 133 | csv := benchmark.CSV() 134 | ioutil.WriteFile(*csvFile, []byte(csv), 0644) 135 | fmt.Printf("Saved metric data in csv file %s\n", *csvFile) 136 | } 137 | } 138 | 139 | func runPublisher(nc *nats.Conn, startwg, donewg *sync.WaitGroup, numMsgs int, msgSize int) { 140 | startwg.Done() 141 | 142 | args := flag.Args() 143 | subj := args[0] 144 | var msg []byte 145 | if msgSize > 0 { 146 | msg = make([]byte, msgSize) 147 | } 148 | 149 | start := time.Now() 150 | 151 | for i := 0; i < numMsgs; i++ { 152 | nc.Publish(subj, msg) 153 | } 154 | nc.Flush() 155 | benchmark.AddPubSample(bench.NewSample(numMsgs, msgSize, start, time.Now(), nc)) 156 | 157 | donewg.Done() 158 | } 159 | 160 | func runSubscriber(nc *nats.Conn, startwg, donewg *sync.WaitGroup, numMsgs int, msgSize int) { 161 | args := flag.Args() 162 | subj := args[0] 163 | 164 | received := 0 165 | ch := make(chan time.Time, 2) 166 | sub, _ := nc.Subscribe(subj, func(msg *nats.Msg) { 167 | received++ 168 | if received == 1 { 169 | ch <- time.Now() 170 | } 171 | if received >= numMsgs { 172 | ch <- time.Now() 173 | } 174 | }) 175 | sub.SetPendingLimits(-1, -1) 176 | nc.Flush() 177 | startwg.Done() 178 | 179 | start := <-ch 180 | end := <-ch 181 | benchmark.AddSubSample(bench.NewSample(numMsgs, msgSize, start, end, nc)) 182 | nc.Close() 183 | donewg.Done() 184 | } 185 | -------------------------------------------------------------------------------- /tools/stan-sub/stan-sub.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016-2018 The NATS Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package main 15 | 16 | import ( 17 | "flag" 18 | "fmt" 19 | "log" 20 | "os" 21 | "os/signal" 22 | "time" 23 | 24 | "github.com/nats-io/stan.go" 25 | "github.com/nats-io/stan.go/pb" 26 | ) 27 | 28 | var usageStr = ` 29 | Usage: stan-sub [options] 30 | 31 | Options: 32 | -s, --server NATS Streaming server URL(s) 33 | -c, --cluster NATS Streaming cluster name 34 | -id,--clientid NATS Streaming client ID 35 | 36 | Subscription Options: 37 | --qgroup Queue group 38 | --seq Start at seqno 39 | --all Deliver all available messages 40 | --last Deliver starting with last published message 41 | --since Deliver messages in last interval (e.g. 1s, 1hr) 42 | (for more information: https://golang.org/pkg/time/#ParseDuration) 43 | --durable Durable subscriber name 44 | --unsubscribe Unsubscribe the durable on exit 45 | ` 46 | 47 | // NOTE: Use tls scheme for TLS, e.g. stan-sub -s tls://demo.nats.io:4443 foo 48 | func usage() { 49 | log.Fatalf(usageStr) 50 | } 51 | 52 | func printMsg(m *stan.Msg, i int) { 53 | log.Printf("[#%d] Received on [%s]: '%s'\n", i, m.Subject, m) 54 | } 55 | 56 | func main() { 57 | var clusterID string 58 | var clientID string 59 | var showTime bool 60 | var startSeq uint64 61 | var startDelta string 62 | var deliverAll bool 63 | var deliverLast bool 64 | var durable string 65 | var qgroup string 66 | var unsubscribe bool 67 | var URL string 68 | 69 | // defaultID := fmt.Sprintf("client.%s", nuid.Next()) 70 | 71 | flag.StringVar(&URL, "s", stan.DefaultNatsURL, "The nats server URLs (separated by comma)") 72 | flag.StringVar(&URL, "server", stan.DefaultNatsURL, "The nats server URLs (separated by comma)") 73 | flag.StringVar(&clusterID, "c", "test-cluster", "The NATS Streaming cluster ID") 74 | flag.StringVar(&clusterID, "cluster", "test-cluster", "The NATS Streaming cluster ID") 75 | flag.StringVar(&clientID, "id", "", "The NATS Streaming client ID to connect with") 76 | flag.StringVar(&clientID, "clientid", "", "The NATS Streaming client ID to connect with") 77 | flag.BoolVar(&showTime, "t", false, "Display timestamps") 78 | // Subscription options 79 | flag.Uint64Var(&startSeq, "seq", 0, "Start at sequence no.") 80 | flag.BoolVar(&deliverAll, "all", false, "Deliver all") 81 | flag.BoolVar(&deliverLast, "last", false, "Start with last value") 82 | flag.StringVar(&startDelta, "since", "", "Deliver messages since specified time offset") 83 | flag.StringVar(&durable, "durable", "", "Durable subscriber name") 84 | flag.StringVar(&qgroup, "qgroup", "", "Queue group name") 85 | flag.BoolVar(&unsubscribe, "unsubscribe", false, "Unsubscribe the durable on exit") 86 | 87 | log.SetFlags(0) 88 | flag.Usage = usage 89 | flag.Parse() 90 | 91 | args := flag.Args() 92 | 93 | if clientID == "" { 94 | log.Printf("Error: A unique client ID must be specified.") 95 | usage() 96 | } 97 | if len(args) < 1 { 98 | log.Printf("Error: A subject must be specified.") 99 | usage() 100 | } 101 | 102 | sc, err := stan.Connect(clusterID, clientID, stan.NatsURL(URL), 103 | stan.SetConnectionLostHandler(func(_ stan.Conn, reason error) { 104 | log.Fatalf("Connection lost, reason: %v", reason) 105 | })) 106 | if err != nil { 107 | log.Fatalf("Can't connect: %v.\nMake sure a NATS Streaming Server is running at: %s", err, URL) 108 | } 109 | log.Printf("Connected to %s clusterID: [%s] clientID: [%s]\n", URL, clusterID, clientID) 110 | 111 | subj, i := args[0], 0 112 | 113 | mcb := func(msg *stan.Msg) { 114 | i++ 115 | printMsg(msg, i) 116 | } 117 | 118 | startOpt := stan.StartAt(pb.StartPosition_NewOnly) 119 | 120 | if startSeq != 0 { 121 | startOpt = stan.StartAtSequence(startSeq) 122 | } else if deliverLast { 123 | startOpt = stan.StartWithLastReceived() 124 | } else if deliverAll { 125 | log.Print("subscribing with DeliverAllAvailable") 126 | startOpt = stan.DeliverAllAvailable() 127 | } else if startDelta != "" { 128 | ago, err := time.ParseDuration(startDelta) 129 | if err != nil { 130 | sc.Close() 131 | log.Fatal(err) 132 | } 133 | startOpt = stan.StartAtTimeDelta(ago) 134 | } 135 | 136 | sub, err := sc.QueueSubscribe(subj, qgroup, mcb, startOpt, stan.DurableName(durable)) 137 | if err != nil { 138 | sc.Close() 139 | log.Fatal(err) 140 | } 141 | 142 | log.Printf("Listening on [%s], clientID=[%s], qgroup=[%s] durable=[%s]\n", subj, clientID, qgroup, durable) 143 | 144 | if showTime { 145 | log.SetFlags(log.LstdFlags) 146 | } 147 | 148 | // Wait for a SIGINT (perhaps triggered by user with CTRL-C) 149 | // Run cleanup when signal is received 150 | signalChan := make(chan os.Signal, 1) 151 | cleanupDone := make(chan bool) 152 | signal.Notify(signalChan, os.Interrupt) 153 | go func() { 154 | for range signalChan { 155 | fmt.Printf("\nReceived an interrupt, unsubscribing and closing connection...\n\n") 156 | // Do not unsubscribe a durable on exit, except if asked to. 157 | if durable == "" || unsubscribe { 158 | sub.Unsubscribe() 159 | } 160 | sc.Close() 161 | cleanupDone <- true 162 | } 163 | }() 164 | <-cleanupDone 165 | } 166 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= 2 | github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM= 3 | github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg= 4 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 5 | github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= 6 | github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 9 | github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= 10 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= 11 | github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 12 | github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= 13 | github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= 14 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 15 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 16 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 17 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 18 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 19 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 20 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 21 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 22 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 23 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 24 | github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 25 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 26 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 27 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 28 | github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 29 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 30 | github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= 31 | github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= 32 | github.com/hashicorp/go-hclog v0.16.2 h1:K4ev2ib4LdQETX5cSZBG0DVLk1jwGqSPXBjdah3veNs= 33 | github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= 34 | github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= 35 | github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= 36 | github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= 37 | github.com/hashicorp/go-msgpack v1.1.5 h1:9byZdVjKTe5mce63pRVNP1L7UAmdHOTEMGehn6KvJWs= 38 | github.com/hashicorp/go-msgpack v1.1.5/go.mod h1:gWVc3sv/wbDmR3rQsj1CAktEZzoz1YNK9NfGLXJ69/4= 39 | github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= 40 | github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 41 | github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= 42 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 43 | github.com/hashicorp/raft v1.3.1 h1:zDT8ke8y2aP4wf9zPTB2uSIeavJ3Hx/ceY4jxI2JxuY= 44 | github.com/hashicorp/raft v1.3.1/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= 45 | github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= 46 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 47 | github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= 48 | github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s= 49 | github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= 50 | github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= 51 | github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= 52 | github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 53 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 54 | github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= 55 | github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= 56 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 57 | github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= 58 | github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= 59 | github.com/nats-io/jwt v1.2.2 h1:w3GMTO969dFg+UOKTmmyuu7IGdusK+7Ytlt//OYH/uU= 60 | github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q= 61 | github.com/nats-io/jwt/v2 v2.0.3 h1:i/O6cmIsjpcQyWDYNcq2JyZ3/VTF8SJ4JWluI5OhpvI= 62 | github.com/nats-io/jwt/v2 v2.0.3/go.mod h1:VRP+deawSXyhNjXmxPCHskrR6Mq50BqpEI5SEcNiGlY= 63 | github.com/nats-io/nats-server/v2 v2.3.3/go.mod h1:3mtbaN5GkCo/Z5T3nNj0I0/W1fPkKzLiDC6jjWJKp98= 64 | github.com/nats-io/nats-server/v2 v2.5.0 h1:wsnVaaXH9VRSg+A2MVg5Q727/CqxnmPLGFQ3YZYKTQg= 65 | github.com/nats-io/nats-server/v2 v2.5.0/go.mod h1:Kj86UtrXAL6LwYRA6H4RqzkHhK0Vcv2ZnKD5WbQ1t3g= 66 | github.com/nats-io/nats-streaming-server v0.22.1 h1:YKDdLAWZud3UnEBvUPaYppMxSDuh+9czTCDriq19tJY= 67 | github.com/nats-io/nats-streaming-server v0.22.1/go.mod h1:1WpVkVV5NyZbHuGGxkaPWopLFnxNthO/TK/BkzFdnPE= 68 | github.com/nats-io/nats.go v1.11.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= 69 | github.com/nats-io/nats.go v1.11.1-0.20210623165838-4b75fc59ae30/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= 70 | github.com/nats-io/nats.go v1.12.1 h1:+0ndxwUPz3CmQ2vjbXdkC1fo3FdiOQDim4gl3Mge8Qo= 71 | github.com/nats-io/nats.go v1.12.1/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= 72 | github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s= 73 | github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8= 74 | github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= 75 | github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= 76 | github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= 77 | github.com/nats-io/stan.go v0.10.0 h1:trLFZNWJ3bLpD3dxEv5kFNBPsc+QqygjfDOfqh3hqg4= 78 | github.com/nats-io/stan.go v0.10.0/go.mod h1:0jEuBXKauB1HHJswHM/lx05K48TJ1Yxj6VIfM4k+aB4= 79 | github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= 80 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 81 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 82 | github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= 83 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 84 | github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 85 | github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 86 | github.com/prometheus/procfs v0.7.1 h1:TlEtJq5GvGqMykEwWzbZWjjztF86swFhsPix1i0bkgA= 87 | github.com/prometheus/procfs v0.7.1/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= 88 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 89 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 90 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 91 | github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= 92 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 93 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 94 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 95 | go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= 96 | go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= 97 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 98 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 99 | golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 100 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 101 | golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= 102 | golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 103 | golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 104 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 105 | golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= 106 | golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= 107 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 108 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 109 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 110 | golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 111 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 112 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 113 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 114 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 115 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 116 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 117 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 118 | golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= 119 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 120 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 121 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 122 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 123 | golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 124 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 125 | golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 126 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 127 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 128 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 129 | golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 130 | golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 131 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 132 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 133 | golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 134 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 135 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 136 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 137 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 138 | golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= 139 | golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 140 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 141 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 142 | golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 143 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 144 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 145 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 146 | golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 147 | golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= 148 | golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 149 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 150 | golang.org/x/tools v0.0.0-20190424220101-1e8e1cfdf96b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 151 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 152 | golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 153 | golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 154 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 155 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 156 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 157 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 158 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 159 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 160 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 161 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 162 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 163 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 164 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 165 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 166 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 167 | google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= 168 | google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 169 | --------------------------------------------------------------------------------