Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #24 from nats-io/build-samples
Browse files Browse the repository at this point in the history
auto-build/update samples
  • Loading branch information
aricart authored Jun 6, 2019
2 parents b66e263 + 271d419 commit c3a71f4
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 271 deletions.
8 changes: 0 additions & 8 deletions releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ builds:
- windows
goarch:
- amd64
- main: ./tools/nats-qrply/nats-qrply.go
binary: nats-qrply
goos:
- darwin
- linux
- windows
goarch:
- amd64
- main: ./tools/nats-qsub/nats-qsub.go
binary: nats-qsub
goos:
Expand Down
36 changes: 17 additions & 19 deletions tools/nats-bench/nats-bench.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2018 The NATS Authors
// Copyright 2015-2019 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -18,11 +18,12 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
"sync"
"time"

"github.com/nats-io/go-nats"
"github.com/nats-io/go-nats/bench"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/bench"
)

// Some sane defaults
Expand All @@ -34,7 +35,13 @@ const (
)

func usage() {
log.Fatalf("Usage: nats-bench [-s server (%s)] [--tls] [-np NUM_PUBLISHERS] [-ns NUM_SUBSCRIBERS] [-n NUM_MSGS] [-ms MESSAGE_SIZE] [-csv csvfile] [-creds file] [-nkey file] <subject>\n", nats.DefaultURL)
log.Printf("Usage: nats-bench [-s server (%s)] [--tls] [-np NUM_PUBLISHERS] [-ns NUM_SUBSCRIBERS] [-n NUM_MSGS] [-ms MESSAGE_SIZE] [-csv csvfile] <subject>\n", nats.DefaultURL)
flag.PrintDefaults()
}

func showUsageAndExit(exitcode int) {
usage()
os.Exit(exitcode)
}

