diff --git a/README.md b/README.md index 3988ab0a..6e22c37c 100644 --- a/README.md +++ b/README.md @@ -51,15 +51,14 @@ lazy val server = ## Creating a client -A `ManagedChannel` is the type used by `grpc-java` to manage a connection to a particular server. This library provides syntax for `ManagedChannelBuilder` which creates a `Resource` which can manage the shutdown of the channel, by calling `.resource[F]` where `F` has an instance of the `Sync` typeclass. This implementation will do a drain of the channel, and attempt to shut down the channel, forcefully closing after 30 seconds. An example of the syntax using `grpc-netty` is: +A `ManagedChannel` is the type used by `grpc-java` to manage a connection to a particular server. This library provides syntax for `ManagedChannelBuilder` which creates a `Resource` which can manage the shutdown of the channel, by calling `.resource[F]` where `F` has an instance of the `Sync` typeclass. This implementation will do a drain of the channel, and attempt to shut down the channel, forcefully closing after 30 seconds. An example of the syntax is: ```scala -import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder +import io.grpc._ import fs2.grpc.syntax.all._ val managedChannelResource: Resource[IO, ManagedChannel] = - NettyChannelBuilder - .forAddress("127.0.0.1", 9999) + Grpc.newChannelBuilderForAddress("127.0.0.1", 9999, InsecureChannelCredentials.create()) .resource[IO] ``` @@ -84,14 +83,14 @@ The generated code provides a method `bindServiceResource[F]`, for any `F` which A `Server` is the type used by `grpc-java` to manage the server connections and lifecycle. This library provides syntax for `ServerBuilder`, which mirrors the pattern for the client. An example is: ```scala -import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder +import io.grpc._ import fs2.grpc.syntax.all._ val helloService: Resource[IO, ServerServiceDefinition] = MyFs2Grpc.bindServiceResource[IO](new MyImpl()) -def run(service: ServerServiceDefinition) = NettyServerBuilder - .forPort(9999) +def run(service: ServerServiceDefinition) = Grpc + .newServerBuilderForPort(9999, InsecureServerCredentials.create()) .addService(service) .resource[IO] .evalMap(server => IO(server.start())) diff --git a/runtime/src/main/scala/fs2/grpc/syntax/ManagedChannelBuilderSyntax.scala b/runtime/src/main/scala/fs2/grpc/syntax/ManagedChannelBuilderSyntax.scala index 95f858b5..829e8f25 100644 --- a/runtime/src/main/scala/fs2/grpc/syntax/ManagedChannelBuilderSyntax.scala +++ b/runtime/src/main/scala/fs2/grpc/syntax/ManagedChannelBuilderSyntax.scala @@ -29,13 +29,13 @@ import cats.effect._ import io.grpc.{ManagedChannel, ManagedChannelBuilder} trait ManagedChannelBuilderSyntax { - implicit final def fs2GrpcSyntaxManagedChannelBuilder[MCB <: ManagedChannelBuilder[MCB]]( - builder: MCB - ): ManagedChannelBuilderOps[MCB] = - new ManagedChannelBuilderOps[MCB](builder) + implicit final def fs2GrpcSyntaxManagedChannelBuilder( + builder: ManagedChannelBuilder[?] + ): ManagedChannelBuilderOps = + new ManagedChannelBuilderOps(builder) } -final class ManagedChannelBuilderOps[MCB <: ManagedChannelBuilder[MCB]](val builder: MCB) extends AnyVal { +final class ManagedChannelBuilderOps(val builder: ManagedChannelBuilder[?]) extends AnyVal { /** Builds a `ManagedChannel` into a resource. The managed channel is shut down when the resource is released. * Shutdown is as follows: diff --git a/runtime/src/main/scala/fs2/grpc/syntax/ServerBuilderSyntax.scala b/runtime/src/main/scala/fs2/grpc/syntax/ServerBuilderSyntax.scala index 208fdc6c..599e1160 100644 --- a/runtime/src/main/scala/fs2/grpc/syntax/ServerBuilderSyntax.scala +++ b/runtime/src/main/scala/fs2/grpc/syntax/ServerBuilderSyntax.scala @@ -29,11 +29,11 @@ import cats.effect._ import io.grpc.{Server, ServerBuilder} trait ServerBuilderSyntax { - implicit final def fs2GrpcSyntaxServerBuilder[SB <: ServerBuilder[SB]](builder: SB): ServerBuilderOps[SB] = - new ServerBuilderOps[SB](builder) + implicit final def fs2GrpcSyntaxServerBuilder(builder: ServerBuilder[?]): ServerBuilderOps = + new ServerBuilderOps(builder) } -final class ServerBuilderOps[SB <: ServerBuilder[SB]](val builder: SB) extends AnyVal { +final class ServerBuilderOps(val builder: ServerBuilder[?]) extends AnyVal { /** Builds a `Server` into a resource. The server is shut down when the resource is released. Shutdown is as follows: * diff --git a/runtime/src/test/scala/fs2/grpc/client/ClientSuite.scala b/runtime/src/test/scala/fs2/grpc/client/ClientSuite.scala index a6a430c7..b0f315d1 100644 --- a/runtime/src/test/scala/fs2/grpc/client/ClientSuite.scala +++ b/runtime/src/test/scala/fs2/grpc/client/ClientSuite.scala @@ -374,11 +374,15 @@ class ClientSuite extends Fs2GrpcSuite { } - runTest0("resource awaits termination of managed channel") { (tc, io, _) => + runTest0("resource awaits termination of managed channel") { (tc, r, _) => import fs2.grpc.syntax.all._ - import netty.shaded.io.grpc.netty.NettyChannelBuilder + import io.grpc._ - val result = NettyChannelBuilder.forAddress("127.0.0.1", 0).resource[IO].use(IO.pure).unsafeToFuture()(io) + val result = Grpc + .newChannelBuilderForAddress("127.0.0.1", 0, InsecureChannelCredentials.create()) + .resource[IO] + .use(IO.pure) + .unsafeToFuture()(r) tc.tick() diff --git a/runtime/src/test/scala/fs2/grpc/server/ServerSuite.scala b/runtime/src/test/scala/fs2/grpc/server/ServerSuite.scala index 7d4e0339..a8d1a1f4 100644 --- a/runtime/src/test/scala/fs2/grpc/server/ServerSuite.scala +++ b/runtime/src/test/scala/fs2/grpc/server/ServerSuite.scala @@ -133,9 +133,13 @@ class ServerSuite extends Fs2GrpcSuite { runTest0("resource awaits termination of server") { (tc, r, _) => import fs2.grpc.syntax.all._ - import netty.shaded.io.grpc.netty.NettyServerBuilder + import io.grpc._ - val result = NettyServerBuilder.forPort(0).resource[IO].use(IO.pure).unsafeToFuture()(r) + val result = Grpc + .newServerBuilderForPort(0, InsecureServerCredentials.create()) + .resource[IO] + .use(IO.pure) + .unsafeToFuture()(r) tc.tick() val server = result.value.get.get