Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a standard subscription [ci-skip] #950

Merged
merged 2 commits into from Apr 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions examples/nats-echo/main.go
Expand Up @@ -44,7 +44,7 @@ func showUsageAndExit(exitcode int) {
}

func printMsg(m *nats.Msg, i int) {
log.Printf("[#%d] Echoing to [%s]: %q", i, m.Reply, m.Data)
log.Printf("[#%d] Echoing from [%s] to [%s]: %q", i, m.Subject, m.Reply, m.Data)
}

func main() {
Expand Down Expand Up @@ -103,7 +103,7 @@ func main() {

subj, i := args[0], 0

nc.QueueSubscribe(subj, "echo", func(msg *nats.Msg) {
handleMsg := func(msg *nats.Msg) {
i++
if msg.Reply != "" {
printMsg(msg, i)
Expand All @@ -115,6 +115,14 @@ func main() {
nc.Publish(msg.Reply, msg.Data)
}
}
}

nc.QueueSubscribe(subj, "echo", func(msg *nats.Msg) {
handleMsg(msg)
})
allSubj := subj + ".all"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this status.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And for this one we just should send back our geo I think? Maybe if you want add in an identifier at startup to customize?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed; it's status and there is an identifier now.

nc.Subscribe(allSubj, func(msg *nats.Msg) {
handleMsg(msg)
})
nc.Flush()

Expand All @@ -123,8 +131,9 @@ func main() {
}

log.Printf("Echo Service listening on [%s]\n", subj)
log.Printf("Echo Service (All) listening on [%s]\n", allSubj)

// Now handle signal to terminate so we cam drain on exit.
// Now handle signal to terminate so we can drain on exit.
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT)

Expand Down