1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| package main
import ( "fmt" "log" "time"
"github.com/nsqio/go-nsq" )
func main() { config := nsq.NewConfig() p, err := nsq.NewProducer("10.8.0.6:4150", config)
if err != nil { log.Panic(err) }
for i := 1000; i < 2000; i++ { msg := fmt.Sprintf("num-%d", i) log.Println("Pub2:" + msg) err = p.Publish("testTopic", []byte(msg)) if err != nil { log.Panic(err) } time.Sleep(time.Second * 1) }
p.Stop() }
|