Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
package main
import (
"flag"
"log"
"os"
"github.com/nsqio/go-nsq"
)
var (
addr = flag.String("addr", "localhost:4150", "NSQ addr")
topic = flag.String("topic", "", "NSQ topic")
message = flag.String("message", "", "Message body")
)
func main() {
// parse the cli options
flag.Parse()
if *topic == "" || *message == "" {
flag.PrintDefaults()
os.Exit(1)
}
// configure a new Producer
config := nsq.NewConfig()
producer, err := nsq.NewProducer(*addr, config)
if err != nil {
log.Fatal(err)
}
// publish a nessage to the producer
err = producer.Publish(*topic, []byte(*message))
if err != nil {
log.Fatal(err)
}
// disconnect
producer.Stop()
}