Skip to content

Commit

Permalink
to_nsq: added async flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gboddin committed Mar 23, 2021
1 parent c164c77 commit f77f5ae
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion apps/to_nsq/to_nsq.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
var (
topic = flag.String("topic", "", "NSQ topic to publish to")
delimiter = flag.String("delimiter", "\n", "character to split input from stdin")
async = flag.Bool("async", false, "use async mode (default false)")

destNsqdTCPAddrs = app.StringArray{}
)
Expand Down Expand Up @@ -138,7 +139,12 @@ func readAndPublish(r *bufio.Reader, delim byte, producers map[string]*nsq.Produ
}

for _, producer := range producers {
err := producer.Publish(*topic, line)
var err error
if *async {
err = producer.PublishAsync(*topic, line, nil, nil)
} else {
err = producer.Publish(*topic, line)
}
if err != nil {
return err
}
Expand Down

0 comments on commit f77f5ae

Please sign in to comment.