|
123456789101112131415161718192021222324252627282930 |
- package nsqclient
-
- import (
- "fmt"
- "github.com/nsqio/go-nsq"
- "time"
- )
-
-
-
-
- func main() {
-
- nsqAddr := "www.lockingos.org:4150"
- conf :=nsq.NewConfig()
- p ,err := nsq.NewProducer(nsqAddr,conf)
- if err != nil {
- fmt.Println(err)
- return
- }
- for {
- message := "message :"+ time.Now().Format("2006-01-02 15:04:05")
- fmt.Println(message)
- // 发送消息
- p.Publish("topic-demo1",[]byte(message))
-
- time.Sleep(2*time.Second)
- }
-
- }
|