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

[Proposal] Unified IDL control for multiple protocols #2595

Open
DMwangnima opened this issue Feb 4, 2024 · 4 comments
Open

[Proposal] Unified IDL control for multiple protocols #2595

DMwangnima opened this issue Feb 4, 2024 · 4 comments

Comments

@DMwangnima
Copy link
Contributor

DMwangnima commented Feb 4, 2024

Unified IDL control for multiple protocols

Client and Server layer APIs can support both IDL and Non-IDL modes.
For IDL mode(Triple + Protobuf), defining proto file and making use of protoc-gen-go-triple to generate related code are straightforward. Generated code(XXX.triple.go) would contain statements that invoking APIs provided by Client and Server layers.
For Non-IDL mode, it needs users to write invoking code by themselves and is not convenient. Take Dubbo+Hessian2 as example:

Client Side

cli, err := client.NewClient(
	client.WithClientProtocolDubbo(),
)
if err ! = nil {
	panic(err)
}
conn, err := cli.Dial("GreetProvider",
	client.WithURL("127.0.0.1:20000"), 
)
if err ! = nil {
	panic(err)
}
var resp string
if err := conn.CallUnary(context.Background(), []interface{}{"hello", "new", "dubbo"}, &resp, "Greet"); err ! = nil {
	logger.Errorf("GreetProvider.Greet err: %s", err)
}

Server Side

GreetProvider.
type GreetProvider struct {
}

func (*GreetProvider) Greet(req string, req1 string, req2 string) (string, error) {
	return req + req1 + req2, nil
}

srv, err := server.NewServer(
	server.WithServerProtocol(
		protocol.WithDubbo(), protocol.WithPort(20000))
		protocol.WithPort(20000),
	),
)
if err ! = nil {
	panic(err)
}
if err := srv.Register(&GreetProvider{}, nil, server.WithInterface("GreetProvider")); err ! = nil {
	panic(err)
}
if err := srv.Serve(); err ! = nil {
	panic(err)
}

Proposal

Even in Non-IDL mode, code is generated using protobuf IDL. In this way, whether you need schema (Protobuf) or not (Hessian2, Msgpack), it's all uniformly used: Protobuf IDL + generated code.

Details:

  1. Generate Dubbo + Hessian2 related code with the help of Protobuf IDL. Compared to XXX.pb.go, XXX.hessian2.go would have much less content (due to Hessian2 schema-free), only structure definitions and the corresponding registration function (hessian2.Register(POJO)).
  2. Non-IDL (Hessian2) may not map perfectly to Protobuf IDL, and we need to define our own dialect in a way that is compatible with the official semantics of Protobuf IDL
  3. XXX.dubbo.go content is basically similar to XXX.triple.go, generating code that uses the APIs of Client layer and Server layer.

Prerequisite:

  1. Provide tools for Dubbo side users to automatically convert Dubbo interface definitions into Protobuf IDL.
  2. Protobuf IDL can support extensions (add Hessian2-specific tag extensions, generate Hessian2-specific content)

Results:

Not only Dubbo + Hessian2, but also Triple + Hessian2, Triple + Json and other Non-IDLs can use the interface in a unified way.

@DMwangnima
Copy link
Contributor Author

@setcy We could talk about this proposal here or via DingDing If you have any question. Feel free to explain your thoughts.

@Phixsura
Copy link

I am interested in this proposal. Could we discuss it further in our spare time?

@DMwangnima
Copy link
Contributor Author

I am interested in this proposal. Could we discuss it further in our spare time?

Sure. Just feel free to take a discussion.

@chickenlj chickenlj added this to the v3.2.0-rc2 milestone Mar 6, 2024
@Yuukirn
Copy link

Yuukirn commented Mar 10, 2024

I am also interested in this. Could we have some discussion with it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants