mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-12 22:54:43 +08:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce56b19fe8 | ||
|
|
1367d776e6 | ||
|
|
987d35ff15 | ||
|
|
d225bb4bd2 | ||
|
|
ea37fb5081 | ||
|
|
0a92f48d0b | ||
|
|
f5e86fee02 | ||
|
|
166facc959 | ||
|
|
5bb747201b | ||
|
|
1014bc54e4 | ||
|
|
9c26c742fe | ||
|
|
d1935b1bbc | ||
|
|
90d54bf3e2 | ||
|
|
78cc33c84e | ||
|
|
9cf21bf418 | ||
|
|
c6d0bd9a19 | ||
|
|
61bf95e457 | ||
|
|
8b2a551ee5 | ||
|
|
927c2ffa37 | ||
|
|
b23b30aac5 |
123
README.md
123
README.md
@@ -661,51 +661,7 @@ Module1 Release.
|
|||||||
第四章:事件使用
|
第四章:事件使用
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
事件是origin中一个重要的组成部分,可以在同一个node中的service与service或者与module之间进行事件通知。系统内置的几个服务,如:TcpService/HttpService等都是通过事件功能实现。他也是一个典型的观察者设计模型。在event中有两个类型的interface,一个是event.IEventProcessor它提供注册与卸载功能,另一个是event.IEventHandler提供消息广播等功能。
|
事件是origin中一个重要的组成部分,可以在服务与各module之间进行事件通知。它也是一个典型的观察者设计模型。在event中有两个类型的interface,一个是event.IEventProcessor它提供注册与卸载功能,另一个是event.IEventHandler提供消息广播等功能。
|
||||||
|
|
||||||
在目录simple_event/TestService4.go中
|
|
||||||
|
|
||||||
```
|
|
||||||
package simple_event
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/duanhf2012/origin/v2/event"
|
|
||||||
"github.com/duanhf2012/origin/v2/node"
|
|
||||||
"github.com/duanhf2012/origin/v2/service"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
//自定义事件类型,必需从event.Sys_Event_User_Define开始
|
|
||||||
//event.Sys_Event_User_Define以内给系统预留
|
|
||||||
EVENT1 event.EventType =event.Sys_Event_User_Define+1
|
|
||||||
)
|
|
||||||
|
|
||||||
func init(){
|
|
||||||
node.Setup(&TestService4{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type TestService4 struct {
|
|
||||||
service.Service
|
|
||||||
}
|
|
||||||
|
|
||||||
func (slf *TestService4) OnInit() error {
|
|
||||||
//10秒后触发广播事件
|
|
||||||
slf.AfterFunc(time.Second*10,slf.TriggerEvent)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (slf *TestService4) TriggerEvent(){
|
|
||||||
//广播事件,传入event.Event对象,类型为EVENT1,Data可以自定义任何数据
|
|
||||||
//这样,所有监听者都可以收到该事件
|
|
||||||
slf.GetEventHandler().NotifyEvent(&event.Event{
|
|
||||||
Type: EVENT1,
|
|
||||||
Data: "event data.",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
在目录simple_event/TestService5.go中
|
在目录simple_event/TestService5.go中
|
||||||
|
|
||||||
@@ -713,53 +669,68 @@ func (slf *TestService4) TriggerEvent(){
|
|||||||
package simple_event
|
package simple_event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duanhf2012/origin/v2/event"
|
"github.com/duanhf2012/origin/v2/event"
|
||||||
"github.com/duanhf2012/origin/v2/node"
|
"github.com/duanhf2012/origin/v2/node"
|
||||||
"github.com/duanhf2012/origin/v2/service"
|
"github.com/duanhf2012/origin/v2/service"
|
||||||
|
"github.com/duanhf2012/origin/v2/util/timer"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init(){
|
func init() {
|
||||||
node.Setup(&TestService5{})
|
node.Setup(&TestService5{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
//自定义事件类型,必需从event.Sys_Event_User_Define开始
|
||||||
|
//event.Sys_Event_User_Define以内给系统预留
|
||||||
|
EVENT1 event.EventType = event.Sys_Event_User_Define + 1
|
||||||
|
)
|
||||||
|
|
||||||
type TestService5 struct {
|
type TestService5 struct {
|
||||||
service.Service
|
service.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestModule struct {
|
type TestModule struct {
|
||||||
service.Module
|
service.Module
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *TestModule) OnInit() error{
|
func (slf *TestModule) OnInit() error {
|
||||||
//在当前node中查找TestService4
|
//在TestModule中注册监听EVENT1事件
|
||||||
pService := node.GetService("TestService4")
|
slf.GetEventProcessor().RegEventReceiverFunc(EVENT1, slf.GetEventHandler(), slf.OnModuleEvent)
|
||||||
|
|
||||||
//在TestModule中,往TestService4中注册EVENT1类型事件监听
|
return nil
|
||||||
pService.(*TestService4).GetEventProcessor().RegEventReciverFunc(EVENT1,slf.GetEventHandler(),slf.OnModuleEvent)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *TestModule) OnModuleEvent(ev event.IEvent){
|
// OnModuleEvent 模块监听事件回调
|
||||||
event := ev.(*event.Event)
|
func (slf *TestModule) OnModuleEvent(ev event.IEvent) {
|
||||||
fmt.Printf("OnModuleEvent type :%d data:%+v\n",event.GetEventType(),event.Data)
|
event := ev.(*event.Event)
|
||||||
|
fmt.Printf("OnModuleEvent type :%d data:%+v\n", event.GetEventType(), event.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnInit 服务初始化函数,在安装服务时,服务将自动调用OnInit函数
|
||||||
//服务初始化函数,在安装服务时,服务将自动调用OnInit函数
|
|
||||||
func (slf *TestService5) OnInit() error {
|
func (slf *TestService5) OnInit() error {
|
||||||
//通过服务名获取服务对象
|
//在服务中注册监听EVENT1类型事件
|
||||||
pService := node.GetService("TestService4")
|
slf.RegEventReceiverFunc(EVENT1, slf.GetEventHandler(), slf.OnServiceEvent)
|
||||||
|
slf.AddModule(&TestModule{})
|
||||||
|
|
||||||
////在TestModule中,往TestService4中注册EVENT1类型事件监听
|
slf.AfterFunc(time.Second*10, slf.TriggerEvent)
|
||||||
pService.(*TestService4).GetEventProcessor().RegEventReciverFunc(EVENT1,slf.GetEventHandler(),slf.OnServiceEvent)
|
return nil
|
||||||
slf.AddModule(&TestModule{})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *TestService5) OnServiceEvent(ev event.IEvent){
|
// OnServiceEvent 服务监听事件回调
|
||||||
event := ev.(*event.Event)
|
func (slf *TestService5) OnServiceEvent(ev event.IEvent) {
|
||||||
fmt.Printf("OnServiceEvent type :%d data:%+v\n",event.Type,event.Data)
|
event := ev.(*event.Event)
|
||||||
|
fmt.Printf("OnServiceEvent type :%d data:%+v\n", event.Type, event.Data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (slf *TestService5) TriggerEvent(t *timer.Timer) {
|
||||||
|
//广播事件,传入event.Event对象,类型为EVENT1,Data可以自定义任何数据
|
||||||
|
//这样,所有监听者都可以收到该事件
|
||||||
|
slf.GetEventHandler().NotifyEvent(&event.Event{
|
||||||
|
Type: EVENT1,
|
||||||
|
Data: "event data.",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -768,8 +739,8 @@ func (slf *TestService5) OnServiceEvent(ev event.IEvent){
|
|||||||
程序运行10秒后,调用slf.TriggerEvent函数广播事件,于是在TestService5中会收到
|
程序运行10秒后,调用slf.TriggerEvent函数广播事件,于是在TestService5中会收到
|
||||||
|
|
||||||
```
|
```
|
||||||
OnServiceEvent type :1001 data:event data.
|
OnServiceEvent type :2 data:event data.
|
||||||
OnModuleEvent type :1001 data:event data.
|
OnModuleEvent type :2 data:event data.
|
||||||
```
|
```
|
||||||
|
|
||||||
在上面的TestModule中监听的事情,当这个Module被Release时监听会自动卸载。
|
在上面的TestModule中监听的事情,当这个Module被Release时监听会自动卸载。
|
||||||
@@ -1181,6 +1152,8 @@ func (slf *TestTcpService) OnRequest (clientid string,msg proto.Message){
|
|||||||
* log/log.go:日志的封装,可以使用它构建对象记录业务文件日志
|
* log/log.go:日志的封装,可以使用它构建对象记录业务文件日志
|
||||||
* util:在该目录下,有常用的uuid,hash,md5,协程封装等工具库
|
* util:在该目录下,有常用的uuid,hash,md5,协程封装等工具库
|
||||||
* https://github.com/duanhf2012/originservice: 其他扩展支持的服务可以在该工程上看到,目前支持firebase推送的封装。
|
* https://github.com/duanhf2012/originservice: 其他扩展支持的服务可以在该工程上看到,目前支持firebase推送的封装。
|
||||||
|
* https://github.com/duanhf2012/origingame: 基础游戏服务器的框架
|
||||||
|
* etcd与nats开发环境搭建可以从https://github.com/duanhf2012/originserver_v2下的docker-compose获取
|
||||||
|
|
||||||
备注:
|
备注:
|
||||||
-----
|
-----
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"github.com/duanhf2012/origin/v2/event"
|
"github.com/duanhf2012/origin/v2/event"
|
||||||
|
"errors"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configDir = "./config/"
|
var configDir = "./config/"
|
||||||
@@ -62,6 +64,7 @@ type Cluster struct {
|
|||||||
locker sync.RWMutex //结点与服务关系保护锁
|
locker sync.RWMutex //结点与服务关系保护锁
|
||||||
mapRpc map[string]*NodeRpcInfo //nodeId
|
mapRpc map[string]*NodeRpcInfo //nodeId
|
||||||
mapServiceNode map[string]map[string]struct{} //map[serviceName]map[NodeId]
|
mapServiceNode map[string]map[string]struct{} //map[serviceName]map[NodeId]
|
||||||
|
mapTemplateServiceNode map[string]map[string]struct{} //map[templateServiceName]map[serviceName]nodeId
|
||||||
|
|
||||||
callSet rpc.CallSet
|
callSet rpc.CallSet
|
||||||
rpcNats rpc.RpcNats
|
rpcNats rpc.RpcNats
|
||||||
@@ -137,6 +140,20 @@ func (cls *Cluster) delServiceNode(serviceName string, nodeId string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//处理模板服务
|
||||||
|
splitServiceName := strings.Split(serviceName,":")
|
||||||
|
if len(splitServiceName) == 2 {
|
||||||
|
serviceName = splitServiceName[0]
|
||||||
|
templateServiceName := splitServiceName[1]
|
||||||
|
|
||||||
|
mapService := cls.mapTemplateServiceNode[templateServiceName]
|
||||||
|
delete(mapService,serviceName)
|
||||||
|
|
||||||
|
if len(cls.mapTemplateServiceNode[templateServiceName]) == 0 {
|
||||||
|
delete(cls.mapTemplateServiceNode,templateServiceName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mapNode := cls.mapServiceNode[serviceName]
|
mapNode := cls.mapServiceNode[serviceName]
|
||||||
delete(mapNode, nodeId)
|
delete(mapNode, nodeId)
|
||||||
if len(mapNode) == 0 {
|
if len(mapNode) == 0 {
|
||||||
@@ -171,7 +188,20 @@ func (cls *Cluster) serviceDiscoverySetNodeInfo(nodeInfo *NodeInfo) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mapDuplicate[serviceName] = nil
|
mapDuplicate[serviceName] = nil
|
||||||
if _, ok := cls.mapServiceNode[serviceName]; ok == false {
|
|
||||||
|
//如果是模板服务,则记录模板关系
|
||||||
|
splitServiceName := strings.Split(serviceName,":")
|
||||||
|
if len(splitServiceName) == 2 {
|
||||||
|
serviceName = splitServiceName[0]
|
||||||
|
templateServiceName := splitServiceName[1]
|
||||||
|
//记录模板
|
||||||
|
if _, ok = cls.mapTemplateServiceNode[templateServiceName]; ok == false {
|
||||||
|
cls.mapTemplateServiceNode[templateServiceName]=map[string]struct{}{}
|
||||||
|
}
|
||||||
|
cls.mapTemplateServiceNode[templateServiceName][serviceName] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok = cls.mapServiceNode[serviceName]; ok == false {
|
||||||
cls.mapServiceNode[serviceName] = make(map[string]struct{}, 1)
|
cls.mapServiceNode[serviceName] = make(map[string]struct{}, 1)
|
||||||
}
|
}
|
||||||
cls.mapServiceNode[serviceName][nodeInfo.NodeId] = struct{}{}
|
cls.mapServiceNode[serviceName][nodeInfo.NodeId] = struct{}{}
|
||||||
@@ -259,25 +289,29 @@ func (cls *Cluster) GetRpcClient(nodeId string) (*rpc.Client,bool) {
|
|||||||
return cls.getRpcClient(nodeId)
|
return cls.getRpcClient(nodeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRpcClient(nodeId string, serviceMethod string,filterRetire bool, clientList []*rpc.Client) (error, int) {
|
func GetNodeIdByTemplateService(templateServiceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, []*rpc.Client) {
|
||||||
|
return GetCluster().GetNodeIdByTemplateService(templateServiceName, rpcClientList, filterRetire)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRpcClient(nodeId string, serviceMethod string,filterRetire bool, clientList []*rpc.Client) (error, []*rpc.Client) {
|
||||||
if nodeId != rpc.NodeIdNull {
|
if nodeId != rpc.NodeIdNull {
|
||||||
pClient,retire := GetCluster().GetRpcClient(nodeId)
|
pClient,retire := GetCluster().GetRpcClient(nodeId)
|
||||||
if pClient == nil {
|
if pClient == nil {
|
||||||
return fmt.Errorf("cannot find nodeid %d!", nodeId), 0
|
return fmt.Errorf("cannot find nodeid %d!", nodeId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果需要筛选掉退休结点
|
//如果需要筛选掉退休结点
|
||||||
if filterRetire == true && retire == true {
|
if filterRetire == true && retire == true {
|
||||||
return fmt.Errorf("cannot find nodeid %d!", nodeId), 0
|
return fmt.Errorf("cannot find nodeid %d!", nodeId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
clientList[0] = pClient
|
clientList = append(clientList,pClient)
|
||||||
return nil, 1
|
return nil, clientList
|
||||||
}
|
}
|
||||||
|
|
||||||
findIndex := strings.Index(serviceMethod, ".")
|
findIndex := strings.Index(serviceMethod, ".")
|
||||||
if findIndex == -1 {
|
if findIndex == -1 {
|
||||||
return fmt.Errorf("servicemethod param %s is error!", serviceMethod), 0
|
return fmt.Errorf("servicemethod param %s is error!", serviceMethod), nil
|
||||||
}
|
}
|
||||||
serviceName := serviceMethod[:findIndex]
|
serviceName := serviceMethod[:findIndex]
|
||||||
|
|
||||||
@@ -376,10 +410,50 @@ func GetNodeByServiceName(serviceName string) map[string]struct{} {
|
|||||||
return mapNodeId
|
return mapNodeId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetNodeByTemplateServiceName 通过模板服务名获取服务名,返回 map[serviceName真实服务名]NodeId
|
||||||
|
func GetNodeByTemplateServiceName(templateServiceName string) map[string]string {
|
||||||
|
cluster.locker.RLock()
|
||||||
|
defer cluster.locker.RUnlock()
|
||||||
|
|
||||||
|
mapServiceName := cluster.mapTemplateServiceNode[templateServiceName]
|
||||||
|
mapNodeId := make(map[string]string,9)
|
||||||
|
for serviceName := range mapServiceName {
|
||||||
|
mapNode, ok := cluster.mapServiceNode[serviceName]
|
||||||
|
if ok == false {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for nodeId,_ := range mapNode {
|
||||||
|
mapNodeId[serviceName] = nodeId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapNodeId
|
||||||
|
}
|
||||||
|
|
||||||
func (cls *Cluster) GetGlobalCfg() interface{} {
|
func (cls *Cluster) GetGlobalCfg() interface{} {
|
||||||
return cls.globalCfg
|
return cls.globalCfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (cls *Cluster) ParseGlobalCfg(cfg interface{}) error{
|
||||||
|
if cls.globalCfg == nil {
|
||||||
|
return errors.New("no service configuration found")
|
||||||
|
}
|
||||||
|
|
||||||
|
rv := reflect.ValueOf(cls.globalCfg)
|
||||||
|
if rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||||
|
return errors.New("no service configuration found")
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes,err := json.Marshal(cls.globalCfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Unmarshal(bytes,cfg)
|
||||||
|
}
|
||||||
|
|
||||||
func (cls *Cluster) GetNodeInfo(nodeId string) (NodeInfo,bool) {
|
func (cls *Cluster) GetNodeInfo(nodeId string) (NodeInfo,bool) {
|
||||||
cls.locker.RLock()
|
cls.locker.RLock()
|
||||||
defer cls.locker.RUnlock()
|
defer cls.locker.RUnlock()
|
||||||
@@ -395,6 +469,11 @@ func (cls *Cluster) GetNodeInfo(nodeId string) (NodeInfo,bool) {
|
|||||||
func (dc *Cluster) CanDiscoveryService(fromMasterNodeId string,serviceName string) bool{
|
func (dc *Cluster) CanDiscoveryService(fromMasterNodeId string,serviceName string) bool{
|
||||||
canDiscovery := true
|
canDiscovery := true
|
||||||
|
|
||||||
|
splitServiceName := strings.Split(serviceName,":")
|
||||||
|
if len(splitServiceName) == 2 {
|
||||||
|
serviceName = splitServiceName[0]
|
||||||
|
}
|
||||||
|
|
||||||
for i:=0;i<len(dc.GetLocalNodeInfo().DiscoveryService);i++{
|
for i:=0;i<len(dc.GetLocalNodeInfo().DiscoveryService);i++{
|
||||||
masterNodeId := dc.GetLocalNodeInfo().DiscoveryService[i].MasterNodeId
|
masterNodeId := dc.GetLocalNodeInfo().DiscoveryService[i].MasterNodeId
|
||||||
//无效的配置,则跳过
|
//无效的配置,则跳过
|
||||||
|
|||||||
@@ -160,6 +160,12 @@ func (dc *OriginDiscoveryMaster) OnNatsDisconnect(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ds *OriginDiscoveryMaster) OnNodeConnected(nodeId string) {
|
func (ds *OriginDiscoveryMaster) OnNodeConnected(nodeId string) {
|
||||||
|
var notifyDiscover rpc.SubscribeDiscoverNotify
|
||||||
|
notifyDiscover.IsFull = true
|
||||||
|
notifyDiscover.NodeInfo = ds.nodeInfo
|
||||||
|
notifyDiscover.MasterNodeId = cluster.GetLocalNodeInfo().NodeId
|
||||||
|
|
||||||
|
ds.GoNode(nodeId, SubServiceDiscover, ¬ifyDiscover)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *OriginDiscoveryMaster) OnNodeDisconnect(nodeId string) {
|
func (ds *OriginDiscoveryMaster) OnNodeDisconnect(nodeId string) {
|
||||||
@@ -183,6 +189,10 @@ func (ds *OriginDiscoveryMaster) OnNodeDisconnect(nodeId string) {
|
|||||||
|
|
||||||
func (ds *OriginDiscoveryMaster) RpcCastGo(serviceMethod string, args interface{}) {
|
func (ds *OriginDiscoveryMaster) RpcCastGo(serviceMethod string, args interface{}) {
|
||||||
for nodeId, _ := range ds.mapNodeInfo {
|
for nodeId, _ := range ds.mapNodeInfo {
|
||||||
|
if nodeId == cluster.GetLocalNodeInfo().NodeId {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
ds.GoNode(nodeId, serviceMethod, args)
|
ds.GoNode(nodeId, serviceMethod, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ func (cls *Cluster) readLocalClusterConfig(nodeId string) (DiscoveryInfo, []Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
if nodeId != rpc.NodeIdNull && (len(nodeInfoList) != 1) {
|
if nodeId != rpc.NodeIdNull && (len(nodeInfoList) != 1) {
|
||||||
return discoveryInfo, nil,rpcMode, fmt.Errorf("%d configurations were found for the configuration with node ID %d!", len(nodeInfoList), nodeId)
|
return discoveryInfo, nil,rpcMode, fmt.Errorf("nodeid %s configuration error in NodeList", nodeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, _ := range nodeInfoList {
|
for i, _ := range nodeInfoList {
|
||||||
@@ -325,6 +325,10 @@ func (cls *Cluster) readLocalService(localNodeId string) error {
|
|||||||
//保存公共配置
|
//保存公共配置
|
||||||
for _, s := range cls.localNodeInfo.ServiceList {
|
for _, s := range cls.localNodeInfo.ServiceList {
|
||||||
for {
|
for {
|
||||||
|
splitServiceName := strings.Split(s,":")
|
||||||
|
if len(splitServiceName) == 2 {
|
||||||
|
s = splitServiceName[0]
|
||||||
|
}
|
||||||
//取公共服务配置
|
//取公共服务配置
|
||||||
pubCfg, ok := serviceConfig[s]
|
pubCfg, ok := serviceConfig[s]
|
||||||
if ok == true {
|
if ok == true {
|
||||||
@@ -355,6 +359,11 @@ func (cls *Cluster) readLocalService(localNodeId string) error {
|
|||||||
|
|
||||||
//组合所有的配置
|
//组合所有的配置
|
||||||
for _, s := range cls.localNodeInfo.ServiceList {
|
for _, s := range cls.localNodeInfo.ServiceList {
|
||||||
|
splitServiceName := strings.Split(s,":")
|
||||||
|
if len(splitServiceName) == 2 {
|
||||||
|
s = splitServiceName[0]
|
||||||
|
}
|
||||||
|
|
||||||
//先从NodeService中找
|
//先从NodeService中找
|
||||||
var serviceCfg interface{}
|
var serviceCfg interface{}
|
||||||
var ok bool
|
var ok bool
|
||||||
@@ -382,12 +391,24 @@ func (cls *Cluster) parseLocalCfg() {
|
|||||||
|
|
||||||
cls.mapRpc[cls.localNodeInfo.NodeId] = &rpcInfo
|
cls.mapRpc[cls.localNodeInfo.NodeId] = &rpcInfo
|
||||||
|
|
||||||
for _, sName := range cls.localNodeInfo.ServiceList {
|
for _, serviceName := range cls.localNodeInfo.ServiceList {
|
||||||
if _, ok := cls.mapServiceNode[sName]; ok == false {
|
splitServiceName := strings.Split(serviceName,":")
|
||||||
cls.mapServiceNode[sName] = make(map[string]struct{})
|
if len(splitServiceName) == 2 {
|
||||||
|
serviceName = splitServiceName[0]
|
||||||
|
templateServiceName := splitServiceName[1]
|
||||||
|
//记录模板
|
||||||
|
if _, ok := cls.mapTemplateServiceNode[templateServiceName]; ok == false {
|
||||||
|
cls.mapTemplateServiceNode[templateServiceName]=map[string]struct{}{}
|
||||||
|
}
|
||||||
|
cls.mapTemplateServiceNode[templateServiceName][serviceName] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
cls.mapServiceNode[sName][cls.localNodeInfo.NodeId] = struct{}{}
|
|
||||||
|
if _, ok := cls.mapServiceNode[serviceName]; ok == false {
|
||||||
|
cls.mapServiceNode[serviceName] = make(map[string]struct{})
|
||||||
|
}
|
||||||
|
|
||||||
|
cls.mapServiceNode[serviceName][cls.localNodeInfo.NodeId] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,6 +424,7 @@ func (cls *Cluster) InitCfg(localNodeId string) error {
|
|||||||
cls.localServiceCfg = map[string]interface{}{}
|
cls.localServiceCfg = map[string]interface{}{}
|
||||||
cls.mapRpc = map[string]*NodeRpcInfo{}
|
cls.mapRpc = map[string]*NodeRpcInfo{}
|
||||||
cls.mapServiceNode = map[string]map[string]struct{}{}
|
cls.mapServiceNode = map[string]map[string]struct{}{}
|
||||||
|
cls.mapTemplateServiceNode = map[string]map[string]struct{}{}
|
||||||
|
|
||||||
//加载本地结点的NodeList配置
|
//加载本地结点的NodeList配置
|
||||||
discoveryInfo, nodeInfoList,rpcMode, err := cls.readLocalClusterConfig(localNodeId)
|
discoveryInfo, nodeInfoList,rpcMode, err := cls.readLocalClusterConfig(localNodeId)
|
||||||
@@ -436,12 +458,37 @@ func (cls *Cluster) IsConfigService(serviceName string) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cls *Cluster) GetNodeIdByTemplateService(templateServiceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, []*rpc.Client) {
|
||||||
|
cls.locker.RLock()
|
||||||
|
defer cls.locker.RUnlock()
|
||||||
|
|
||||||
func (cls *Cluster) GetNodeIdByService(serviceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, int) {
|
mapServiceName := cls.mapTemplateServiceNode[templateServiceName]
|
||||||
|
for serviceName := range mapServiceName {
|
||||||
|
mapNodeId, ok := cls.mapServiceNode[serviceName]
|
||||||
|
if ok == true {
|
||||||
|
for nodeId, _ := range mapNodeId {
|
||||||
|
pClient,retire := GetCluster().getRpcClient(nodeId)
|
||||||
|
if pClient == nil || pClient.IsConnected() == false {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果需要筛选掉退休的,对retire状态的结点略过
|
||||||
|
if filterRetire == true && retire == true {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcClientList = append(rpcClientList,pClient)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, rpcClientList
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cls *Cluster) GetNodeIdByService(serviceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, []*rpc.Client) {
|
||||||
cls.locker.RLock()
|
cls.locker.RLock()
|
||||||
defer cls.locker.RUnlock()
|
defer cls.locker.RUnlock()
|
||||||
mapNodeId, ok := cls.mapServiceNode[serviceName]
|
mapNodeId, ok := cls.mapServiceNode[serviceName]
|
||||||
count := 0
|
|
||||||
if ok == true {
|
if ok == true {
|
||||||
for nodeId, _ := range mapNodeId {
|
for nodeId, _ := range mapNodeId {
|
||||||
pClient,retire := GetCluster().getRpcClient(nodeId)
|
pClient,retire := GetCluster().getRpcClient(nodeId)
|
||||||
@@ -454,15 +501,11 @@ func (cls *Cluster) GetNodeIdByService(serviceName string, rpcClientList []*rpc.
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcClientList[count] = pClient
|
rpcClientList = append(rpcClientList,pClient)
|
||||||
count++
|
|
||||||
if count >= cap(rpcClientList) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, count
|
return nil, rpcClientList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cls *Cluster) GetServiceCfg(serviceName string) interface{} {
|
func (cls *Cluster) GetServiceCfg(serviceName string) interface{} {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/duanhf2012/origin/v2/log"
|
"github.com/duanhf2012/origin/v2/log"
|
||||||
"github.com/duanhf2012/origin/v2/util/queue"
|
"github.com/duanhf2012/origin/v2/util/queue"
|
||||||
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
var idleTimeout = int64(2 * time.Second)
|
var idleTimeout = int64(2 * time.Second)
|
||||||
@@ -30,6 +31,9 @@ type dispatch struct {
|
|||||||
|
|
||||||
waitWorker sync.WaitGroup
|
waitWorker sync.WaitGroup
|
||||||
waitDispatch sync.WaitGroup
|
waitDispatch sync.WaitGroup
|
||||||
|
|
||||||
|
cancelContext context.Context
|
||||||
|
cancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dispatch) open(minGoroutineNum int32, maxGoroutineNum int32, tasks chan task, cbChannel chan func(error)) {
|
func (d *dispatch) open(minGoroutineNum int32, maxGoroutineNum int32, tasks chan task, cbChannel chan func(error)) {
|
||||||
@@ -40,7 +44,7 @@ func (d *dispatch) open(minGoroutineNum int32, maxGoroutineNum int32, tasks chan
|
|||||||
d.workerQueue = make(chan task)
|
d.workerQueue = make(chan task)
|
||||||
d.cbChannel = cbChannel
|
d.cbChannel = cbChannel
|
||||||
d.queueIdChannel = make(chan int64, cap(tasks))
|
d.queueIdChannel = make(chan int64, cap(tasks))
|
||||||
|
d.cancelContext,d.cancel = context.WithCancel(context.Background())
|
||||||
d.waitDispatch.Add(1)
|
d.waitDispatch.Add(1)
|
||||||
go d.run()
|
go d.run()
|
||||||
}
|
}
|
||||||
@@ -64,10 +68,12 @@ func (d *dispatch) run() {
|
|||||||
d.processqueueEvent(queueId)
|
d.processqueueEvent(queueId)
|
||||||
case <-timeout.C:
|
case <-timeout.C:
|
||||||
d.processTimer()
|
d.processTimer()
|
||||||
if atomic.LoadInt32(&d.minConcurrentNum) == -1 && len(d.tasks) == 0 {
|
case <- d.cancelContext.Done():
|
||||||
atomic.StoreInt64(&idleTimeout,int64(time.Millisecond * 10))
|
atomic.StoreInt64(&idleTimeout,int64(time.Millisecond * 5))
|
||||||
}
|
|
||||||
timeout.Reset(time.Duration(atomic.LoadInt64(&idleTimeout)))
|
timeout.Reset(time.Duration(atomic.LoadInt64(&idleTimeout)))
|
||||||
|
for i:=int32(0);i<d.workerNum;i++{
|
||||||
|
d.processIdle()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +172,8 @@ func (c *dispatch) pushAsyncDoCallbackEvent(cb func(err error)) {
|
|||||||
|
|
||||||
func (d *dispatch) close() {
|
func (d *dispatch) close() {
|
||||||
atomic.StoreInt32(&d.minConcurrentNum, -1)
|
atomic.StoreInt32(&d.minConcurrentNum, -1)
|
||||||
|
d.cancel()
|
||||||
|
|
||||||
|
|
||||||
breakFor:
|
breakFor:
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const (
|
|||||||
Sys_Event_QueueTaskFinish EventType = -10
|
Sys_Event_QueueTaskFinish EventType = -10
|
||||||
Sys_Event_Retire EventType = -11
|
Sys_Event_Retire EventType = -11
|
||||||
Sys_Event_EtcdDiscovery EventType = -12
|
Sys_Event_EtcdDiscovery EventType = -12
|
||||||
|
Sys_Event_Gin_Event EventType = -13
|
||||||
|
|
||||||
Sys_Event_User_Define EventType = 1
|
Sys_Event_User_Define EventType = 1
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,16 +10,20 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultSkip = 7
|
||||||
type IOriginHandler interface {
|
type IOriginHandler interface {
|
||||||
slog.Handler
|
slog.Handler
|
||||||
Lock()
|
Lock()
|
||||||
UnLock()
|
UnLock()
|
||||||
|
SetSkip(skip int)
|
||||||
|
GetSkip() int
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseHandler struct {
|
type BaseHandler struct {
|
||||||
addSource bool
|
addSource bool
|
||||||
w io.Writer
|
w io.Writer
|
||||||
locker sync.Mutex
|
locker sync.Mutex
|
||||||
|
skip int
|
||||||
}
|
}
|
||||||
|
|
||||||
type OriginTextHandler struct {
|
type OriginTextHandler struct {
|
||||||
@@ -32,6 +36,14 @@ type OriginJsonHandler struct {
|
|||||||
*slog.JSONHandler
|
*slog.JSONHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bh *BaseHandler) SetSkip(skip int){
|
||||||
|
bh.skip = skip
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bh *BaseHandler) GetSkip() int{
|
||||||
|
return bh.skip
|
||||||
|
}
|
||||||
|
|
||||||
func getStrLevel(level slog.Level) string{
|
func getStrLevel(level slog.Level) string{
|
||||||
switch level {
|
switch level {
|
||||||
case LevelTrace:
|
case LevelTrace:
|
||||||
@@ -78,6 +90,7 @@ func NewOriginTextHandler(level slog.Level,w io.Writer,addSource bool,replaceAtt
|
|||||||
ReplaceAttr: replaceAttr,
|
ReplaceAttr: replaceAttr,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
textHandler.skip = defaultSkip
|
||||||
return &textHandler
|
return &textHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +137,7 @@ func NewOriginJsonHandler(level slog.Level,w io.Writer,addSource bool,replaceAtt
|
|||||||
ReplaceAttr: replaceAttr,
|
ReplaceAttr: replaceAttr,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
jsonHandler.skip = defaultSkip
|
||||||
return &jsonHandler
|
return &jsonHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +155,7 @@ func (oh *OriginJsonHandler) Handle(context context.Context, record slog.Record)
|
|||||||
func (b *BaseHandler) Fill(context context.Context, record *slog.Record) {
|
func (b *BaseHandler) Fill(context context.Context, record *slog.Record) {
|
||||||
if b.addSource {
|
if b.addSource {
|
||||||
var pcs [1]uintptr
|
var pcs [1]uintptr
|
||||||
runtime.Callers(7, pcs[:])
|
runtime.Callers(b.skip, pcs[:])
|
||||||
record.PC = pcs[0]
|
record.PC = pcs[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,6 +239,10 @@ func (iw *IoWriter) swichFile() error{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDefaultHandler() IOriginHandler{
|
||||||
|
return gLogger.(*Logger).Slogger.Handler().(IOriginHandler)
|
||||||
|
}
|
||||||
|
|
||||||
func NewTextLogger(level slog.Level,pathName string,filePrefix string,addSource bool,logChannelCap int) (ILogger,error){
|
func NewTextLogger(level slog.Level,pathName string,filePrefix string,addSource bool,logChannelCap int) (ILogger,error){
|
||||||
var logger Logger
|
var logger Logger
|
||||||
logger.ioWriter.filePath = pathName
|
logger.ioWriter.filePath = pathName
|
||||||
|
|||||||
@@ -45,8 +45,10 @@ func (jsonProcessor *JsonProcessor) SetByteOrder(littleEndian bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// must goroutine safe
|
// must goroutine safe
|
||||||
func (jsonProcessor *JsonProcessor ) MsgRoute(clientId string,msg interface{}) error{
|
func (jsonProcessor *JsonProcessor ) MsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte)) error{
|
||||||
pPackInfo := msg.(*JsonPackInfo)
|
pPackInfo := msg.(*JsonPackInfo)
|
||||||
|
defer recyclerReaderBytes(pPackInfo.rawMsg)
|
||||||
|
|
||||||
v,ok := jsonProcessor.mapMsg[pPackInfo.typ]
|
v,ok := jsonProcessor.mapMsg[pPackInfo.typ]
|
||||||
if ok == false {
|
if ok == false {
|
||||||
return fmt.Errorf("cannot find msgtype %d is register!",pPackInfo.typ)
|
return fmt.Errorf("cannot find msgtype %d is register!",pPackInfo.typ)
|
||||||
@@ -58,7 +60,6 @@ func (jsonProcessor *JsonProcessor ) MsgRoute(clientId string,msg interface{}) e
|
|||||||
|
|
||||||
func (jsonProcessor *JsonProcessor) Unmarshal(clientId string,data []byte) (interface{}, error) {
|
func (jsonProcessor *JsonProcessor) Unmarshal(clientId string,data []byte) (interface{}, error) {
|
||||||
typeStruct := struct {Type int `json:"typ"`}{}
|
typeStruct := struct {Type int `json:"typ"`}{}
|
||||||
defer jsonProcessor.ReleaseBytes(data)
|
|
||||||
err := json.Unmarshal(data, &typeStruct)
|
err := json.Unmarshal(data, &typeStruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -76,7 +77,7 @@ func (jsonProcessor *JsonProcessor) Unmarshal(clientId string,data []byte) (inte
|
|||||||
return nil,err
|
return nil,err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &JsonPackInfo{typ:msgType,msg:msgData},nil
|
return &JsonPackInfo{typ:msgType,msg:msgData,rawMsg: data},nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jsonProcessor *JsonProcessor) Marshal(clientId string,msg interface{}) ([]byte, error) {
|
func (jsonProcessor *JsonProcessor) Marshal(clientId string,msg interface{}) ([]byte, error) {
|
||||||
@@ -104,7 +105,8 @@ func (jsonProcessor *JsonProcessor) MakeRawMsg(msgType uint16,msg []byte) *JsonP
|
|||||||
return &JsonPackInfo{typ:msgType,rawMsg:msg}
|
return &JsonPackInfo{typ:msgType,rawMsg:msg}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jsonProcessor *JsonProcessor) UnknownMsgRoute(clientId string,msg interface{}){
|
func (jsonProcessor *JsonProcessor) UnknownMsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte)){
|
||||||
|
defer recyclerReaderBytes(msg.([]byte))
|
||||||
if jsonProcessor.unknownMessageHandler==nil {
|
if jsonProcessor.unknownMessageHandler==nil {
|
||||||
log.Debug("Unknown message",log.String("clientId",clientId))
|
log.Debug("Unknown message",log.String("clientId",clientId))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -54,8 +54,10 @@ func (slf *PBPackInfo) GetMsg() proto.Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// must goroutine safe
|
// must goroutine safe
|
||||||
func (pbProcessor *PBProcessor) MsgRoute(clientId string, msg interface{}) error {
|
func (pbProcessor *PBProcessor) MsgRoute(clientId string, msg interface{},recyclerReaderBytes func(data []byte)) error {
|
||||||
pPackInfo := msg.(*PBPackInfo)
|
pPackInfo := msg.(*PBPackInfo)
|
||||||
|
defer recyclerReaderBytes(pPackInfo.rawMsg)
|
||||||
|
|
||||||
v, ok := pbProcessor.mapMsg[pPackInfo.typ]
|
v, ok := pbProcessor.mapMsg[pPackInfo.typ]
|
||||||
if ok == false {
|
if ok == false {
|
||||||
return fmt.Errorf("Cannot find msgtype %d is register!", pPackInfo.typ)
|
return fmt.Errorf("Cannot find msgtype %d is register!", pPackInfo.typ)
|
||||||
@@ -67,7 +69,6 @@ func (pbProcessor *PBProcessor) MsgRoute(clientId string, msg interface{}) error
|
|||||||
|
|
||||||
// must goroutine safe
|
// must goroutine safe
|
||||||
func (pbProcessor *PBProcessor) Unmarshal(clientId string, data []byte) (interface{}, error) {
|
func (pbProcessor *PBProcessor) Unmarshal(clientId string, data []byte) (interface{}, error) {
|
||||||
defer pbProcessor.ReleaseBytes(data)
|
|
||||||
return pbProcessor.UnmarshalWithOutRelease(clientId, data)
|
return pbProcessor.UnmarshalWithOutRelease(clientId, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ func (pbProcessor *PBProcessor) UnmarshalWithOutRelease(clientId string, data []
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &PBPackInfo{typ: msgType, msg: protoMsg}, nil
|
return &PBPackInfo{typ: msgType, msg: protoMsg,rawMsg:data}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// must goroutine safe
|
// must goroutine safe
|
||||||
@@ -133,8 +134,9 @@ func (pbProcessor *PBProcessor) MakeRawMsg(msgType uint16, msg []byte) *PBPackIn
|
|||||||
return &PBPackInfo{typ: msgType, rawMsg: msg}
|
return &PBPackInfo{typ: msgType, rawMsg: msg}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pbProcessor *PBProcessor) UnknownMsgRoute(clientId string, msg interface{}) {
|
func (pbProcessor *PBProcessor) UnknownMsgRoute(clientId string, msg interface{},recyclerReaderBytes func(data []byte)) {
|
||||||
pbProcessor.unknownMessageHandler(clientId, msg.([]byte))
|
pbProcessor.unknownMessageHandler(clientId, msg.([]byte))
|
||||||
|
recyclerReaderBytes(msg.([]byte))
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect event
|
// connect event
|
||||||
|
|||||||
@@ -38,9 +38,11 @@ func (pbRawProcessor *PBRawProcessor) SetByteOrder(littleEndian bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// must goroutine safe
|
// must goroutine safe
|
||||||
func (pbRawProcessor *PBRawProcessor ) MsgRoute(clientId string, msg interface{}) error{
|
func (pbRawProcessor *PBRawProcessor ) MsgRoute(clientId string, msg interface{},recyclerReaderBytes func(data []byte)) error{
|
||||||
pPackInfo := msg.(*PBRawPackInfo)
|
pPackInfo := msg.(*PBRawPackInfo)
|
||||||
pbRawProcessor.msgHandler(clientId,pPackInfo.typ,pPackInfo.rawMsg)
|
pbRawProcessor.msgHandler(clientId,pPackInfo.typ,pPackInfo.rawMsg)
|
||||||
|
recyclerReaderBytes(pPackInfo.rawMsg)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +82,8 @@ func (pbRawProcessor *PBRawProcessor) MakeRawMsg(msgType uint16,msg []byte,pbRaw
|
|||||||
pbRawPackInfo.rawMsg = msg
|
pbRawPackInfo.rawMsg = msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pbRawProcessor *PBRawProcessor) UnknownMsgRoute(clientId string,msg interface{}){
|
func (pbRawProcessor *PBRawProcessor) UnknownMsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte)){
|
||||||
|
defer recyclerReaderBytes(msg.([]byte))
|
||||||
if pbRawProcessor.unknownMessageHandler == nil {
|
if pbRawProcessor.unknownMessageHandler == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package processor
|
|||||||
|
|
||||||
type IProcessor interface {
|
type IProcessor interface {
|
||||||
// must goroutine safe
|
// must goroutine safe
|
||||||
MsgRoute(clientId string,msg interface{}) error
|
MsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte)) error
|
||||||
//must goroutine safe
|
//must goroutine safe
|
||||||
UnknownMsgRoute(clientId string,msg interface{})
|
UnknownMsgRoute(clientId string,msg interface{},recyclerReaderBytes func(data []byte))
|
||||||
// connect event
|
// connect event
|
||||||
ConnectedRoute(clientId string)
|
ConnectedRoute(clientId string)
|
||||||
DisConnectedRoute(clientId string)
|
DisConnectedRoute(clientId string)
|
||||||
|
|||||||
@@ -129,6 +129,13 @@ func (tcpConn *TCPConn) ReadMsg() ([]byte, error) {
|
|||||||
return tcpConn.msgParser.Read(tcpConn)
|
return tcpConn.msgParser.Read(tcpConn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tcpConn *TCPConn) GetRecyclerReaderBytes() func (data []byte) {
|
||||||
|
bytePool := tcpConn.msgParser.IBytesMempool
|
||||||
|
return func(data []byte) {
|
||||||
|
bytePool.ReleaseBytes(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (tcpConn *TCPConn) ReleaseReadMsg(byteBuff []byte){
|
func (tcpConn *TCPConn) ReleaseReadMsg(byteBuff []byte){
|
||||||
tcpConn.msgParser.ReleaseBytes(byteBuff)
|
tcpConn.msgParser.ReleaseBytes(byteBuff)
|
||||||
}
|
}
|
||||||
|
|||||||
46
node/node.go
46
node/node.go
@@ -25,9 +25,11 @@ import (
|
|||||||
var sig chan os.Signal
|
var sig chan os.Signal
|
||||||
var nodeId string
|
var nodeId string
|
||||||
var preSetupService []service.IService //预安装
|
var preSetupService []service.IService //预安装
|
||||||
|
var preSetupTemplateService []func()service.IService
|
||||||
var profilerInterval time.Duration
|
var profilerInterval time.Duration
|
||||||
var bValid bool
|
var bValid bool
|
||||||
var configDir = "./config/"
|
var configDir = "./config/"
|
||||||
|
var NodeIsRun = false
|
||||||
|
|
||||||
const(
|
const(
|
||||||
SingleStop syscall.Signal = 10
|
SingleStop syscall.Signal = 10
|
||||||
@@ -56,7 +58,7 @@ func init() {
|
|||||||
console.RegisterCommandString("loglevel", "debug", "<-loglevel debug|release|warning|error|fatal> Set loglevel.", setLevel)
|
console.RegisterCommandString("loglevel", "debug", "<-loglevel debug|release|warning|error|fatal> Set loglevel.", setLevel)
|
||||||
console.RegisterCommandString("logpath", "", "<-logpath path> Set log file path.", setLogPath)
|
console.RegisterCommandString("logpath", "", "<-logpath path> Set log file path.", setLogPath)
|
||||||
console.RegisterCommandInt("logsize", 0, "<-logsize size> Set log size(MB).", setLogSize)
|
console.RegisterCommandInt("logsize", 0, "<-logsize size> Set log size(MB).", setLogSize)
|
||||||
console.RegisterCommandInt("logchannelcap", 0, "<-logchannelcap num> Set log channel cap.", setLogChannelCapNum)
|
console.RegisterCommandInt("logchannelcap", -1, "<-logchannelcap num> Set log channel cap.", setLogChannelCapNum)
|
||||||
console.RegisterCommandString("pprof", "", "<-pprof ip:port> Open performance analysis.", setPprof)
|
console.RegisterCommandString("pprof", "", "<-pprof ip:port> Open performance analysis.", setPprof)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,6 +171,31 @@ func initNode(id string) {
|
|||||||
serviceOrder := cluster.GetCluster().GetLocalNodeInfo().ServiceList
|
serviceOrder := cluster.GetCluster().GetLocalNodeInfo().ServiceList
|
||||||
for _,serviceName:= range serviceOrder{
|
for _,serviceName:= range serviceOrder{
|
||||||
bSetup := false
|
bSetup := false
|
||||||
|
|
||||||
|
//判断是否有配置模板服务
|
||||||
|
splitServiceName := strings.Split(serviceName,":")
|
||||||
|
if len(splitServiceName) == 2 {
|
||||||
|
serviceName = splitServiceName[0]
|
||||||
|
templateServiceName := splitServiceName[1]
|
||||||
|
for _,newSer := range preSetupTemplateService {
|
||||||
|
ser := newSer()
|
||||||
|
ser.OnSetup(ser)
|
||||||
|
if ser.GetName() == templateServiceName {
|
||||||
|
ser.SetName(serviceName)
|
||||||
|
ser.Init(ser,cluster.GetRpcClient,cluster.GetRpcServer,cluster.GetCluster().GetServiceCfg(ser.GetName()))
|
||||||
|
service.Setup(ser)
|
||||||
|
|
||||||
|
bSetup = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if bSetup == false{
|
||||||
|
log.Error("Template service not found",log.String("service name",serviceName),log.String("template service name",templateServiceName))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, s := range preSetupService {
|
for _, s := range preSetupService {
|
||||||
if s.GetName() != serviceName {
|
if s.GetName() != serviceName {
|
||||||
continue
|
continue
|
||||||
@@ -328,13 +355,14 @@ func startNode(args interface{}) error {
|
|||||||
cluster.GetCluster().Start()
|
cluster.GetCluster().Start()
|
||||||
|
|
||||||
//6.监听程序退出信号&性能报告
|
//6.监听程序退出信号&性能报告
|
||||||
bRun := true
|
|
||||||
var pProfilerTicker *time.Ticker = &time.Ticker{}
|
var pProfilerTicker *time.Ticker = &time.Ticker{}
|
||||||
if profilerInterval > 0 {
|
if profilerInterval > 0 {
|
||||||
pProfilerTicker = time.NewTicker(profilerInterval)
|
pProfilerTicker = time.NewTicker(profilerInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
for bRun {
|
NodeIsRun = true
|
||||||
|
for NodeIsRun {
|
||||||
select {
|
select {
|
||||||
case s := <-sig:
|
case s := <-sig:
|
||||||
signal := s.(syscall.Signal)
|
signal := s.(syscall.Signal)
|
||||||
@@ -342,7 +370,7 @@ func startNode(args interface{}) error {
|
|||||||
log.Info("receipt retire signal.")
|
log.Info("receipt retire signal.")
|
||||||
notifyAllServiceRetire()
|
notifyAllServiceRetire()
|
||||||
}else {
|
}else {
|
||||||
bRun = false
|
NodeIsRun = false
|
||||||
log.Info("receipt stop signal.")
|
log.Info("receipt stop signal.")
|
||||||
}
|
}
|
||||||
case <-pProfilerTicker.C:
|
case <-pProfilerTicker.C:
|
||||||
@@ -367,6 +395,12 @@ func Setup(s ...service.IService) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetupTemplate(fs ...func()service.IService){
|
||||||
|
for _, f := range fs {
|
||||||
|
preSetupTemplateService = append(preSetupTemplateService, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetService(serviceName string) service.IService {
|
func GetService(serviceName string) service.IService {
|
||||||
return service.GetService(serviceName)
|
return service.GetService(serviceName)
|
||||||
}
|
}
|
||||||
@@ -472,6 +506,10 @@ func setLogChannelCapNum(args interface{}) error {
|
|||||||
return errors.New("param logsize is error")
|
return errors.New("param logsize is error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if logChannelCap == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
log.LogChannelCap = logChannelCap
|
log.LogChannelCap = logChannelCap
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.31.0
|
// protoc-gen-go v1.31.0
|
||||||
// protoc v3.11.4
|
// protoc v4.24.0
|
||||||
// source: test/rpc/messagequeue.proto
|
// source: rpcproto/messagequeue.proto
|
||||||
|
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
@@ -50,11 +50,11 @@ func (x SubscribeType) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (SubscribeType) Descriptor() protoreflect.EnumDescriptor {
|
func (SubscribeType) Descriptor() protoreflect.EnumDescriptor {
|
||||||
return file_test_rpc_messagequeue_proto_enumTypes[0].Descriptor()
|
return file_rpcproto_messagequeue_proto_enumTypes[0].Descriptor()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (SubscribeType) Type() protoreflect.EnumType {
|
func (SubscribeType) Type() protoreflect.EnumType {
|
||||||
return &file_test_rpc_messagequeue_proto_enumTypes[0]
|
return &file_rpcproto_messagequeue_proto_enumTypes[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x SubscribeType) Number() protoreflect.EnumNumber {
|
func (x SubscribeType) Number() protoreflect.EnumNumber {
|
||||||
@@ -63,7 +63,7 @@ func (x SubscribeType) Number() protoreflect.EnumNumber {
|
|||||||
|
|
||||||
// Deprecated: Use SubscribeType.Descriptor instead.
|
// Deprecated: Use SubscribeType.Descriptor instead.
|
||||||
func (SubscribeType) EnumDescriptor() ([]byte, []int) {
|
func (SubscribeType) EnumDescriptor() ([]byte, []int) {
|
||||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{0}
|
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubscribeMethod int32
|
type SubscribeMethod int32
|
||||||
@@ -96,11 +96,11 @@ func (x SubscribeMethod) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (SubscribeMethod) Descriptor() protoreflect.EnumDescriptor {
|
func (SubscribeMethod) Descriptor() protoreflect.EnumDescriptor {
|
||||||
return file_test_rpc_messagequeue_proto_enumTypes[1].Descriptor()
|
return file_rpcproto_messagequeue_proto_enumTypes[1].Descriptor()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (SubscribeMethod) Type() protoreflect.EnumType {
|
func (SubscribeMethod) Type() protoreflect.EnumType {
|
||||||
return &file_test_rpc_messagequeue_proto_enumTypes[1]
|
return &file_rpcproto_messagequeue_proto_enumTypes[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x SubscribeMethod) Number() protoreflect.EnumNumber {
|
func (x SubscribeMethod) Number() protoreflect.EnumNumber {
|
||||||
@@ -109,7 +109,7 @@ func (x SubscribeMethod) Number() protoreflect.EnumNumber {
|
|||||||
|
|
||||||
// Deprecated: Use SubscribeMethod.Descriptor instead.
|
// Deprecated: Use SubscribeMethod.Descriptor instead.
|
||||||
func (SubscribeMethod) EnumDescriptor() ([]byte, []int) {
|
func (SubscribeMethod) EnumDescriptor() ([]byte, []int) {
|
||||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{1}
|
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{1}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DBQueuePopReq struct {
|
type DBQueuePopReq struct {
|
||||||
@@ -127,7 +127,7 @@ type DBQueuePopReq struct {
|
|||||||
func (x *DBQueuePopReq) Reset() {
|
func (x *DBQueuePopReq) Reset() {
|
||||||
*x = DBQueuePopReq{}
|
*x = DBQueuePopReq{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[0]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[0]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ func (x *DBQueuePopReq) String() string {
|
|||||||
func (*DBQueuePopReq) ProtoMessage() {}
|
func (*DBQueuePopReq) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *DBQueuePopReq) ProtoReflect() protoreflect.Message {
|
func (x *DBQueuePopReq) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[0]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[0]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -153,7 +153,7 @@ func (x *DBQueuePopReq) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use DBQueuePopReq.ProtoReflect.Descriptor instead.
|
// Deprecated: Use DBQueuePopReq.ProtoReflect.Descriptor instead.
|
||||||
func (*DBQueuePopReq) Descriptor() ([]byte, []int) {
|
func (*DBQueuePopReq) Descriptor() ([]byte, []int) {
|
||||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{0}
|
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBQueuePopReq) GetCustomerId() string {
|
func (x *DBQueuePopReq) GetCustomerId() string {
|
||||||
@@ -203,7 +203,7 @@ type DBQueuePopRes struct {
|
|||||||
func (x *DBQueuePopRes) Reset() {
|
func (x *DBQueuePopRes) Reset() {
|
||||||
*x = DBQueuePopRes{}
|
*x = DBQueuePopRes{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[1]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[1]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ func (x *DBQueuePopRes) String() string {
|
|||||||
func (*DBQueuePopRes) ProtoMessage() {}
|
func (*DBQueuePopRes) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *DBQueuePopRes) ProtoReflect() protoreflect.Message {
|
func (x *DBQueuePopRes) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[1]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[1]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -229,7 +229,7 @@ func (x *DBQueuePopRes) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use DBQueuePopRes.ProtoReflect.Descriptor instead.
|
// Deprecated: Use DBQueuePopRes.ProtoReflect.Descriptor instead.
|
||||||
func (*DBQueuePopRes) Descriptor() ([]byte, []int) {
|
func (*DBQueuePopRes) Descriptor() ([]byte, []int) {
|
||||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{1}
|
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBQueuePopRes) GetQueueName() string {
|
func (x *DBQueuePopRes) GetQueueName() string {
|
||||||
@@ -255,7 +255,7 @@ type DBQueueSubscribeReq struct {
|
|||||||
SubType SubscribeType `protobuf:"varint,1,opt,name=SubType,proto3,enum=SubscribeType" json:"SubType,omitempty"` //订阅类型
|
SubType SubscribeType `protobuf:"varint,1,opt,name=SubType,proto3,enum=SubscribeType" json:"SubType,omitempty"` //订阅类型
|
||||||
Method SubscribeMethod `protobuf:"varint,2,opt,name=Method,proto3,enum=SubscribeMethod" json:"Method,omitempty"` //订阅方法
|
Method SubscribeMethod `protobuf:"varint,2,opt,name=Method,proto3,enum=SubscribeMethod" json:"Method,omitempty"` //订阅方法
|
||||||
CustomerId string `protobuf:"bytes,3,opt,name=CustomerId,proto3" json:"CustomerId,omitempty"` //消费者Id
|
CustomerId string `protobuf:"bytes,3,opt,name=CustomerId,proto3" json:"CustomerId,omitempty"` //消费者Id
|
||||||
FromNodeId int32 `protobuf:"varint,4,opt,name=FromNodeId,proto3" json:"FromNodeId,omitempty"`
|
FromNodeId string `protobuf:"bytes,4,opt,name=FromNodeId,proto3" json:"FromNodeId,omitempty"`
|
||||||
RpcMethod string `protobuf:"bytes,5,opt,name=RpcMethod,proto3" json:"RpcMethod,omitempty"`
|
RpcMethod string `protobuf:"bytes,5,opt,name=RpcMethod,proto3" json:"RpcMethod,omitempty"`
|
||||||
TopicName string `protobuf:"bytes,6,opt,name=TopicName,proto3" json:"TopicName,omitempty"` //主题名称
|
TopicName string `protobuf:"bytes,6,opt,name=TopicName,proto3" json:"TopicName,omitempty"` //主题名称
|
||||||
StartIndex uint64 `protobuf:"varint,7,opt,name=StartIndex,proto3" json:"StartIndex,omitempty"` //开始位置 ,格式前4位是时间戳秒,后面是序号。如果填0时,服务自动修改成:(4bit 当前时间秒)| (0000 4bit)
|
StartIndex uint64 `protobuf:"varint,7,opt,name=StartIndex,proto3" json:"StartIndex,omitempty"` //开始位置 ,格式前4位是时间戳秒,后面是序号。如果填0时,服务自动修改成:(4bit 当前时间秒)| (0000 4bit)
|
||||||
@@ -265,7 +265,7 @@ type DBQueueSubscribeReq struct {
|
|||||||
func (x *DBQueueSubscribeReq) Reset() {
|
func (x *DBQueueSubscribeReq) Reset() {
|
||||||
*x = DBQueueSubscribeReq{}
|
*x = DBQueueSubscribeReq{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[2]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[2]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -278,7 +278,7 @@ func (x *DBQueueSubscribeReq) String() string {
|
|||||||
func (*DBQueueSubscribeReq) ProtoMessage() {}
|
func (*DBQueueSubscribeReq) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *DBQueueSubscribeReq) ProtoReflect() protoreflect.Message {
|
func (x *DBQueueSubscribeReq) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[2]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[2]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -291,7 +291,7 @@ func (x *DBQueueSubscribeReq) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use DBQueueSubscribeReq.ProtoReflect.Descriptor instead.
|
// Deprecated: Use DBQueueSubscribeReq.ProtoReflect.Descriptor instead.
|
||||||
func (*DBQueueSubscribeReq) Descriptor() ([]byte, []int) {
|
func (*DBQueueSubscribeReq) Descriptor() ([]byte, []int) {
|
||||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{2}
|
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBQueueSubscribeReq) GetSubType() SubscribeType {
|
func (x *DBQueueSubscribeReq) GetSubType() SubscribeType {
|
||||||
@@ -315,11 +315,11 @@ func (x *DBQueueSubscribeReq) GetCustomerId() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBQueueSubscribeReq) GetFromNodeId() int32 {
|
func (x *DBQueueSubscribeReq) GetFromNodeId() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.FromNodeId
|
return x.FromNodeId
|
||||||
}
|
}
|
||||||
return 0
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBQueueSubscribeReq) GetRpcMethod() string {
|
func (x *DBQueueSubscribeReq) GetRpcMethod() string {
|
||||||
@@ -359,7 +359,7 @@ type DBQueueSubscribeRes struct {
|
|||||||
func (x *DBQueueSubscribeRes) Reset() {
|
func (x *DBQueueSubscribeRes) Reset() {
|
||||||
*x = DBQueueSubscribeRes{}
|
*x = DBQueueSubscribeRes{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[3]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[3]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -372,7 +372,7 @@ func (x *DBQueueSubscribeRes) String() string {
|
|||||||
func (*DBQueueSubscribeRes) ProtoMessage() {}
|
func (*DBQueueSubscribeRes) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *DBQueueSubscribeRes) ProtoReflect() protoreflect.Message {
|
func (x *DBQueueSubscribeRes) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[3]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[3]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -385,7 +385,7 @@ func (x *DBQueueSubscribeRes) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use DBQueueSubscribeRes.ProtoReflect.Descriptor instead.
|
// Deprecated: Use DBQueueSubscribeRes.ProtoReflect.Descriptor instead.
|
||||||
func (*DBQueueSubscribeRes) Descriptor() ([]byte, []int) {
|
func (*DBQueueSubscribeRes) Descriptor() ([]byte, []int) {
|
||||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{3}
|
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{3}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DBQueuePublishReq struct {
|
type DBQueuePublishReq struct {
|
||||||
@@ -400,7 +400,7 @@ type DBQueuePublishReq struct {
|
|||||||
func (x *DBQueuePublishReq) Reset() {
|
func (x *DBQueuePublishReq) Reset() {
|
||||||
*x = DBQueuePublishReq{}
|
*x = DBQueuePublishReq{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[4]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[4]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -413,7 +413,7 @@ func (x *DBQueuePublishReq) String() string {
|
|||||||
func (*DBQueuePublishReq) ProtoMessage() {}
|
func (*DBQueuePublishReq) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *DBQueuePublishReq) ProtoReflect() protoreflect.Message {
|
func (x *DBQueuePublishReq) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[4]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[4]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -426,7 +426,7 @@ func (x *DBQueuePublishReq) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use DBQueuePublishReq.ProtoReflect.Descriptor instead.
|
// Deprecated: Use DBQueuePublishReq.ProtoReflect.Descriptor instead.
|
||||||
func (*DBQueuePublishReq) Descriptor() ([]byte, []int) {
|
func (*DBQueuePublishReq) Descriptor() ([]byte, []int) {
|
||||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{4}
|
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{4}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBQueuePublishReq) GetTopicName() string {
|
func (x *DBQueuePublishReq) GetTopicName() string {
|
||||||
@@ -452,7 +452,7 @@ type DBQueuePublishRes struct {
|
|||||||
func (x *DBQueuePublishRes) Reset() {
|
func (x *DBQueuePublishRes) Reset() {
|
||||||
*x = DBQueuePublishRes{}
|
*x = DBQueuePublishRes{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[5]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[5]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@@ -465,7 +465,7 @@ func (x *DBQueuePublishRes) String() string {
|
|||||||
func (*DBQueuePublishRes) ProtoMessage() {}
|
func (*DBQueuePublishRes) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *DBQueuePublishRes) ProtoReflect() protoreflect.Message {
|
func (x *DBQueuePublishRes) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_test_rpc_messagequeue_proto_msgTypes[5]
|
mi := &file_rpcproto_messagequeue_proto_msgTypes[5]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@@ -478,13 +478,13 @@ func (x *DBQueuePublishRes) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use DBQueuePublishRes.ProtoReflect.Descriptor instead.
|
// Deprecated: Use DBQueuePublishRes.ProtoReflect.Descriptor instead.
|
||||||
func (*DBQueuePublishRes) Descriptor() ([]byte, []int) {
|
func (*DBQueuePublishRes) Descriptor() ([]byte, []int) {
|
||||||
return file_test_rpc_messagequeue_proto_rawDescGZIP(), []int{5}
|
return file_rpcproto_messagequeue_proto_rawDescGZIP(), []int{5}
|
||||||
}
|
}
|
||||||
|
|
||||||
var File_test_rpc_messagequeue_proto protoreflect.FileDescriptor
|
var File_rpcproto_messagequeue_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_test_rpc_messagequeue_proto_rawDesc = []byte{
|
var file_rpcproto_messagequeue_proto_rawDesc = []byte{
|
||||||
0x0a, 0x1b, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61,
|
0x0a, 0x1b, 0x72, 0x70, 0x63, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61,
|
||||||
0x67, 0x65, 0x71, 0x75, 0x65, 0x75, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa3, 0x01,
|
0x67, 0x65, 0x71, 0x75, 0x65, 0x75, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa3, 0x01,
|
||||||
0x0a, 0x0d, 0x44, 0x42, 0x51, 0x75, 0x65, 0x75, 0x65, 0x50, 0x6f, 0x70, 0x52, 0x65, 0x71, 0x12,
|
0x0a, 0x0d, 0x44, 0x42, 0x51, 0x75, 0x65, 0x75, 0x65, 0x50, 0x6f, 0x70, 0x52, 0x65, 0x71, 0x12,
|
||||||
0x1e, 0x0a, 0x0a, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20,
|
0x1e, 0x0a, 0x0a, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20,
|
||||||
@@ -510,7 +510,7 @@ var file_test_rpc_messagequeue_proto_rawDesc = []byte{
|
|||||||
0x6f, 0x64, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x43, 0x75,
|
0x6f, 0x64, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x43, 0x75,
|
||||||
0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
|
0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
|
||||||
0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x46, 0x72,
|
0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x46, 0x72,
|
||||||
0x6f, 0x6d, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a,
|
0x6f, 0x6d, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
|
||||||
0x46, 0x72, 0x6f, 0x6d, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x52, 0x70,
|
0x46, 0x72, 0x6f, 0x6d, 0x4e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x52, 0x70,
|
||||||
0x63, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x52,
|
0x63, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x52,
|
||||||
0x70, 0x63, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x6f, 0x70, 0x69,
|
0x70, 0x63, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x6f, 0x70, 0x69,
|
||||||
@@ -539,20 +539,20 @@ var file_test_rpc_messagequeue_proto_rawDesc = []byte{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_test_rpc_messagequeue_proto_rawDescOnce sync.Once
|
file_rpcproto_messagequeue_proto_rawDescOnce sync.Once
|
||||||
file_test_rpc_messagequeue_proto_rawDescData = file_test_rpc_messagequeue_proto_rawDesc
|
file_rpcproto_messagequeue_proto_rawDescData = file_rpcproto_messagequeue_proto_rawDesc
|
||||||
)
|
)
|
||||||
|
|
||||||
func file_test_rpc_messagequeue_proto_rawDescGZIP() []byte {
|
func file_rpcproto_messagequeue_proto_rawDescGZIP() []byte {
|
||||||
file_test_rpc_messagequeue_proto_rawDescOnce.Do(func() {
|
file_rpcproto_messagequeue_proto_rawDescOnce.Do(func() {
|
||||||
file_test_rpc_messagequeue_proto_rawDescData = protoimpl.X.CompressGZIP(file_test_rpc_messagequeue_proto_rawDescData)
|
file_rpcproto_messagequeue_proto_rawDescData = protoimpl.X.CompressGZIP(file_rpcproto_messagequeue_proto_rawDescData)
|
||||||
})
|
})
|
||||||
return file_test_rpc_messagequeue_proto_rawDescData
|
return file_rpcproto_messagequeue_proto_rawDescData
|
||||||
}
|
}
|
||||||
|
|
||||||
var file_test_rpc_messagequeue_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
|
var file_rpcproto_messagequeue_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
|
||||||
var file_test_rpc_messagequeue_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
var file_rpcproto_messagequeue_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
||||||
var file_test_rpc_messagequeue_proto_goTypes = []interface{}{
|
var file_rpcproto_messagequeue_proto_goTypes = []interface{}{
|
||||||
(SubscribeType)(0), // 0: SubscribeType
|
(SubscribeType)(0), // 0: SubscribeType
|
||||||
(SubscribeMethod)(0), // 1: SubscribeMethod
|
(SubscribeMethod)(0), // 1: SubscribeMethod
|
||||||
(*DBQueuePopReq)(nil), // 2: DBQueuePopReq
|
(*DBQueuePopReq)(nil), // 2: DBQueuePopReq
|
||||||
@@ -562,7 +562,7 @@ var file_test_rpc_messagequeue_proto_goTypes = []interface{}{
|
|||||||
(*DBQueuePublishReq)(nil), // 6: DBQueuePublishReq
|
(*DBQueuePublishReq)(nil), // 6: DBQueuePublishReq
|
||||||
(*DBQueuePublishRes)(nil), // 7: DBQueuePublishRes
|
(*DBQueuePublishRes)(nil), // 7: DBQueuePublishRes
|
||||||
}
|
}
|
||||||
var file_test_rpc_messagequeue_proto_depIdxs = []int32{
|
var file_rpcproto_messagequeue_proto_depIdxs = []int32{
|
||||||
0, // 0: DBQueueSubscribeReq.SubType:type_name -> SubscribeType
|
0, // 0: DBQueueSubscribeReq.SubType:type_name -> SubscribeType
|
||||||
1, // 1: DBQueueSubscribeReq.Method:type_name -> SubscribeMethod
|
1, // 1: DBQueueSubscribeReq.Method:type_name -> SubscribeMethod
|
||||||
2, // [2:2] is the sub-list for method output_type
|
2, // [2:2] is the sub-list for method output_type
|
||||||
@@ -572,13 +572,13 @@ var file_test_rpc_messagequeue_proto_depIdxs = []int32{
|
|||||||
0, // [0:2] is the sub-list for field type_name
|
0, // [0:2] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_test_rpc_messagequeue_proto_init() }
|
func init() { file_rpcproto_messagequeue_proto_init() }
|
||||||
func file_test_rpc_messagequeue_proto_init() {
|
func file_rpcproto_messagequeue_proto_init() {
|
||||||
if File_test_rpc_messagequeue_proto != nil {
|
if File_rpcproto_messagequeue_proto != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !protoimpl.UnsafeEnabled {
|
if !protoimpl.UnsafeEnabled {
|
||||||
file_test_rpc_messagequeue_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
file_rpcproto_messagequeue_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*DBQueuePopReq); i {
|
switch v := v.(*DBQueuePopReq); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@@ -590,7 +590,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_test_rpc_messagequeue_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
file_rpcproto_messagequeue_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*DBQueuePopRes); i {
|
switch v := v.(*DBQueuePopRes); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@@ -602,7 +602,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_test_rpc_messagequeue_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
file_rpcproto_messagequeue_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*DBQueueSubscribeReq); i {
|
switch v := v.(*DBQueueSubscribeReq); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@@ -614,7 +614,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_test_rpc_messagequeue_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
file_rpcproto_messagequeue_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*DBQueueSubscribeRes); i {
|
switch v := v.(*DBQueueSubscribeRes); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@@ -626,7 +626,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_test_rpc_messagequeue_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
file_rpcproto_messagequeue_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*DBQueuePublishReq); i {
|
switch v := v.(*DBQueuePublishReq); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@@ -638,7 +638,7 @@ func file_test_rpc_messagequeue_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_test_rpc_messagequeue_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
file_rpcproto_messagequeue_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*DBQueuePublishRes); i {
|
switch v := v.(*DBQueuePublishRes); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@@ -655,19 +655,19 @@ func file_test_rpc_messagequeue_proto_init() {
|
|||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
File: protoimpl.DescBuilder{
|
File: protoimpl.DescBuilder{
|
||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: file_test_rpc_messagequeue_proto_rawDesc,
|
RawDescriptor: file_rpcproto_messagequeue_proto_rawDesc,
|
||||||
NumEnums: 2,
|
NumEnums: 2,
|
||||||
NumMessages: 6,
|
NumMessages: 6,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 0,
|
NumServices: 0,
|
||||||
},
|
},
|
||||||
GoTypes: file_test_rpc_messagequeue_proto_goTypes,
|
GoTypes: file_rpcproto_messagequeue_proto_goTypes,
|
||||||
DependencyIndexes: file_test_rpc_messagequeue_proto_depIdxs,
|
DependencyIndexes: file_rpcproto_messagequeue_proto_depIdxs,
|
||||||
EnumInfos: file_test_rpc_messagequeue_proto_enumTypes,
|
EnumInfos: file_rpcproto_messagequeue_proto_enumTypes,
|
||||||
MessageInfos: file_test_rpc_messagequeue_proto_msgTypes,
|
MessageInfos: file_rpcproto_messagequeue_proto_msgTypes,
|
||||||
}.Build()
|
}.Build()
|
||||||
File_test_rpc_messagequeue_proto = out.File
|
File_rpcproto_messagequeue_proto = out.File
|
||||||
file_test_rpc_messagequeue_proto_rawDesc = nil
|
file_rpcproto_messagequeue_proto_rawDesc = nil
|
||||||
file_test_rpc_messagequeue_proto_goTypes = nil
|
file_rpcproto_messagequeue_proto_goTypes = nil
|
||||||
file_test_rpc_messagequeue_proto_depIdxs = nil
|
file_rpcproto_messagequeue_proto_depIdxs = nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ message DBQueueSubscribeReq {
|
|||||||
SubscribeType SubType = 1; //订阅类型
|
SubscribeType SubType = 1; //订阅类型
|
||||||
SubscribeMethod Method = 2; //订阅方法
|
SubscribeMethod Method = 2; //订阅方法
|
||||||
string CustomerId = 3; //消费者Id
|
string CustomerId = 3; //消费者Id
|
||||||
int32 FromNodeId = 4;
|
string FromNodeId = 4;
|
||||||
string RpcMethod = 5;
|
string RpcMethod = 5;
|
||||||
string TopicName = 6; //主题名称
|
string TopicName = 6; //主题名称
|
||||||
uint64 StartIndex = 7; //开始位置 ,格式前4位是时间戳秒,后面是序号。如果填0时,服务自动修改成:(4bit 当前时间秒)| (0000 4bit)
|
uint64 StartIndex = 7; //开始位置 ,格式前4位是时间戳秒,后面是序号。如果填0时,服务自动修改成:(4bit 当前时间秒)| (0000 4bit)
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxClusterNode int = 128
|
const maxClusterNode int = 32
|
||||||
|
|
||||||
type FuncRpcClient func(nodeId string, serviceMethod string,filterRetire bool, client []*Client) (error, int)
|
type FuncRpcClient func(nodeId string, serviceMethod string,filterRetire bool, client []*Client) (error, []*Client)
|
||||||
type FuncRpcServer func() IServer
|
type FuncRpcServer func() IServer
|
||||||
const NodeIdNull = ""
|
const NodeIdNull = ""
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ type RpcHandler struct {
|
|||||||
funcRpcClient FuncRpcClient
|
funcRpcClient FuncRpcClient
|
||||||
funcRpcServer FuncRpcServer
|
funcRpcServer FuncRpcServer
|
||||||
|
|
||||||
pClientList []*Client
|
//pClientList []*Client
|
||||||
}
|
}
|
||||||
|
|
||||||
//type TriggerRpcConnEvent func(bConnect bool, clientSeq uint32, nodeId string)
|
//type TriggerRpcConnEvent func(bConnect bool, clientSeq uint32, nodeId string)
|
||||||
@@ -110,7 +110,6 @@ type IRpcHandler interface {
|
|||||||
GoNode(nodeId string, serviceMethod string, args interface{}) error
|
GoNode(nodeId string, serviceMethod string, args interface{}) error
|
||||||
RawGoNode(rpcProcessorType RpcProcessorType, nodeId string, rpcMethodId uint32, serviceName string, rawArgs []byte) error
|
RawGoNode(rpcProcessorType RpcProcessorType, nodeId string, rpcMethodId uint32, serviceName string, rawArgs []byte) error
|
||||||
CastGo(serviceMethod string, args interface{}) error
|
CastGo(serviceMethod string, args interface{}) error
|
||||||
IsSingleCoroutine() bool
|
|
||||||
UnmarshalInParam(rpcProcessor IRpcProcessor, serviceMethod string, rawRpcMethodId uint32, inParam []byte) (interface{}, error)
|
UnmarshalInParam(rpcProcessor IRpcProcessor, serviceMethod string, rawRpcMethodId uint32, inParam []byte) (interface{}, error)
|
||||||
GetRpcServer() FuncRpcServer
|
GetRpcServer() FuncRpcServer
|
||||||
}
|
}
|
||||||
@@ -135,7 +134,6 @@ func (handler *RpcHandler) InitRpcHandler(rpcHandler IRpcHandler, getClientFun F
|
|||||||
handler.mapFunctions = map[string]RpcMethodInfo{}
|
handler.mapFunctions = map[string]RpcMethodInfo{}
|
||||||
handler.funcRpcClient = getClientFun
|
handler.funcRpcClient = getClientFun
|
||||||
handler.funcRpcServer = getServerFun
|
handler.funcRpcServer = getServerFun
|
||||||
handler.pClientList = make([]*Client, maxClusterNode)
|
|
||||||
handler.RegisterRpc(rpcHandler)
|
handler.RegisterRpc(rpcHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +272,7 @@ func (handler *RpcHandler) HandlerRpcRequest(request *RpcRequest) {
|
|||||||
//普通的rpc请求
|
//普通的rpc请求
|
||||||
v, ok := handler.mapFunctions[request.RpcRequestData.GetServiceMethod()]
|
v, ok := handler.mapFunctions[request.RpcRequestData.GetServiceMethod()]
|
||||||
if ok == false {
|
if ok == false {
|
||||||
err := "RpcHandler " + handler.rpcHandler.GetName() + "cannot find " + request.RpcRequestData.GetServiceMethod()
|
err := "RpcHandler " + handler.rpcHandler.GetName() + " cannot find " + request.RpcRequestData.GetServiceMethod()
|
||||||
log.Error("HandlerRpcRequest cannot find serviceMethod",log.String("RpcHandlerName",handler.rpcHandler.GetName()),log.String("serviceMethod",request.RpcRequestData.GetServiceMethod()))
|
log.Error("HandlerRpcRequest cannot find serviceMethod",log.String("RpcHandlerName",handler.rpcHandler.GetName()),log.String("serviceMethod",request.RpcRequestData.GetServiceMethod()))
|
||||||
if request.requestHandle != nil {
|
if request.requestHandle != nil {
|
||||||
request.requestHandle(nil, RpcError(err))
|
request.requestHandle(nil, RpcError(err))
|
||||||
@@ -435,9 +433,9 @@ func (handler *RpcHandler) CallMethod(client *Client,ServiceMethod string, param
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (handler *RpcHandler) goRpc(processor IRpcProcessor, bCast bool, nodeId string, serviceMethod string, args interface{}) error {
|
func (handler *RpcHandler) goRpc(processor IRpcProcessor, bCast bool, nodeId string, serviceMethod string, args interface{}) error {
|
||||||
var pClientList [maxClusterNode]*Client
|
pClientList :=make([]*Client,0,maxClusterNode)
|
||||||
err, count := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList[:])
|
err, pClientList := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList)
|
||||||
if count == 0 {
|
if len(pClientList) == 0 {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("call serviceMethod is failed",log.String("serviceMethod",serviceMethod),log.ErrorAttr("error",err))
|
log.Error("call serviceMethod is failed",log.String("serviceMethod",serviceMethod),log.ErrorAttr("error",err))
|
||||||
} else {
|
} else {
|
||||||
@@ -446,13 +444,13 @@ func (handler *RpcHandler) goRpc(processor IRpcProcessor, bCast bool, nodeId str
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if count > 1 && bCast == false {
|
if len(pClientList) > 1 && bCast == false {
|
||||||
log.Error("cannot call serviceMethod more then 1 node",log.String("serviceMethod",serviceMethod))
|
log.Error("cannot call serviceMethod more then 1 node",log.String("serviceMethod",serviceMethod))
|
||||||
return errors.New("cannot call more then 1 node")
|
return errors.New("cannot call more then 1 node")
|
||||||
}
|
}
|
||||||
|
|
||||||
//2.rpcClient调用
|
//2.rpcClient调用
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < len(pClientList); i++ {
|
||||||
pCall := pClientList[i].Go(pClientList[i].GetTargetNodeId(),DefaultRpcTimeout,handler.rpcHandler,true, serviceMethod, args, nil)
|
pCall := pClientList[i].Go(pClientList[i].GetTargetNodeId(),DefaultRpcTimeout,handler.rpcHandler,true, serviceMethod, args, nil)
|
||||||
if pCall.Err != nil {
|
if pCall.Err != nil {
|
||||||
err = pCall.Err
|
err = pCall.Err
|
||||||
@@ -465,16 +463,16 @@ func (handler *RpcHandler) goRpc(processor IRpcProcessor, bCast bool, nodeId str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (handler *RpcHandler) callRpc(timeout time.Duration,nodeId string, serviceMethod string, args interface{}, reply interface{}) error {
|
func (handler *RpcHandler) callRpc(timeout time.Duration,nodeId string, serviceMethod string, args interface{}, reply interface{}) error {
|
||||||
var pClientList [maxClusterNode]*Client
|
pClientList :=make([]*Client,0,maxClusterNode)
|
||||||
err, count := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList[:])
|
err, pClientList := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Call serviceMethod is failed",log.ErrorAttr("error",err))
|
log.Error("Call serviceMethod is failed",log.ErrorAttr("error",err))
|
||||||
return err
|
return err
|
||||||
} else if count <= 0 {
|
} else if len(pClientList) <= 0 {
|
||||||
err = errors.New("Call serviceMethod is error:cannot find " + serviceMethod)
|
err = errors.New("Call serviceMethod is error:cannot find " + serviceMethod)
|
||||||
log.Error("cannot find serviceMethod",log.String("serviceMethod",serviceMethod))
|
log.Error("cannot find serviceMethod",log.String("serviceMethod",serviceMethod))
|
||||||
return err
|
return err
|
||||||
} else if count > 1 {
|
} else if len(pClientList) > 1 {
|
||||||
log.Error("Cannot call more then 1 node!",log.String("serviceMethod",serviceMethod))
|
log.Error("Cannot call more then 1 node!",log.String("serviceMethod",serviceMethod))
|
||||||
return errors.New("cannot call more then 1 node")
|
return errors.New("cannot call more then 1 node")
|
||||||
}
|
}
|
||||||
@@ -509,9 +507,9 @@ func (handler *RpcHandler) asyncCallRpc(timeout time.Duration,nodeId string, ser
|
|||||||
}
|
}
|
||||||
|
|
||||||
reply := reflect.New(fVal.Type().In(0).Elem()).Interface()
|
reply := reflect.New(fVal.Type().In(0).Elem()).Interface()
|
||||||
var pClientList [2]*Client
|
pClientList :=make([]*Client,0,1)
|
||||||
err, count := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList[:])
|
err, pClientList := handler.funcRpcClient(nodeId, serviceMethod,false, pClientList[:])
|
||||||
if count == 0 || err != nil {
|
if len(pClientList) == 0 || err != nil {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if nodeId != NodeIdNull {
|
if nodeId != NodeIdNull {
|
||||||
err = fmt.Errorf("cannot find %s from nodeId %d",serviceMethod,nodeId)
|
err = fmt.Errorf("cannot find %s from nodeId %d",serviceMethod,nodeId)
|
||||||
@@ -524,7 +522,7 @@ func (handler *RpcHandler) asyncCallRpc(timeout time.Duration,nodeId string, ser
|
|||||||
return emptyCancelRpc,nil
|
return emptyCancelRpc,nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if count > 1 {
|
if len(pClientList) > 1 {
|
||||||
err := errors.New("cannot call more then 1 node")
|
err := errors.New("cannot call more then 1 node")
|
||||||
fVal.Call([]reflect.Value{reflect.ValueOf(reply), reflect.ValueOf(err)})
|
fVal.Call([]reflect.Value{reflect.ValueOf(reply), reflect.ValueOf(err)})
|
||||||
log.Error("cannot call more then 1 node",log.String("serviceMethod",serviceMethod))
|
log.Error("cannot call more then 1 node",log.String("serviceMethod",serviceMethod))
|
||||||
@@ -540,10 +538,6 @@ func (handler *RpcHandler) GetName() string {
|
|||||||
return handler.rpcHandler.GetName()
|
return handler.rpcHandler.GetName()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *RpcHandler) IsSingleCoroutine() bool {
|
|
||||||
return handler.rpcHandler.IsSingleCoroutine()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (handler *RpcHandler) CallWithTimeout(timeout time.Duration,serviceMethod string, args interface{}, reply interface{}) error {
|
func (handler *RpcHandler) CallWithTimeout(timeout time.Duration,serviceMethod string, args interface{}, reply interface{}) error {
|
||||||
return handler.callRpc(timeout,NodeIdNull, serviceMethod, args, reply)
|
return handler.callRpc(timeout,NodeIdNull, serviceMethod, args, reply)
|
||||||
}
|
}
|
||||||
@@ -593,12 +587,13 @@ func (handler *RpcHandler) CastGo(serviceMethod string, args interface{}) error
|
|||||||
|
|
||||||
func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType, nodeId string, rpcMethodId uint32, serviceName string, rawArgs []byte) error {
|
func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType, nodeId string, rpcMethodId uint32, serviceName string, rawArgs []byte) error {
|
||||||
processor := GetProcessor(uint8(rpcProcessorType))
|
processor := GetProcessor(uint8(rpcProcessorType))
|
||||||
err, count := handler.funcRpcClient(nodeId, serviceName,false, handler.pClientList)
|
pClientList := make([]*Client,0,1)
|
||||||
if count == 0 || err != nil {
|
err, pClientList := handler.funcRpcClient(nodeId, serviceName,false, pClientList)
|
||||||
|
if len(pClientList) == 0 || err != nil {
|
||||||
log.Error("call serviceMethod is failed",log.ErrorAttr("error",err))
|
log.Error("call serviceMethod is failed",log.ErrorAttr("error",err))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if count > 1 {
|
if len(pClientList) > 1 {
|
||||||
err := errors.New("cannot call more then 1 node")
|
err := errors.New("cannot call more then 1 node")
|
||||||
log.Error("cannot call more then 1 node",log.String("serviceName",serviceName))
|
log.Error("cannot call more then 1 node",log.String("serviceName",serviceName))
|
||||||
return err
|
return err
|
||||||
@@ -606,14 +601,14 @@ func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType, nodeId s
|
|||||||
|
|
||||||
//2.rpcClient调用
|
//2.rpcClient调用
|
||||||
//如果调用本结点服务
|
//如果调用本结点服务
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < len(pClientList); i++ {
|
||||||
//跨node调用
|
//跨node调用
|
||||||
pCall := handler.pClientList[i].RawGo(handler.pClientList[i].GetTargetNodeId(),DefaultRpcTimeout,handler.rpcHandler,processor, true, rpcMethodId, serviceName, rawArgs, nil)
|
pCall := pClientList[i].RawGo(pClientList[i].GetTargetNodeId(),DefaultRpcTimeout,handler.rpcHandler,processor, true, rpcMethodId, serviceName, rawArgs, nil)
|
||||||
if pCall.Err != nil {
|
if pCall.Err != nil {
|
||||||
err = pCall.Err
|
err = pCall.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.pClientList[i].RemovePending(pCall.Seq)
|
pClientList[i].RemovePending(pCall.Seq)
|
||||||
ReleaseCall(pCall)
|
ReleaseCall(pCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,14 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"github.com/duanhf2012/origin/v2/concurrent"
|
"github.com/duanhf2012/origin/v2/concurrent"
|
||||||
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
var timerDispatcherLen = 100000
|
var timerDispatcherLen = 100000
|
||||||
var maxServiceEventChannelNum = 2000000
|
var maxServiceEventChannelNum = 2000000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type IService interface {
|
type IService interface {
|
||||||
concurrent.IConcurrent
|
concurrent.IConcurrent
|
||||||
Init(iService IService,getClientFun rpc.FuncRpcClient,getServerFun rpc.FuncRpcServer,serviceCfg interface{})
|
Init(iService IService,getClientFun rpc.FuncRpcClient,getServerFun rpc.FuncRpcServer,serviceCfg interface{})
|
||||||
@@ -55,6 +58,7 @@ type Service struct {
|
|||||||
serviceCfg interface{}
|
serviceCfg interface{}
|
||||||
goroutineNum int32
|
goroutineNum int32
|
||||||
startStatus bool
|
startStatus bool
|
||||||
|
isRelease int32
|
||||||
retire int32
|
retire int32
|
||||||
eventProcessor event.IEventProcessor
|
eventProcessor event.IEventProcessor
|
||||||
profiler *profiler.Profiler //性能分析器
|
profiler *profiler.Profiler //性能分析器
|
||||||
@@ -145,6 +149,7 @@ func (s *Service) Init(iService IService,getClientFun rpc.FuncRpcClient,getServe
|
|||||||
|
|
||||||
func (s *Service) Start() {
|
func (s *Service) Start() {
|
||||||
s.startStatus = true
|
s.startStatus = true
|
||||||
|
atomic.StoreInt32(&s.isRelease,0)
|
||||||
var waitRun sync.WaitGroup
|
var waitRun sync.WaitGroup
|
||||||
|
|
||||||
for i:=int32(0);i< s.goroutineNum;i++{
|
for i:=int32(0);i< s.goroutineNum;i++{
|
||||||
@@ -173,6 +178,7 @@ func (s *Service) Run() {
|
|||||||
select {
|
select {
|
||||||
case <- s.closeSig:
|
case <- s.closeSig:
|
||||||
bStop = true
|
bStop = true
|
||||||
|
s.Release()
|
||||||
concurrent.Close()
|
concurrent.Close()
|
||||||
case cb:=<-concurrentCBChannel:
|
case cb:=<-concurrentCBChannel:
|
||||||
concurrent.DoCallback(cb)
|
concurrent.DoCallback(cb)
|
||||||
@@ -245,10 +251,6 @@ func (s *Service) Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if bStop == true {
|
if bStop == true {
|
||||||
if atomic.AddInt32(&s.goroutineNum,-1)<=0 {
|
|
||||||
s.startStatus = false
|
|
||||||
s.Release()
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,8 +273,11 @@ func (s *Service) Release(){
|
|||||||
log.Dump(string(buf[:l]),log.String("error",errString))
|
log.Dump(string(buf[:l]),log.String("error",errString))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
s.self.OnRelease()
|
if atomic.AddInt32(&s.isRelease,-1) == -1{
|
||||||
|
s.self.OnRelease()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) OnRelease(){
|
func (s *Service) OnRelease(){
|
||||||
@@ -293,6 +298,24 @@ func (s *Service) GetServiceCfg()interface{}{
|
|||||||
return s.serviceCfg
|
return s.serviceCfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) ParseServiceCfg(cfg interface{}) error{
|
||||||
|
if s.serviceCfg == nil {
|
||||||
|
return errors.New("no service configuration found")
|
||||||
|
}
|
||||||
|
|
||||||
|
rv := reflect.ValueOf(s.serviceCfg)
|
||||||
|
if rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||||
|
return errors.New("no service configuration found")
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes,err := json.Marshal(s.serviceCfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Unmarshal(bytes,cfg)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) GetProfiler() *profiler.Profiler{
|
func (s *Service) GetProfiler() *profiler.Profiler{
|
||||||
return s.profiler
|
return s.profiler
|
||||||
}
|
}
|
||||||
@@ -305,10 +328,6 @@ func (s *Service) UnRegEventReceiverFunc(eventType event.EventType, receiver eve
|
|||||||
s.eventProcessor.UnRegEventReceiverFun(eventType, receiver)
|
s.eventProcessor.UnRegEventReceiverFun(eventType, receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) IsSingleCoroutine() bool {
|
|
||||||
return s.goroutineNum == 1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) RegRawRpc(rpcMethodId uint32,rawRpcCB rpc.RawRpcCallBack){
|
func (s *Service) RegRawRpc(rpcMethodId uint32,rawRpcCB rpc.RawRpcCallBack){
|
||||||
s.rpcHandler.RegRawRpc(rpcMethodId,rawRpcCB)
|
s.rpcHandler.RegRawRpc(rpcMethodId,rawRpcCB)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func Init() {
|
|||||||
for _,s := range setupServiceList {
|
for _,s := range setupServiceList {
|
||||||
err := s.OnInit()
|
err := s.OnInit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.SError("Failed to initialize "+s.GetName()+" service:"+err.Error())
|
log.Error("Failed to initialize "+s.GetName()+" service",log.ErrorAttr("err",err))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package ginmodule
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"datacenter/common/processor"
|
|
||||||
"github.com/duanhf2012/origin/v2/event"
|
"github.com/duanhf2012/origin/v2/event"
|
||||||
"github.com/duanhf2012/origin/v2/log"
|
"github.com/duanhf2012/origin/v2/log"
|
||||||
"github.com/duanhf2012/origin/v2/service"
|
"github.com/duanhf2012/origin/v2/service"
|
||||||
@@ -10,34 +9,36 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type IGinProcessor interface {
|
||||||
|
Process(data *gin.Context) (*gin.Context, error)
|
||||||
|
}
|
||||||
|
|
||||||
type GinModule struct {
|
type GinModule struct {
|
||||||
service.Module
|
service.Module
|
||||||
|
|
||||||
*GinConf
|
|
||||||
*gin.Engine
|
*gin.Engine
|
||||||
srv *http.Server
|
srv *http.Server
|
||||||
|
|
||||||
processor []processor.IGinProcessor
|
listenAddr string
|
||||||
|
handleTimeout time.Duration
|
||||||
|
processor []IGinProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
type GinConf struct {
|
func (gm *GinModule) Init(addr string, handleTimeout time.Duration,engine *gin.Engine) {
|
||||||
Addr string
|
gm.listenAddr = addr
|
||||||
}
|
gm.handleTimeout = handleTimeout
|
||||||
|
|
||||||
const Sys_Event_Gin_Event event.EventType = -11
|
|
||||||
|
|
||||||
func (gm *GinModule) Init(conf *GinConf, engine *gin.Engine) {
|
|
||||||
gm.GinConf = conf
|
|
||||||
gm.Engine = engine
|
gm.Engine = engine
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) SetupDataProcessor(processor ...processor.IGinProcessor) {
|
func (gm *GinModule) SetupDataProcessor(processor ...IGinProcessor) {
|
||||||
gm.processor = processor
|
gm.processor = processor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) AppendDataProcessor(processor ...processor.IGinProcessor) {
|
func (gm *GinModule) AppendDataProcessor(processor ...IGinProcessor) {
|
||||||
gm.processor = append(gm.processor, processor...)
|
gm.processor = append(gm.processor, processor...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,27 +48,28 @@ func (gm *GinModule) OnInit() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gm.srv = &http.Server{
|
gm.srv = &http.Server{
|
||||||
Addr: gm.Addr,
|
Addr: gm.listenAddr,
|
||||||
Handler: gm.Engine,
|
Handler: gm.Engine,
|
||||||
}
|
}
|
||||||
|
|
||||||
gm.Engine.Use(Logger())
|
gm.Engine.Use(Logger())
|
||||||
gm.Engine.Use(gin.Recovery())
|
gm.Engine.Use(gin.Recovery())
|
||||||
gm.GetEventProcessor().RegEventReceiverFunc(Sys_Event_Gin_Event, gm.GetEventHandler(), gm.eventHandler)
|
gm.GetEventProcessor().RegEventReceiverFunc(event.Sys_Event_Gin_Event, gm.GetEventHandler(), gm.eventHandler)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) eventHandler(ev event.IEvent) {
|
func (gm *GinModule) eventHandler(ev event.IEvent) {
|
||||||
ginEvent := ev.(*GinEvent)
|
ginEvent := ev.(*GinEvent)
|
||||||
for _, handler := range ginEvent.handlersChain {
|
for _, handler := range ginEvent.handlersChain {
|
||||||
handler(ginEvent.c)
|
handler(&ginEvent.c)
|
||||||
}
|
}
|
||||||
|
|
||||||
ginEvent.chanWait <- struct{}{}
|
//ginEvent.chanWait <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) Start() {
|
func (gm *GinModule) Start() {
|
||||||
log.Info("http start listen", slog.Any("addr", gm.Addr))
|
gm.srv.Addr = gm.listenAddr
|
||||||
|
log.Info("http start listen", slog.Any("addr", gm.listenAddr))
|
||||||
go func() {
|
go func() {
|
||||||
err := gm.srv.ListenAndServe()
|
err := gm.srv.ListenAndServe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -77,7 +79,7 @@ func (gm *GinModule) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) StartTLS(certFile, keyFile string) {
|
func (gm *GinModule) StartTLS(certFile, keyFile string) {
|
||||||
log.Info("http start listen", slog.Any("addr", gm.Addr))
|
log.Info("http start listen", slog.Any("addr", gm.listenAddr))
|
||||||
go func() {
|
go func() {
|
||||||
err := gm.srv.ListenAndServeTLS(certFile, keyFile)
|
err := gm.srv.ListenAndServeTLS(certFile, keyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -92,17 +94,102 @@ func (gm *GinModule) Stop(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type GinEvent struct {
|
type SafeContext struct {
|
||||||
handlersChain gin.HandlersChain
|
*gin.Context
|
||||||
chanWait chan struct{}
|
chanWait chan struct{}
|
||||||
c *gin.Context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) JSONAndDone(code int, obj any) {
|
||||||
|
c.Context.JSON(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) AsciiJSONAndDone(code int, obj any){
|
||||||
|
c.Context.AsciiJSON(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) PureJSONAndDone(code int, obj any){
|
||||||
|
c.Context.PureJSON(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) XMLAndDone(code int, obj any){
|
||||||
|
c.Context.XML(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) YAMLAndDone(code int, obj any){
|
||||||
|
c.Context.YAML(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) TOMLAndDone(code int, obj any){
|
||||||
|
c.Context.TOML(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) ProtoBufAndDone(code int, obj any){
|
||||||
|
c.Context.ProtoBuf(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) StringAndDone(code int, format string, values ...any){
|
||||||
|
c.Context.String(code,format,values...)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) RedirectAndDone(code int, location string){
|
||||||
|
c.Context.Redirect(code,location)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) DataAndDone(code int, contentType string, data []byte){
|
||||||
|
c.Context.Data(code,contentType,data)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) DataFromReaderAndDone(code int, contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string){
|
||||||
|
c.DataFromReader(code,contentLength,contentType,reader,extraHeaders)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) HTMLAndDone(code int, name string, obj any){
|
||||||
|
c.Context.HTML(code,name,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) IndentedJSONAndDone(code int, obj any){
|
||||||
|
c.Context.IndentedJSON(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) SecureJSONAndDone(code int, obj any){
|
||||||
|
c.Context.SecureJSON(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) JSONPAndDone(code int, obj any){
|
||||||
|
c.Context.JSONP(code,obj)
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SafeContext) Done(){
|
||||||
|
c.chanWait <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type GinEvent struct {
|
||||||
|
handlersChain []SafeHandlerFunc
|
||||||
|
c SafeContext
|
||||||
|
}
|
||||||
|
|
||||||
|
type SafeHandlerFunc func(*SafeContext)
|
||||||
|
|
||||||
func (ge *GinEvent) GetEventType() event.EventType {
|
func (ge *GinEvent) GetEventType() event.EventType {
|
||||||
return Sys_Event_Gin_Event
|
return event.Sys_Event_Gin_Event
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) handleMethod(httpMethod, relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
func (gm *GinModule) handleMethod(httpMethod, relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||||
return gm.Engine.Handle(httpMethod, relativePath, func(c *gin.Context) {
|
return gm.Engine.Handle(httpMethod, relativePath, func(c *gin.Context) {
|
||||||
for _, p := range gm.processor {
|
for _, p := range gm.processor {
|
||||||
_, err := p.Process(c)
|
_, err := p.Process(c)
|
||||||
@@ -112,33 +199,71 @@ func (gm *GinModule) handleMethod(httpMethod, relativePath string, handlers ...g
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ev GinEvent
|
var ev GinEvent
|
||||||
chanWait := make(chan struct{})
|
chanWait := make(chan struct{},2)
|
||||||
ev.chanWait = chanWait
|
ev.c.chanWait = chanWait
|
||||||
ev.handlersChain = handlers
|
ev.handlersChain = handlers
|
||||||
ev.c = c
|
ev.c.Context = c
|
||||||
gm.NotifyEvent(&ev)
|
gm.NotifyEvent(&ev)
|
||||||
|
|
||||||
<-chanWait
|
ctx,cancel := context.WithTimeout(context.Background(), gm.handleTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
select{
|
||||||
|
case <-ctx.Done():
|
||||||
|
log.Error("GinModule process timeout", slog.Any("path", c.Request.URL.Path))
|
||||||
|
c.AbortWithStatus(http.StatusRequestTimeout)
|
||||||
|
case <-chanWait:
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) SafeGET(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
// GET 回调处理是在gin协程中
|
||||||
|
func (gm *GinModule) GET(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||||
|
return gm.Engine.GET(relativePath, handlers...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST 回调处理是在gin协程中
|
||||||
|
func (gm *GinModule) POST(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||||
|
return gm.Engine.POST(relativePath, handlers...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE 回调处理是在gin协程中
|
||||||
|
func (gm *GinModule) DELETE(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||||
|
return gm.Engine.DELETE(relativePath, handlers...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PATCH 回调处理是在gin协程中
|
||||||
|
func (gm *GinModule) PATCH(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||||
|
return gm.Engine.PATCH(relativePath, handlers...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put 回调处理是在gin协程中
|
||||||
|
func (gm *GinModule) Put(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
||||||
|
return gm.Engine.PUT(relativePath, handlers...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SafeGET 回调处理是在service协程中
|
||||||
|
func (gm *GinModule) SafeGET(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||||
return gm.handleMethod(http.MethodGet, relativePath, handlers...)
|
return gm.handleMethod(http.MethodGet, relativePath, handlers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) SafePOST(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
// SafePOST 回调处理是在service协程中
|
||||||
|
func (gm *GinModule) SafePOST(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||||
return gm.handleMethod(http.MethodPost, relativePath, handlers...)
|
return gm.handleMethod(http.MethodPost, relativePath, handlers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) SafeDELETE(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
// SafeDELETE 回调处理是在service协程中
|
||||||
|
func (gm *GinModule) SafeDELETE(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||||
return gm.handleMethod(http.MethodDelete, relativePath, handlers...)
|
return gm.handleMethod(http.MethodDelete, relativePath, handlers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) SafePATCH(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
// SafePATCH 回调处理是在service协程中
|
||||||
|
func (gm *GinModule) SafePATCH(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||||
return gm.handleMethod(http.MethodPatch, relativePath, handlers...)
|
return gm.handleMethod(http.MethodPatch, relativePath, handlers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GinModule) SafePut(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
|
// SafePut 回调处理是在service协程中
|
||||||
|
func (gm *GinModule) SafePut(relativePath string, handlers ...SafeHandlerFunc) gin.IRoutes {
|
||||||
return gm.handleMethod(http.MethodPut, relativePath, handlers...)
|
return gm.handleMethod(http.MethodPut, relativePath, handlers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package ginmodule
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duanhf2012/origin/log"
|
"github.com/duanhf2012/origin/v2/log"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -48,6 +47,10 @@ func (mm *MongoModule) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mm *MongoModule) Stop() error {
|
||||||
|
return mm.client.Disconnect(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
func (mm *MongoModule) TakeSession() Session {
|
func (mm *MongoModule) TakeSession() Session {
|
||||||
return Session{Client: mm.client, maxOperatorTimeOut: mm.maxOperatorTimeOut}
|
return Session{Client: mm.client, maxOperatorTimeOut: mm.maxOperatorTimeOut}
|
||||||
}
|
}
|
||||||
@@ -86,12 +89,12 @@ func (s *Session) EnsureUniqueIndex(db string, collection string, indexKeys [][]
|
|||||||
func (s *Session) ensureIndex(db string, collection string, indexKeys [][]string, bBackground bool, unique bool, sparse bool, asc bool) error {
|
func (s *Session) ensureIndex(db string, collection string, indexKeys [][]string, bBackground bool, unique bool, sparse bool, asc bool) error {
|
||||||
var indexes []mongo.IndexModel
|
var indexes []mongo.IndexModel
|
||||||
for _, keys := range indexKeys {
|
for _, keys := range indexKeys {
|
||||||
keysDoc := bsonx.Doc{}
|
keysDoc := bson.D{}
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if asc {
|
if asc {
|
||||||
keysDoc = keysDoc.Append(key, bsonx.Int32(1))
|
keysDoc = append(keysDoc, bson.E{Key:key,Value:1})
|
||||||
} else {
|
} else {
|
||||||
keysDoc = keysDoc.Append(key, bsonx.Int32(-1))
|
keysDoc = append(keysDoc, bson.E{Key:key,Value:-1})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type CustomerSubscriber struct {
|
|||||||
rpc.IRpcHandler
|
rpc.IRpcHandler
|
||||||
topic string
|
topic string
|
||||||
subscriber *Subscriber
|
subscriber *Subscriber
|
||||||
fromNodeId int
|
fromNodeId string
|
||||||
callBackRpcMethod string
|
callBackRpcMethod string
|
||||||
serviceName string
|
serviceName string
|
||||||
StartIndex uint64
|
StartIndex uint64
|
||||||
@@ -37,7 +37,7 @@ const (
|
|||||||
MethodLast SubscribeMethod = 1 //Last模式,以该消费者上次记录的位置开始订阅
|
MethodLast SubscribeMethod = 1 //Last模式,以该消费者上次记录的位置开始订阅
|
||||||
)
|
)
|
||||||
|
|
||||||
func (cs *CustomerSubscriber) trySetSubscriberBaseInfo(rpcHandler rpc.IRpcHandler, ss *Subscriber, topic string, subscribeMethod SubscribeMethod, customerId string, fromNodeId int, callBackRpcMethod string, startIndex uint64, oneBatchQuantity int32) error {
|
func (cs *CustomerSubscriber) trySetSubscriberBaseInfo(rpcHandler rpc.IRpcHandler, ss *Subscriber, topic string, subscribeMethod SubscribeMethod, customerId string, fromNodeId string, callBackRpcMethod string, startIndex uint64, oneBatchQuantity int32) error {
|
||||||
cs.subscriber = ss
|
cs.subscriber = ss
|
||||||
cs.fromNodeId = fromNodeId
|
cs.fromNodeId = fromNodeId
|
||||||
cs.callBackRpcMethod = callBackRpcMethod
|
cs.callBackRpcMethod = callBackRpcMethod
|
||||||
@@ -85,7 +85,7 @@ func (cs *CustomerSubscriber) trySetSubscriberBaseInfo(rpcHandler rpc.IRpcHandle
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 开始订阅
|
// 开始订阅
|
||||||
func (cs *CustomerSubscriber) Subscribe(rpcHandler rpc.IRpcHandler, ss *Subscriber, topic string, subscribeMethod SubscribeMethod, customerId string, fromNodeId int, callBackRpcMethod string, startIndex uint64, oneBatchQuantity int32) error {
|
func (cs *CustomerSubscriber) Subscribe(rpcHandler rpc.IRpcHandler, ss *Subscriber, topic string, subscribeMethod SubscribeMethod, customerId string, fromNodeId string, callBackRpcMethod string, startIndex uint64, oneBatchQuantity int32) error {
|
||||||
err := cs.trySetSubscriberBaseInfo(rpcHandler, ss, topic, subscribeMethod, customerId, fromNodeId, callBackRpcMethod, startIndex, oneBatchQuantity)
|
err := cs.trySetSubscriberBaseInfo(rpcHandler, ss, topic, subscribeMethod, customerId, fromNodeId, callBackRpcMethod, startIndex, oneBatchQuantity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -122,5 +122,5 @@ func (ms *MessageQueueService) RPC_Publish(inParam *rpc.DBQueuePublishReq, outPa
|
|||||||
|
|
||||||
func (ms *MessageQueueService) RPC_Subscribe(req *rpc.DBQueueSubscribeReq, res *rpc.DBQueueSubscribeRes) error {
|
func (ms *MessageQueueService) RPC_Subscribe(req *rpc.DBQueueSubscribeReq, res *rpc.DBQueueSubscribeRes) error {
|
||||||
topicRoom := ms.GetTopicRoom(req.TopicName)
|
topicRoom := ms.GetTopicRoom(req.TopicName)
|
||||||
return topicRoom.TopicSubscribe(ms.GetRpcHandler(), req.SubType, int32(req.Method), int(req.FromNodeId), req.RpcMethod, req.TopicName, req.CustomerId, req.StartIndex, req.OneBatchQuantity)
|
return topicRoom.TopicSubscribe(ms.GetRpcHandler(), req.SubType, int32(req.Method), req.FromNodeId, req.RpcMethod, req.TopicName, req.CustomerId, req.StartIndex, req.OneBatchQuantity)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func (ss *Subscriber) PersistTopicData(topic string, topics []TopicData, retryCo
|
|||||||
return ss.dataPersist.PersistTopicData(topic, topics, retryCount)
|
return ss.dataPersist.PersistTopicData(topic, topics, retryCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *Subscriber) TopicSubscribe(rpcHandler rpc.IRpcHandler, subScribeType rpc.SubscribeType, subscribeMethod SubscribeMethod, fromNodeId int, callBackRpcMethod string, topic string, customerId string, StartIndex uint64, oneBatchQuantity int32) error {
|
func (ss *Subscriber) TopicSubscribe(rpcHandler rpc.IRpcHandler, subScribeType rpc.SubscribeType, subscribeMethod SubscribeMethod, fromNodeId string, callBackRpcMethod string, topic string, customerId string, StartIndex uint64, oneBatchQuantity int32) error {
|
||||||
//取消订阅时
|
//取消订阅时
|
||||||
if subScribeType == rpc.SubscribeType_Unsubscribe {
|
if subScribeType == rpc.SubscribeType_Unsubscribe {
|
||||||
ss.UnSubscribe(customerId)
|
ss.UnSubscribe(customerId)
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ func (mp *MongoPersist) JugeTimeoutSave() bool{
|
|||||||
|
|
||||||
func (mp *MongoPersist) persistCoroutine(){
|
func (mp *MongoPersist) persistCoroutine(){
|
||||||
defer mp.waitGroup.Done()
|
defer mp.waitGroup.Done()
|
||||||
for atomic.LoadInt32(&mp.stop)==0 || mp.hasPersistData(){
|
for atomic.LoadInt32(&mp.stop)==0 {
|
||||||
//间隔时间sleep
|
//间隔时间sleep
|
||||||
time.Sleep(time.Second*1)
|
time.Sleep(time.Second*1)
|
||||||
|
|
||||||
|
|||||||
@@ -107,12 +107,16 @@ func (tcpService *TcpService) TcpEventHandler(ev event.IEvent) {
|
|||||||
case TPT_DisConnected:
|
case TPT_DisConnected:
|
||||||
tcpService.process.DisConnectedRoute(pack.ClientId)
|
tcpService.process.DisConnectedRoute(pack.ClientId)
|
||||||
case TPT_UnknownPack:
|
case TPT_UnknownPack:
|
||||||
tcpService.process.UnknownMsgRoute(pack.ClientId,pack.Data)
|
tcpService.process.UnknownMsgRoute(pack.ClientId,pack.Data,tcpService.recyclerReaderBytes)
|
||||||
case TPT_Pack:
|
case TPT_Pack:
|
||||||
tcpService.process.MsgRoute(pack.ClientId,pack.Data)
|
tcpService.process.MsgRoute(pack.ClientId,pack.Data,tcpService.recyclerReaderBytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tcpService *TcpService) recyclerReaderBytes(data []byte) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (tcpService *TcpService) SetProcessor(process processor.IProcessor,handler event.IEventHandler){
|
func (tcpService *TcpService) SetProcessor(process processor.IProcessor,handler event.IEventHandler){
|
||||||
tcpService.process = process
|
tcpService.process = process
|
||||||
tcpService.RegEventReceiverFunc(event.Sys_Event_Tcp,handler, tcpService.TcpEventHandler)
|
tcpService.RegEventReceiverFunc(event.Sys_Event_Tcp,handler, tcpService.TcpEventHandler)
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ func (ws *WSService) WSEventHandler(ev event.IEvent) {
|
|||||||
case WPT_DisConnected:
|
case WPT_DisConnected:
|
||||||
pack.MsgProcessor.DisConnectedRoute(pack.ClientId)
|
pack.MsgProcessor.DisConnectedRoute(pack.ClientId)
|
||||||
case WPT_UnknownPack:
|
case WPT_UnknownPack:
|
||||||
pack.MsgProcessor.UnknownMsgRoute(pack.ClientId,pack.Data)
|
pack.MsgProcessor.UnknownMsgRoute(pack.ClientId,pack.Data,ws.recyclerReaderBytes)
|
||||||
case WPT_Pack:
|
case WPT_Pack:
|
||||||
pack.MsgProcessor.MsgRoute(pack.ClientId,pack.Data)
|
pack.MsgProcessor.MsgRoute(pack.ClientId,pack.Data,ws.recyclerReaderBytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ func (slf *WSClient) Run() {
|
|||||||
for{
|
for{
|
||||||
bytes,err := slf.wsConn.ReadMsg()
|
bytes,err := slf.wsConn.ReadMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("read client id %d is error:%+v",slf.id,err)
|
log.Debug("read client id %s is error:%+v",slf.id,err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
data,err:=slf.wsService.process.Unmarshal(slf.id,bytes)
|
data,err:=slf.wsService.process.Unmarshal(slf.id,bytes)
|
||||||
@@ -153,7 +153,7 @@ func (ws *WSService) SendMsg(clientid string,msg interface{}) error{
|
|||||||
client,ok := ws.mapClient[clientid]
|
client,ok := ws.mapClient[clientid]
|
||||||
if ok == false{
|
if ok == false{
|
||||||
ws.mapClientLocker.Unlock()
|
ws.mapClientLocker.Unlock()
|
||||||
return fmt.Errorf("client %d is disconnect!",clientid)
|
return fmt.Errorf("client %s is disconnect!",clientid)
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.mapClientLocker.Unlock()
|
ws.mapClientLocker.Unlock()
|
||||||
@@ -180,3 +180,5 @@ func (ws *WSService) Close(clientid string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ws *WSService) recyclerReaderBytes(data []byte) {
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user