dubbo-go icon indicating copy to clipboard operation
dubbo-go copied to clipboard

[Proposal] Unified IDL control for multiple protocols

Open DMwangnima opened this issue 1 year ago • 4 comments

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 avatar Feb 04 '24 06:02 DMwangnima

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

DMwangnima avatar Feb 10 '24 08:02 DMwangnima

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

Phixsura avatar Feb 29 '24 18:02 Phixsura

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

Sure. Just feel free to take a discussion.

DMwangnima avatar Mar 01 '24 12:03 DMwangnima

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

Yuukirn avatar Mar 10 '24 15:03 Yuukirn