smallnest / rpcx

Best microservices framework in Go, like alibaba Dubbo, but with more features, Scale easily. Try it. Test it. If you feel it's better, use it! 𝐉𝐚𝐯𝐚有𝐝𝐮𝐛𝐛𝐨, 𝐆𝐨𝐥𝐚𝐧𝐠有𝐫𝐩𝐜𝐱! build for cloud!
https://rpcx.io
Other
8.08k stars 1.16k forks source link

feat: add nil call server message handler #866

Closed dickens7 closed 1 month ago

dickens7 commented 1 month ago

增加 NilCallServerMessageHandler func(msg *protocol.Message) 支持自定义服务器消息的处理 目的是可以自行控制 服务器 SendMessage的消息 和 RPC reply消息顺序处理问题

如下代码:

期望先处理 abcde 再处理 reply, 当前 bidirectional 方式是一个 chan 无法保证这种顺序问题 通过 NilCallServerMessageHandler 就可以自行在业务逻辑中处理这种场景

type Bidirectional struct {
    *server.Server
}

func (t *Bidirectional) Mul(ctx context.Context, args *Args, reply *Reply) error {
    conn := ctx.Value(server.RemoteConnContextKey).(net.Conn)
    t.SendMessage(conn, "test_service_path", "test_service_method", nil, []byte("abcde"))
    reply.C = args.A * args.B
    return nil
}