Skip to content

Commit

Permalink
[CHANGED] Import of stan-sub.go
Browse files Browse the repository at this point in the history
To be consistent with other examples programs, changed code to not
use the "." import.
  • Loading branch information
kozlovic committed Jul 19, 2016
1 parent beba61d commit 87bd2a6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions examples/stan-sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os/signal"
"time"

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

Expand Down Expand Up @@ -39,7 +39,7 @@ func usage() {
log.Fatalf(usageStr)
}

func printMsg(m *Msg, i int) {
func printMsg(m *stan.Msg, i int) {
log.Printf("[#%d] Received on [%s]: '%s'\n", i, m.Subject, m)
}

Expand All @@ -58,8 +58,8 @@ func main() {

// defaultID := fmt.Sprintf("client.%s", nuid.Next())

flag.StringVar(&URL, "s", DefaultNatsURL, "The nats server URLs (separated by comma)")
flag.StringVar(&URL, "server", DefaultNatsURL, "The nats server URLs (separated by comma)")
flag.StringVar(&URL, "s", stan.DefaultNatsURL, "The nats server URLs (separated by comma)")
flag.StringVar(&URL, "server", stan.DefaultNatsURL, "The nats server URLs (separated by comma)")
flag.StringVar(&clusterID, "c", "test-cluster", "The NATS Streaming cluster ID")
flag.StringVar(&clusterID, "cluster", "test-cluster", "The NATS Streaming cluster ID")
flag.StringVar(&clientID, "id", "", "The NATS Streaming client ID to connect with")
Expand Down Expand Up @@ -89,38 +89,38 @@ func main() {
usage()
}

sc, err := Connect(clusterID, clientID, NatsURL(URL))
sc, err := stan.Connect(clusterID, clientID, stan.NatsURL(URL))
if err != nil {
log.Fatalf("Can't connect: %v.\nMake sure a NATS Streaming Server is running at: %s", err, URL)
}
log.Printf("Connected to %s clusterID: [%s] clientID: [%s]\n", URL, clusterID, clientID)

subj, i := args[0], 0

mcb := func(msg *Msg) {
mcb := func(msg *stan.Msg) {
i++
printMsg(msg, i)
}

startOpt := StartAt(pb.StartPosition_NewOnly)
startOpt := stan.StartAt(pb.StartPosition_NewOnly)

if startSeq != 0 {
startOpt = StartAtSequence(startSeq)
startOpt = stan.StartAtSequence(startSeq)
} else if deliverLast == true {
startOpt = StartWithLastReceived()
startOpt = stan.StartWithLastReceived()
} else if deliverAll == true {
log.Print("subscribing with DeliverAllAvailable")
startOpt = DeliverAllAvailable()
startOpt = stan.DeliverAllAvailable()
} else if startDelta != "" {
ago, err := time.ParseDuration(startDelta)
if err != nil {
sc.Close()
log.Fatal(err)
}
startOpt = StartAtTimeDelta(ago)
startOpt = stan.StartAtTimeDelta(ago)
}

sub, err := sc.QueueSubscribe(subj, qgroup, mcb, startOpt, DurableName(durable))
sub, err := sc.QueueSubscribe(subj, qgroup, mcb, startOpt, stan.DurableName(durable))
if err != nil {
sc.Close()
log.Fatal(err)
Expand Down

0 comments on commit 87bd2a6

Please sign in to comment.