var benchmark *bench.Benchmark
Expand All @@ -48,15 +55,19 @@ func main() {
var msgSize = flag.Int("ms", DefaultMessageSize, "Size of the message.")
var csvFile = flag.String("csv", "", "Save bench data to csv file")
var userCreds = flag.String("creds", "", "User Credentials File")
var nkeyFile = flag.String("nkey", "", "NKey Seed File")
var showHelp = flag.Bool("h", false, "Show help message")

log.SetFlags(0)
flag.Usage = usage
flag.Parse()

if *showHelp {
showUsageAndExit(0)
}

args := flag.Args()
if len(args) != 1 {
usage()
showUsageAndExit(1)
}

if *numMsgs <= 0 {
Expand All @@ -66,24 +77,11 @@ func main() {
// Connect Options.
opts := []nats.Option{nats.Name("NATS Benchmark")}

if *userCreds != "" && *nkeyFile != "" {
log.Fatal("specify -seed or -creds")
}

// Use UserCredentials
if *userCreds != "" {
opts = append(opts, nats.UserCredentials(*userCreds))
}

// Use Nkey authentication.
if *nkeyFile != "" {
opt, err := nats.NkeyOptionFromSeed(*nkeyFile)
if err != nil {
log.Fatal(err)
}
opts = append(opts, opt)
}

// Use TLS specified
if *tls {
opts = append(opts, nats.Secure(nil))
Expand Down
35 changes: 16 additions & 19 deletions tools/nats-echo/nats-echo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 The NATS Authors
// Copyright 2018-2019 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -26,15 +26,21 @@ import (
"syscall"
"time"

"github.com/nats-io/go-nats"
"github.com/nats-io/nats.go"
)

// NOTE: Can test with demo servers.
// nats-echo -s demo.nats.io <subject>
// nats-echo -s demo.nats.io:4443 <subject> (TLS version)

func usage() {
log.Fatalf("Usage: nats-echo [-s server] [-creds file] [-nkey seedfile] [-t] <subject>")
log.Printf("Usage: nats-echo [-s server] [-creds file] [-t] <subject>\n")
flag.PrintDefaults()
}

func showUsageAndExit(exitcode int) {
usage()
os.Exit(exitcode)
}

func printMsg(m *nats.Msg, i int) {
Expand All @@ -44,18 +50,22 @@ func printMsg(m *nats.Msg, i int) {
func main() {
var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)")
var userCreds = flag.String("creds", "", "User Credentials File")
var nkeyFile = flag.String("nkey", "", "NKey Seed File")
var showTime = flag.Bool("t", false, "Display timestamps")
var showHelp = flag.Bool("h", false, "Show help message")
var geoloc = flag.Bool("geo", false, "Display geo location of echo service")
var geo string

log.SetFlags(0)
flag.Usage = usage
flag.Parse()

if *showHelp {
showUsageAndExit(0)
}

args := flag.Args()
if len(args) != 1 {
usage()
showUsageAndExit(1)
}

// Lookup geo if requested
Expand All @@ -66,24 +76,11 @@ func main() {
opts := []nats.Option{nats.Name("NATS Echo Service")}
opts = setupConnOptions(opts)

if *userCreds != "" && *nkeyFile != "" {
log.Fatal("specify -seed or -creds")
}

// Use UserCredentials
if *userCreds != "" {
opts = append(opts, nats.UserCredentials(*userCreds))
}

// Use Nkey authentication.
if *nkeyFile != "" {
opt, err := nats.NkeyOptionFromSeed(*nkeyFile)
if err != nil {
log.Fatal(err)
}
opts = append(opts, opt)
}

// Connect to NATS
nc, err := nats.Connect(*urls, opts...)
if err != nil {
Expand Down Expand Up @@ -171,7 +168,7 @@ func lookupGeo() string {
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
g := &geo{}
g := geo{}
if err := json.Unmarshal(body, &g); err != nil {
log.Fatalf("Error unmarshalling geo: %v", err)
}
Expand Down
35 changes: 16 additions & 19 deletions tools/nats-pub/nats-pub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2018 The NATS Authors
// Copyright 2012-2019 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -16,60 +16,57 @@ package main
import (
"flag"
"log"
"os"

"github.com/nats-io/go-nats"
"github.com/nats-io/nats.go"
)

// NOTE: Can test with demo servers.
// nats-pub -s demo.nats.io <subject> <msg>
// nats-pub -s demo.nats.io:4443 <subject> <msg> (TLS version)

func usage() {
log.Fatalf("Usage: nats-pub [-s server] [-creds file] [-nkey file] <subject> <msg>")
log.Printf("Usage: nats-pub [-s server] [-creds file] <subject> <msg>\n")
flag.PrintDefaults()
}

func showUsageAndExit(exitcode int) {
usage()
os.Exit(exitcode)
}

func main() {
var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)")
var userCreds = flag.String("creds", "", "User Credentials File")
var nkeyFile = flag.String("nkey", "", "NKey Seed File")
var showHelp = flag.Bool("h", false, "Show help message")

log.SetFlags(0)
flag.Usage = usage
flag.Parse()

if *showHelp {
showUsageAndExit(0)
}

args := flag.Args()
if len(args) != 2 {
usage()
showUsageAndExit(1)
}

// Connect Options.
opts := []nats.Option{nats.Name("NATS Sample Publisher")}

if *userCreds != "" && *nkeyFile != "" {
log.Fatal("specify -seed or -creds")
}

// Use UserCredentials
if *userCreds != "" {
opts = append(opts, nats.UserCredentials(*userCreds))
}

// Use Nkey authentication.
if *nkeyFile != "" {
opt, err := nats.NkeyOptionFromSeed(*nkeyFile)
if err != nil {
log.Fatal(err)
}
opts = append(opts, opt)
}

// Connect to NATS
nc, err := nats.Connect(*urls, opts...)
if err != nil {
log.Fatal(err)
}
defer nc.Close()

subj, msg := args[0], []byte(args[1])

nc.Publish(subj, msg)
Expand Down
120 changes: 0 additions & 120 deletions tools/nats-qrply/nats-qrply.go

This file was deleted.

Loading

0 comments on commit c3a71f4

Please sign in to comment.