diff --git a/features/cdr/cdrevent.go b/features/cdr/cdrevent.go index b1c1e5aa..2b46ddfb 100644 --- a/features/cdr/cdrevent.go +++ b/features/cdr/cdrevent.go @@ -57,7 +57,7 @@ func PostCDREventFromNF(w http.ResponseWriter, r *http.Request) { } // 推送到ws订阅组 - wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_CDR, cdrEvent) + wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_IMS_CDR, cdrEvent) services.ResponseStatusOK204NoContent(w) } diff --git a/features/event/event.go b/features/event/event.go index ecf55f85..9691ada6 100644 --- a/features/event/event.go +++ b/features/event/event.go @@ -63,7 +63,7 @@ func PostUEEventFromAMF(c *gin.Context) { } // 推送到ws订阅组 - wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_UE, ueEvent) + wsService.NewWSSendImpl.ByGroupID(wsService.GROUP_AMF_UE, ueEvent) services.ResponseStatusOK204NoContent(c.Writer) } diff --git a/src/modules/ws/service/ws.impl.go b/src/modules/ws/service/ws.impl.go index 2d64fd30..447438b0 100644 --- a/src/modules/ws/service/ws.impl.go +++ b/src/modules/ws/service/ws.impl.go @@ -14,12 +14,14 @@ import ( ) var ( + // ws客户端读写互斥锁 + mutex sync.Mutex // ws客户端 [clientId: client] - WsClients = sync.Map{} + WsClients sync.Map // ws用户对应的多个客户端id [uid:clientIds] - WsUsers = sync.Map{} + WsUsers sync.Map // ws组对应的多个用户id [groupID:uids] - WsGroup = sync.Map{} + WsGroup sync.Map ) // 实例化服务层 WSImpl 结构体 @@ -148,6 +150,7 @@ func (s *WSImpl) clientWrite(wsClient *model.WSClient) { // CloseClient 客户端关闭 func (s *WSImpl) CloseClient(clientID string) { + mutex.Lock() v, ok := WsClients.Load(clientID) if !ok { return @@ -159,6 +162,7 @@ func (s *WSImpl) CloseClient(clientID string) { client.Conn.Close() client.StopChan <- struct{}{} WsClients.Delete(clientID) + mutex.Unlock() }() // 客户端断线时自动踢出Uid绑定列表 diff --git a/src/modules/ws/service/ws_send.impl.go b/src/modules/ws/service/ws_send.impl.go index 8d2aa693..62b7601a 100644 --- a/src/modules/ws/service/ws_send.impl.go +++ b/src/modules/ws/service/ws_send.impl.go @@ -8,15 +8,18 @@ import ( "ems.agt/src/modules/ws/model" ) +// 订阅组指定编号为支持服务器向客户端主动推送数据 const ( // 组号-其他 GROUP_OTHER = "0" // 组号-指标 - GROUP_KPI = "1" - // 组号-CDR会话事件-IMS - GROUP_CDR = "1005" - // 组号-UE会话事件-AMF - GROUP_UE = "1010" + GROUP_KPI = "10" + // 组号-指标UPF + GROUP_KPI_UPF = "12" + // 组号-IMS_CDR会话事件 + GROUP_IMS_CDR = "1005" + // 组号-AMF_UE会话事件 + GROUP_AMF_UE = "1010" ) // 实例化服务层 WSSendImpl 结构体