servicecontext.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package svc
  2. import (
  3. "ylink/core/inner/rpc/internal/config"
  4. "ylink/core/inner/rpc/internal/ext"
  5. "ylink/ext/ds/treemap"
  6. "ylink/ext/kafka"
  7. "ylink/ext/model"
  8. )
  9. type ServiceContext struct {
  10. Config config.Config
  11. RecvBoxProducer *kafka.Producer
  12. }
  13. func NewServiceContext(c config.Config) *ServiceContext {
  14. fetchCsCenterInfo()
  15. recvBoxProducer := kafka.NewKafkaProducer(c.KqSendMsgConf.Brokers, c.KqSendMsgConf.Topic)
  16. var sendBoxHandler ext.SendBoxConsumerHandler
  17. sendBoxHandler.Init(c.KqRecvMsgConf, recvBoxProducer)
  18. go sendBoxHandler.ConsumerGroup.RegisterHandleAndConsumer(&sendBoxHandler)
  19. return &ServiceContext{
  20. Config: c,
  21. }
  22. }
  23. func fetchCsCenterInfo() {
  24. // mock info
  25. mockInfo()
  26. }
  27. func mockInfo() {
  28. ext.IdMap = treemap.New(treemap.WithGoroutineSafe())
  29. ext.CsMap = treemap.New(treemap.WithGoroutineSafe())
  30. game1231P2cMap := treemap.New(treemap.WithGoroutineSafe())
  31. game1231P2cMap.Insert("player1231", "cs_1231")
  32. game1231P2cMap.Insert("player1111", "cs_2222")
  33. game1111P2cMap := treemap.New(treemap.WithGoroutineSafe())
  34. game1111P2cMap.Insert("player1231", "cs_1111")
  35. ext.IdMap.Insert("game1231", game1231P2cMap)
  36. ext.IdMap.Insert("game1111", game1111P2cMap)
  37. ext.CsMap.Insert("cs_1231", &model.CsInfo{
  38. CsId: "cs_1231",
  39. CsNickname: "客服1231",
  40. CsAvatarUrl: "https://www.baidu.com",
  41. CsSignature: "我是客服1231",
  42. OnlineStatus: 1,
  43. })
  44. ext.CsMap.Insert("cs_1111", &model.CsInfo{
  45. CsId: "cs_1111",
  46. CsNickname: "客服1111",
  47. CsAvatarUrl: "https://www.baidu.com",
  48. CsSignature: "我是客服1111",
  49. OnlineStatus: 1,
  50. })
  51. ext.CsMap.Insert("cs_2222", &model.CsInfo{
  52. CsId: "cs_2222",
  53. CsNickname: "客服2222",
  54. CsAvatarUrl: "https://www.baidu.com",
  55. CsSignature: "我是客服2222",
  56. OnlineStatus: 0,
  57. })
  58. }