dubbo-go
dubbo-go copied to clipboard
[Proposal] Unified IDL control for multiple protocols
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:
- 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)).
- 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
- XXX.dubbo.go content is basically similar to XXX.triple.go, generating code that uses the APIs of
Client
layer andServer
layer.
Prerequisite:
- Provide tools for Dubbo side users to automatically convert Dubbo interface definitions into Protobuf IDL.
- 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.
@setcy We could talk about this proposal here or via DingDing If you have any question. Feel free to explain your thoughts.
I am interested in this proposal. Could we discuss it further in our spare time?
I am interested in this proposal. Could we discuss it further in our spare time?
Sure. Just feel free to take a discussion.
I am also interested in this. Could we have some discussion with it?