Skip to content

feat: support for multiple services in a single proto file #227

@abjeni

Description

@abjeni

Gorums currently supports multiple services, but you cannot have multiple services in a single proto file. The problem with multiple services is that we have no seperation between services, so if two services were to have the same rpc call, for example a multicast call named heartbeat, both would be a method belonging to the Configuration struct, it would be a name collision and would cause a compiler error.
A simple way to fix this is to create a seperate node and configuration struct for each service, where the struct names contain the service names.
Another solution is to have the rpc call names contain the service names, which avoids collisions without adding additional configurations and node structs.

Example

Example for a proto file with the services Example1 and Example2, both having a quorum call and a unicast call with the same name.

// Example1Node holds the node specific methods for the Example1 service.
type Example1Node struct {
	*gorums.RawNode
}

// Unicast is a one-way call; no replies are processed.
func (n *Example1Node) Unicast(ctx context.Context, in *Request, opts ...gorums.CallOption) {
	/*...*/
}
// A Example1Configuration represents a static set of nodes on which quorum remote
// procedure calls may be invoked.
type Example1Configuration struct {
	gorums.RawConfiguration
	qspec Example1QuorumSpec
	nodes []*Example1Node
} 

// QuorumCall is a quorum call invoked on all nodes in configuration c,
// with the same argument in, and returns a combined result.
func (c *Example1Configuration) QuorumCall(ctx context.Context, in *Request) (resp *Response, err error) {
	/*...*/
}
// Example2Node holds the node specific methods for the Example2 service.
type Example2Node struct {
	*gorums.RawNode
}

// Unicast is a one-way call; no replies are processed.
func (n *Example2Node) Unicast(ctx context.Context, in *Request, opts ...gorums.CallOption) {
	/*...*/
}
// A Example2Configuration represents a static set of nodes on which quorum remote
// procedure calls may be invoked.
type Example2Configuration struct {
	gorums.RawConfiguration
	qspec Example2QuorumSpec
	nodes []*Example2Node
}

// QuorumCall is a quorum call invoked on all nodes in configuration c,
// with the same argument in, and returns a combined result.
func (c *Example2Configuration) QuorumCall(ctx context.Context, in *Request) (resp *Response, err error) {
	/*...*/
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions