parent
0ed393b1a5
commit
fb396d9cf0
@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/rpc/user"
|
||||
"flag"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10100, "rpc listening port")
|
||||
flag.Parse()
|
||||
rpcServer := user.NewUserServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
//"Open_IM/pkg/common/constant"
|
||||
//"Open_IM/pkg/common/db"
|
||||
//imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
//cp "Open_IM/pkg/common/utils"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbStatistics "Open_IM/pkg/proto/statistics"
|
||||
//open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
//"context"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type statisticsServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewStatisticsGroupServer(port int) *statisticsServer {
|
||||
log.NewPrivateLog("group")
|
||||
return &statisticsServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *statisticsServer) Run() {
|
||||
log.NewInfo("0", "group rpc start ")
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbStatistics.RegisterUserServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "group rpc success")
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,95 @@
|
||||
syntax = "proto3";
|
||||
import "Open_IM/pkg/proto/sdk_ws/ws.proto";
|
||||
option go_package = "./statistics;statistics";
|
||||
package statistics;
|
||||
|
||||
message StatisticsReq {
|
||||
string from = 1;
|
||||
string to = 2;
|
||||
}
|
||||
|
||||
message GetActiveUserReq{
|
||||
server_api_params.ResponsePagination Pagination = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message UserResp{
|
||||
string NickName = 1;
|
||||
string UserId = 2;
|
||||
string MessageNum = 3;
|
||||
}
|
||||
|
||||
message GetActiveUserResp {
|
||||
repeated UserResp Users = 1;
|
||||
server_api_params.ResponsePagination Pagination = 2;
|
||||
}
|
||||
|
||||
message GetActiveGroupReq{
|
||||
server_api_params.ResponsePagination Pagination = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message GroupResp {
|
||||
string GroupName = 1;
|
||||
string GroupId = 2;
|
||||
string MessageNum = 3;
|
||||
}
|
||||
|
||||
message GetActiveGroupResp {
|
||||
repeated GroupResp Groups = 1;
|
||||
server_api_params.ResponsePagination Pagination = 2;
|
||||
}
|
||||
|
||||
message DateNumList {
|
||||
string Date = 1;
|
||||
int32 Num = 2;
|
||||
}
|
||||
|
||||
|
||||
message GetMessageStatisticsReq {
|
||||
StatisticsReq StatisticsReq = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
|
||||
message GetMessageStatisticsResp {
|
||||
int32 PrivateMessageNum = 1;
|
||||
int32 GroupMessageNum = 2;
|
||||
repeated DateNumList PrivateMessageNumList = 3;
|
||||
repeated DateNumList GroupMessageNumList = 4;
|
||||
}
|
||||
|
||||
message GetGroupStatisticsReq {
|
||||
StatisticsReq StatisticsReq = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
|
||||
message GetGroupStatisticsResp {
|
||||
int32 IncreaseGroupNum = 1;
|
||||
int32 TotalGroupNum = 2;
|
||||
repeated DateNumList IncreaseGroupNumList = 3;
|
||||
repeated DateNumList TotalGroupNumList = 4;
|
||||
}
|
||||
|
||||
message GetUserStatisticsReq {
|
||||
StatisticsReq StatisticsReq = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message GetUserStatisticsResp {
|
||||
int32 IncreaseUserNum = 1;
|
||||
int32 ActiveUserNum = 2;
|
||||
int32 TotalUserNum = 3;
|
||||
repeated DateNumList IncreaseUserNumList = 4;
|
||||
repeated DateNumList ActiveUserNumList = 5;
|
||||
repeated DateNumList TotalUserNumList = 6;
|
||||
}
|
||||
|
||||
service user {
|
||||
rpc GetActiveUser(GetActiveUserReq) returns(GetActiveUserResp);
|
||||
rpc GetActiveGroup(GetActiveGroupReq) returns(GetActiveGroupResp);
|
||||
rpc GetMessageStatistics(GetMessageStatisticsReq) returns(GetMessageStatisticsResp);
|
||||
rpc GetGroupStatistics(GetGroupStatisticsReq) returns(GetGroupStatisticsResp);
|
||||
rpc GetUserStatistics(GetUserStatisticsReq) returns(GetUserStatisticsResp);
|
||||
}
|
Loading…
Reference in new issue