文件同步
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 line
948 B

  1. package nsqclient
  2. import (
  3. "github.com/nsqio/go-nsq"
  4. "log"
  5. )
  6. /**
  7. Locking通知消息
  8. */
  9. type LockingMsg struct{
  10. Id int64 `json:"id,string"`
  11. UserIds []int64 `json:"userIds"`
  12. PushChannel int `json:"pushChannel"`
  13. Title string `json:"title"`
  14. Body string `json:"body"`
  15. Type string `json:"type"`
  16. PushTimeUnix int64 `json:"pushTimeUnix,string"`
  17. Parameter map[string] string `json:"parameter"`
  18. }
  19. var MsgQueue = make(chan string,100000)
  20. type NewHandler struct{}
  21. func (m *NewHandler) HandleMessage(msg *nsq.Message) (err error) {
  22. //addr := msg.NSQDAddress
  23. message := string(msg.Body)
  24. log.Println(message)
  25. MsgQueue <- message
  26. return
  27. }
  28. func Consumers(topic, channel, addr string) {
  29. conf := nsq.NewConfig()
  30. new_consumer, err := nsq.NewConsumer(topic, channel, conf)
  31. if err != nil {
  32. }
  33. // 接收消息
  34. new_handler := &NewHandler{}
  35. new_consumer.AddHandler(new_handler)
  36. err = new_consumer.ConnectToNSQD(addr)
  37. if err != nil {
  38. }
  39. }