From f77f5ae9c6211693f6a3a7ec8e75537df641d8d4 Mon Sep 17 00:00:00 2001 From: Gregory Boddin Date: Tue, 23 Mar 2021 17:20:56 +0100 Subject: [PATCH] to_nsq: added async flag --- apps/to_nsq/to_nsq.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/to_nsq/to_nsq.go b/apps/to_nsq/to_nsq.go index b70c5b6df..021cb8538 100644 --- a/apps/to_nsq/to_nsq.go +++ b/apps/to_nsq/to_nsq.go @@ -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{} ) @@ -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 }