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 33 34 35 36
| package main
import ( "log" "github.com/bitly/go-nsq" "io/ioutil" "strconv" )
var nullLogger = log.New(ioutil.Discard, "", log.LstdFlags)
func sendMsg(message string){ config := nsq.NewConfig() w, _ := nsq.NewProducer("127.0.0.1:4150", config) err := w.Ping() if err != nil { log.Fatalln("error ping 10.50.115.16:4150", err) w, _ = nsq.NewProducer("192.168.2.68:4150", config) } w.SetLogger(nullLogger, nsq.LogLevelInfo)
err2 := w.Publish("a-test", []byte(message)) if err2 != nil { log.Panic("Could not connect nsq") } w.Stop() }
func main() { for i := 0; i < 2; i ++ { sendMsg("msg index "+ strconv.Itoa(i + 10000)) } }
|