Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nil call server message handler #866

Merged
merged 1 commit into from
Jul 25, 2024

Conversation

dickens7
Copy link
Contributor

增加 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
}

@smallnest smallnest merged commit 4310c44 into smallnest:master Jul 25, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants