Proposal: support bound multiple service implements into one server
Is your feature request related to a problem? Please describe.
We usually don't declare all services in one IDL (proto file). Take COMMUNITY_MEMBERSHIP as an example, we usually logically distinguish between Member services and Maintainer services, they are Each implements its own logic, we only merge when starting the service.
We'll distinguish them like this:
- base.proto
message BaseResp {
...
}
- maintainer.proto
service MaintainerService {
rpc MergePullRequest (MergePullRequestRequest) returns (MergePullRequestResponse) {}
}
- member.proto
service MemberService {
rpc CloseIssues (CloseIssuesRequest) returns (CloseIssuesResponse) {}
}
When I use grpc-go I can make multiple impls bound into one service.
s := grpc.NewServer(...)
maintainer.RegisterMaintainerServer(s, &MaintainerServiceImpl{})
member.RegisterMemberServer(s, &MemberServiceImpl{})
s.Serve(...)
grpc-go/serviceInfo kitex/serviceInfo
Describe the solution you'd like Support bound multiple service implements into one server
Kitex doesn't support multi-service now. But for thrift, you can define multi-service in IDL and use combine service . For gRPC, it is our TODO to support it.
I have two questions about Combine Service
Question 1
There could be decades method defined in service, but only one or two methods is needed by client. Combine Service provides a way to split one service into several services. For Example, there is a ExampleService
I'm not sure if I'm right, the Combine Service appears to be designed to simplify client-side logic, but it does not have the ability to split services and combine multi IDL files, we can split services ourself, but seems combine multi IDL files should be supported.
// CombineServiceImpl implements the last service interface defined in the IDL.
type CombineServiceImpl struct{}
func (s *CombineServiceImpl) MergePullRequest(ctx context.Context, req *api.MergePullRequestRequest) (resp *api.MergePullRequestResponse, err error) {
return maintainerSrv.MergePullRequest(...)
}
func (s *CombineServiceImpl) CloseIssues(ctx context.Context, req *api.CloseIssuesRequest) (resp *api. CloseIssuesResponse, err error) {
return memberSrv.CloseIssues(...)
}
Question 2
exampleservice0, exampleservice1 and exampleservice2 are normally generated codes.
We may only need a few sub service of CombineService, can we reuse the same connection if we only want to use exampleservice0 and exampleservice1 ?
Question 1 I am sure about your question, this is to combine multi services in one service which name is CombineService. When your generated code file is too big to read, it is useful. And as you said, it also can simplify client-side code.
Question 2 How to use the connection depends on your client. If you want to use 2 services, you can use CombineService to build a client.
TODO same with #679
@a631807682 The gRPC multi-service feature is now released in version v0.8.0. Please check it out.