main.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jybase/go-logger/logger"
  4. _ "app.yhyue.com/moapp/message/config"
  5. "app.yhyue.com/moapp/message/handler"
  6. "app.yhyue.com/moapp/message/services"
  7. "github.com/gogf/gf/v2/os/gcfg"
  8. "github.com/gogf/gf/v2/os/gctx"
  9. "github.com/nsqio/go-nsq"
  10. "log"
  11. )
  12. func init() {
  13. logger.SetConsole(false)
  14. logger.SetRollingDaily("./logs", "message.log")
  15. }
  16. func nsqWork() {
  17. // Instantiate a consumer that will subscribe to the provided channel.
  18. config := nsq.NewConfig()
  19. consumer, err := nsq.NewConsumer("jy_event", "event", config)
  20. if err != nil {
  21. log.Fatal(err)
  22. }
  23. // Set the Handler for messages received by this Consumer. Can be called multiple times.
  24. // See also AddConcurrentHandlers.
  25. consumer.AddHandler(&handler.Handler{})
  26. // Use nsqlookupd to discover nsqd instances.
  27. // See also ConnectToNSQD, ConnectToNSQDs, ConnectToNSQLookupds.
  28. err = consumer.ConnectToNSQLookupd(gcfg.Instance().MustGet(gctx.New(), "nsq.address", "").String())
  29. if err != nil {
  30. log.Fatal(err)
  31. }
  32. // Gracefully stop the consumer.
  33. //consumer.Stop()
  34. select {}
  35. }
  36. //
  37. func main() {
  38. go nsqWork()
  39. /*//注册代理服务
  40. gateWayEtcd := gcfg.Instance().MustGet(gctx.New(), "etcd.gateway.address", "").Strings()
  41. gateWayServerCode := gcfg.Instance().MustGet(gctx.New(), "etcd.gateway.serverCode", "").String()
  42. gateWayServerPort := gcfg.Instance().MustGet(gctx.New(), "server.address", "").String()
  43. closeNotify, err := node.NewNode(gateWayEtcd...).Register(gateWayServerCode, gateWayServerPort)
  44. if err != nil {
  45. panic(err)
  46. }
  47. //启动服务
  48. go func() {*/
  49. services.InitActivityServer().Run()
  50. /*}()
  51. quit := make(chan os.Signal, 1)
  52. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  53. <-quit
  54. closeNotify()*/
  55. }