Skip to content

Commit c3b7b4a

Browse files
committed
to_nsq: added async flag
1 parent c164c77 commit c3b7b4a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

apps/to_nsq/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Usage of ./to_nsq:
1616
Throttle messages to n/second. 0 to disable
1717
-topic string
1818
NSQ topic to publish to
19+
-async bool
20+
Publish message asynchronously (default false)
1921
```
2022

2123
### Examples

apps/to_nsq/to_nsq.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
var (
2424
topic = flag.String("topic", "", "NSQ topic to publish to")
2525
delimiter = flag.String("delimiter", "\n", "character to split input from stdin")
26+
async = flag.Bool("async", false, "use async mode (default false)")
2627

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

140141
for _, producer := range producers {
141-
err := producer.Publish(*topic, line)
142+
var err error
143+
if *async {
144+
err = producer.Publish(*topic, line)
145+
} else {
146+
err = producer.PublishAsync(*topic, line, nil, nil)
147+
}
142148
if err != nil {
143149
return err
144150
}

0 commit comments

Comments
 (0)