Skip to content

Commit

Permalink
Merge pull request #190 from mreiferson/nsq_tail_safety_190
Browse files Browse the repository at this point in the history
nsq_tail: safety
  • Loading branch information
jehiah committed May 21, 2013
2 parents b854537 + 27b47c3 commit d9e2273
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions examples/nsq_tail/nsq_tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"log"
"math/rand"
"os"
"os/signal"
"strings"
"syscall"
"time"
)

var (
showVersion = flag.Bool("version", false, "print version string")
topic = flag.String("topic", "", "nsq topic")
channel = flag.String("channel", "nsq_tail#ephemeral", "nsq channel")
channel = flag.String("channel", "", "nsq channel")
maxInFlight = flag.Int("max-in-flight", 200, "max number of messages to allow in flight")
nsqdTCPAddrs = util.StringArray{}
lookupdHTTPAddrs = util.StringArray{}
Expand Down Expand Up @@ -47,8 +50,13 @@ func main() {
return
}

if *topic == "" || *channel == "" {
log.Fatalf("--topic and --channel are required")
if *channel == "" {
rand.Seed(time.Now().UnixNano())
*channel = fmt.Sprintf("tail%06d#ephemeral", rand.Int()%999999)
}

if *topic == "" {
log.Fatalf("--topic is required")
}

if *maxInFlight < 0 {
Expand Down

0 comments on commit d9e2273

Please sign in to comment.