修改
This commit is contained in:
parent
495530a575
commit
b07cff2f5d
@ -1,5 +1,7 @@
|
||||
package ipb
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
func MakeMsg(serviceName string, connId uint32, userId int64, msgId int32, msg []byte) *InternalMsg {
|
||||
return &InternalMsg{
|
||||
ServiceName: serviceName,
|
||||
@ -10,14 +12,15 @@ func MakeMsg(serviceName string, connId uint32, userId int64, msgId int32, msg [
|
||||
}
|
||||
}
|
||||
|
||||
//func MakeRpcMsg(serviceName string, connId uint32, userId int64, msgId int32, msg []byte) *InternalMsg {
|
||||
// return &InternalMsg{
|
||||
// ServiceName: serviceName,
|
||||
// ConnId: connId,
|
||||
// UserId: userId,
|
||||
// MsgId: msgId,
|
||||
// Msg: msg,
|
||||
// Type: MsgType_RpcMsg,
|
||||
// RetRpcMsgId: genRpcId(),
|
||||
// }
|
||||
//}
|
||||
func MakeRpcMsg[T any](rpcMsgId string, userId int64, msg *T) *InternalMsg {
|
||||
data, _ := json.Marshal(msg)
|
||||
return &InternalMsg{
|
||||
ServiceName: "",
|
||||
ConnId: 0,
|
||||
UserId: userId,
|
||||
MsgId: 0,
|
||||
Msg: data,
|
||||
Type: MsgType_RpcMsg,
|
||||
RpcMsgId: rpcMsgId,
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,6 @@ func TestWipeWarn(t *testing.T) {
|
||||
|
||||
password := fmt.Sprintf("%x", md5.Sum([]byte(username)))
|
||||
t.Log(password)
|
||||
s := "hello world"
|
||||
t.Log(MakeRpcMsg[string]("test.rpc", 0, &s))
|
||||
}
|
||||
|
@ -144,6 +144,9 @@ func (s *NatsService) Send(topic string, msg *ipb.InternalMsg) error {
|
||||
return s.nats.Publish(topic, data)
|
||||
}
|
||||
|
||||
// call会阻塞主协程,需要起新协程去等待返回值,业务逻辑则转回主协程处理。
|
||||
// 不要将处理返回值的业务逻辑放到新协程,避免业务逻辑中有数据并发问题
|
||||
// 比如并发call拉用户数据,然后操作本地的user map
|
||||
func (s *NatsService) Call(rpcTopic string, timeout time.Duration, msg *ipb.InternalMsg) (*ipb.InternalMsg, error) {
|
||||
data, _ := proto.Marshal(msg)
|
||||
response, err := s.nats.Rpc(rpcTopic, timeout, data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user