-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
runtime/src/main/scala/com/soundcloud/twinagle/ServerBuilder.scala
Outdated
Show resolved
Hide resolved
) { | ||
def register[ |
There was a problem hiding this comment.
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.
codegen/src/sbt-test/generator/e2e/src/test/scala/proto/test/MultiServiceSpec.scala
Outdated
Show resolved
Hide resolved
runtime/src/main/scala/com/soundcloud/twinagle/ProtoService.scala
Outdated
Show resolved
Hide resolved
runtime/src/test/scala/com/soundcloud/twinagle/ServerSpec.scala
Outdated
Show resolved
Hide resolved
748acb5
to
8d6e2e8
Compare
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.
8d6e2e8
to
20a49b3
Compare
64c62f1
to
96d1383
Compare
val httpService = ServerBuilder() | ||
.register(svc1) | ||
.register(svc2) | ||
.build |
There was a problem hiding this comment.
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).
assert(rpcs.map(_.metadata.service).toSet.size == 1, "inconsistent services in metadata") | ||
assert(rpcs.map(_.metadata.prefix).toSet.size == 1, "inconsistent prefixes in metadata") |
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice result
#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.
#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.
This change makes
ServerBuilder
more "officially" part of Twinagle's API.runtime:
ProtoService
/ProtoRpc
model to represent protobuf services and their RPC methodsProtoService
s instead of individual metadata/method pairsServerBuilder
parameters optionalcodegen:
MyService.protoService(impl)
factory to createProtoService
representation ofMyService
.MyService.server()
to useprotoService
under the hood.Fixes #123