Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow multiple proto services per Twinagle Server #132

Merged
merged 4 commits into from
Jun 22, 2020

Conversation

ccmtaylor
Copy link
Member

This change makes ServerBuilder more "officially" part of Twinagle's API.

runtime:

  • introduce ProtoService/ProtoRpc model to represent protobuf services and their RPC methods
  • modify ServerBuilder to register ProtoServices instead of individual metadata/method pairs
  • make all ServerBuilder parameters optional

codegen:

  • introduce MyService.protoService(impl) factory to create ProtoService representation of MyService.
  • modify MyService.server() to use protoService under the hood.

Fixes #123

@ccmtaylor ccmtaylor requested a review from a team June 3, 2020 09:21
) {
def register[
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ServerBuilder is public, I considered keeping this method around, or marking it deprecated for backwards compat. However, it should previously only have been used from generated code, so I went ahead and deleted it.

@ccmtaylor ccmtaylor force-pushed the multiple-services branch from 748acb5 to 8d6e2e8 Compare June 3, 2020 15:21
This change makes `ServerBuilder` more "officially" part of
Twinagle's API.

runtime:
- introduce `ProtoService`/`ProtoRpc` model to represent
  protobuf services and their RPC methods
- modify ServerBuilder to register `ProtoService`s instead
  of individual metadata/method pairs
- make all `ServerBuilder` parameters optional

codegen:
- introduce `MyService.protoService(impl)` factory to create
  `ProtoService` representation of `MyService`.
- modify `MyService.server()` to use `protoService`
  under the hood.
@ccmtaylor ccmtaylor force-pushed the multiple-services branch from 8d6e2e8 to 20a49b3 Compare June 3, 2020 15:24
@ccmtaylor ccmtaylor force-pushed the multiple-services branch from 64c62f1 to 96d1383 Compare June 12, 2020 20:19
Comment on lines +21 to +24
val httpService = ServerBuilder()
.register(svc1)
.register(svc2)
.build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "ship has probably sailed", but it wouldn't bother me if this were the only way of building a server (i.e. no convenience .server factory method).

Comment on lines +9 to +10
assert(rpcs.map(_.metadata.service).toSet.size == 1, "inconsistent services in metadata")
assert(rpcs.map(_.metadata.prefix).toSet.size == 1, "inconsistent prefixes in metadata")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(note to self: in-person follow up so I fully understand the possible circumstances here)

def build: Service[Request, Response] =
new Server(endpoints.map(instrument))

private def instrument(rpc: ProtoRpc): ProtoRpc =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to the method extraction, definitely reads better

| $ServerBuilder(extension)
|${m.methods.map(registerEndpoint).mkString("\n")}
| .build
| $ServerBuilder(extension).register(service).build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice result

@ccmtaylor ccmtaylor merged commit 1b7eb1f into master Jun 22, 2020
@ccmtaylor ccmtaylor deleted the multiple-services branch June 22, 2020 12:47
ccmtaylor added a commit that referenced this pull request Sep 29, 2020
#132 introduced a bug that caused the code generator to emit
bad code for services that expose multiple RPCs. This change
fixes the error and adds a test case to avoid future regressions.
ccmtaylor added a commit that referenced this pull request Sep 29, 2020
#132 introduced a bug that caused the code generator to emit
bad code for services that expose multiple RPCs. This change
fixes the error and adds a test case to avoid future regressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support composing multiple protobuf services
2 participants