kitex icon indicating copy to clipboard operation
kitex copied to clipboard

Proposal: support bound multiple service implements into one server

Open a631807682 opened this issue 3 years ago • 3 comments

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

a631807682 avatar Aug 17 '22 08:08 a631807682

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.

YangruiEmma avatar Aug 17 '22 09:08 YangruiEmma

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 ?

a631807682 avatar Aug 18 '22 04:08 a631807682

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.

YangruiEmma avatar Aug 18 '22 07:08 YangruiEmma

TODO same with #679

YangruiEmma avatar Nov 28 '22 09:11 YangruiEmma

@a631807682 The gRPC multi-service feature is now released in version v0.8.0. Please check it out.

Marina-Sakai avatar Nov 29 '23 13:11 Marina-Sakai