diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index c466aa04..87aeaa4b 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: release-drafter/release-drafter@v5 with: - name: "Play/Lagom gRPC $RESOLVED_VERSION" + name: "Play gRPC $RESOLVED_VERSION" config-name: release-drafts/increasing-minor-version.yml # located in .github/ in the default branch within this or the .github repo commitish: ${{ github.ref_name }} env: diff --git a/README.md b/README.md index 354e7c48..dfa1c28d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ [![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org) [![Mergify Status](https://img.shields.io/endpoint.svg?url=https://api.mergify.com/v1/badges/playframework/play-grpc&style=flat)](https://mergify.com) -Play and Lagom support for [akka-grpc](https://doc.akka.io/docs/akka-grpc/current/). +Play support for [akka-grpc](https://doc.akka.io/docs/akka-grpc/current/). ## Project Status diff --git a/build.sbt b/build.sbt index a4840316..4781227a 100644 --- a/build.sbt +++ b/build.sbt @@ -40,10 +40,6 @@ aggregateProjects( playTestkit, playSpecs2, playScalaTest, - lagomScaladslGrpcTestKit, - lagomJavadslGrpcTestKit, - lagomInteropTestJava, - lagomInteropTestScala, docs, ) @@ -213,83 +209,6 @@ val playInteropTestJava = Project("play-grpc-interop-test-java", file("play-inte .enablePlugins(build.play.grpc.NoPublish) .pluginTestingSettings -val lagomJavadslGrpcTestKit = Project("lagom-javadsl-grpc-testkit", file("lagom-javadsl-grpc-testkit")) - .settings( - libraryDependencies += Dependencies.Compile.lagomJavadslTestKit, - libraryDependencies += Dependencies.Compile.akkaDiscovery, - ) - .pluginTestingSettings - -val lagomScaladslGrpcTestKit = Project("lagom-scaladsl-grpc-testkit", file("lagom-scaladsl-grpc-testkit")) - .settings( - libraryDependencies += Dependencies.Compile.lagomScaladslTestKit, - libraryDependencies += Dependencies.Compile.akkaDiscovery, - ) - .pluginTestingSettings - -val lagomInteropTestScala = Project("lagom-grpc-interop-test-scala", file("lagom-interop-test-scala")) - .dependsOn(playRuntime, lagomScaladslGrpcTestKit % Test) - .settings( - ReflectiveCodeGen.generatedLanguages := Seq(AkkaGrpc.Scala), - ReflectiveCodeGen.extraGenerators ++= List( - "akka.grpc.gen.scaladsl.ScalaMarshallersCodeGenerator", - "play.grpc.gen.scaladsl.PlayScalaClientCodeGenerator", - "play.grpc.gen.scaladsl.PlayScalaServerCodeGenerator", - ), - libraryDependencies ++= Seq( - // TODO https://github.com/akka/akka-grpc/issues/193 - Dependencies.Compile.grpcStub, - Dependencies.Compile.lagomScaladslTestKit, - Dependencies.Compile.playAkkaHttpServer, - Dependencies.Compile.playAkkaHttp2Support, - Dependencies.Compile.macwire, - // Used to force the akka version - Dependencies.Compile.akkaClusterShardingTyped, - Dependencies.Compile.akkaPersistenceQuery, - Dependencies.Compile.akkaPersistenceTyped, - Dependencies.Compile.akkaStream, - Dependencies.Compile.akkaSerializationJackson, - Dependencies.Test.akkaActorTestkitTyped, - Dependencies.Test.akkaStreamTestkit, - Dependencies.Test.junit, - Dependencies.Test.scalaTest, - Dependencies.Test.logback, - ), - ) - .pluginTestingSettings - .enablePlugins(build.play.grpc.NoPublish) - -val lagomInteropTestJava = Project("lagom-grpc-interop-test-java", file("lagom-interop-test-java")) - .dependsOn(playRuntime, lagomJavadslGrpcTestKit % Test) - .settings( - ReflectiveCodeGen.generatedLanguages := Seq(AkkaGrpc.Java), - ReflectiveCodeGen.extraGenerators ++= List( - "play.grpc.gen.javadsl.PlayJavaClientCodeGenerator", - "play.grpc.gen.javadsl.PlayJavaServerCodeGenerator", - ), - libraryDependencies ++= Seq( - // TODO https://github.com/akka/akka-grpc/issues/193 - Dependencies.Compile.grpcStub, - Dependencies.Compile.lagomJavadslTestKit, - Dependencies.Compile.playAkkaHttpServer, - Dependencies.Compile.playAkkaHttp2Support, - // Used to force the akka version - Dependencies.Compile.akkaClusterShardingTyped, - Dependencies.Compile.akkaPersistenceQuery, - Dependencies.Compile.akkaPersistenceTyped, - Dependencies.Compile.akkaStream, - Dependencies.Compile.akkaSerializationJackson, - Dependencies.Test.akkaActorTestkitTyped, - Dependencies.Test.akkaStreamTestkit, - Dependencies.Test.junit, - Dependencies.Test.junitInterface, - Dependencies.Test.scalaTest, - Dependencies.Test.logback, - ), - ) - .pluginTestingSettings - .enablePlugins(build.play.grpc.NoPublish) - val docs = Project("play-grpc-docs", file("docs")) .enablePlugins(AkkaParadoxPlugin) .settings( diff --git a/docs/src/main/paradox/index.md b/docs/src/main/paradox/index.md index 88961786..e900c3ad 100644 --- a/docs/src/main/paradox/index.md +++ b/docs/src/main/paradox/index.md @@ -2,13 +2,12 @@ [Akka gRPC](https://doc.akka.io/docs/akka-grpc/current/) provides support for building streaming gRPC servers and clients on top of Akka Streams. Play gRPC provides examples and tools on embedding Akka gRPC endpoints on -Play applications and Lagom Services. +Play applications. @@toc @@@ index * [Akka-gRPC in Play](play/index.md) - * [Akka-gRPC in Lagom](lagom/index.md) @@@ diff --git a/docs/src/main/paradox/lagom/consuming-grpc.md b/docs/src/main/paradox/lagom/consuming-grpc.md deleted file mode 100644 index 14ac9d59..00000000 --- a/docs/src/main/paradox/lagom/consuming-grpc.md +++ /dev/null @@ -1,72 +0,0 @@ -## Using a gRPC client in Lagom - -Akka gRPC has special support to allow for seamless configuration of generated clients in Play. To enable this, you -need first to enable the gRPC plugin as described in the [client docs](https://doc.akka.io/docs/akka-grpc/current/client/walkthrough.html) and then add a -source generator in `build.sbt`: - -Scala -: ``` -akkaGrpcExtraGenerators += play.grpc.gen.scaladsl.PlayScalaClientCodeGenerator -``` - -Java -: ``` -akkaGrpcExtraGenerators += play.grpc.gen.javadsl.PlayJavaClientCodeGenerator -``` - -This will generate a Play module that provides all generated clients for injection. The module must be enabled -by adding it to the enabled modules in the `application.conf`. - -You can then put the following `helloworld.proto` file in `app/protobuf`: - -Scala -: @@snip[helloworld.proto](/lagom-interop-test-scala/src/main/proto/helloworld.proto) { #protoSources } - -Java -: @@snip[helloworld.proto](/lagom-interop-test-java/src/main/proto/helloworld.proto) { #protoSources } - - -@@@ div { .group-scala } - -For Scala, you first need to provide a `GrpcClientSettings` object in your cake: - -Scala -: @@snip[HelloLoader.scala](/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloLoader.scala) { #service-client-conf } - - -And then instantiate the client using the settings above: - -Scala -: @@snip[HelloLoader.scala](/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloLoader.scala) { #service-client-creation } - - -@@@ - - -@@@ div { .group-java } - -For Java, the module file is generated in @java[`com.lightbend.lagom.javadsl.grpc.interop.AkkaGrpcClientModule` by default], which corresponds to the default value -of `flat_package` for @java[Java]@scala[Scala]. You can read more about this in [Services](https://doc.akka.io/docs/akka-grpc/current/proto.html). - -The exact package of the module will be based on the package the proto files are generated in, configured through -the `java_package` option in the proto-file (if there are multiple different gRPC generated clients the module will -be generated in the longest package prefix shared between the clients). - -To hook it into Play, in `application.conf`: - -Java -: @@snip[application.conf](/lagom-interop-test-java/src/main/resources/application.conf) { #client-module-java } - -The clients are configured with entries under `akka.grpc.client` named after the client (`gRPC` package name dot `ServiceName`), -again, in `application.conf`: - -Java -: @@snip[application.conf](/lagom-interop-test-java/src/main/resources/application.conf) { #service-client-conf } - -See [Client Configuration](https://doc.akka.io/docs/akka-grpc/current/client/configuration.html) for more information on the available options. If the configuration -is not present for that client and it is used by some other component, the application start will fail with an exception -when injecting the client (see [#271](https://github.com/akka/akka-grpc/issues/271)). - -At this point the client is then available to be injected as any other regular object. - -@@@ diff --git a/docs/src/main/paradox/lagom/index.md b/docs/src/main/paradox/lagom/index.md deleted file mode 100644 index fe86412c..00000000 --- a/docs/src/main/paradox/lagom/index.md +++ /dev/null @@ -1,12 +0,0 @@ -# Lagom gRPC - - -@@@ index - - * [Overview](overview.md) - * [Serving gRPC from Lagom](serving-grpc.md) - * [Using a gRPC client in Lagom](consuming-grpc.md) - * [Using a gRPC client in Lagom tests](lagom-grpc-testkit.md) - * [Lagom gRPC sample applications](sample-applications.md) - -@@@ diff --git a/docs/src/main/paradox/lagom/lagom-grpc-testkit.md b/docs/src/main/paradox/lagom/lagom-grpc-testkit.md deleted file mode 100644 index 77750c90..00000000 --- a/docs/src/main/paradox/lagom/lagom-grpc-testkit.md +++ /dev/null @@ -1,41 +0,0 @@ -## Using a gRPC client in Lagom tests - -When your Lagom Service exposes a gRPC interface you will need a gRPC Client on your -tests. `play-grpc` provides extensions to @java[[Lagom's `testkit`](https://www.lagomframework.com/documentation/current/java/Test.html#How-to-test-one-service)]@scala[[Lagom's `testkit`](https://www.lagomframework.com/documentation/current/scala/TestingServices.html#How-to-test-one-service)]. - -First you have to include the dependency to the testkit extension: - -Scala -: @@@vars - ```scala - libraryDependencies += "com.typesafe.play" %% "lagom-scaladsl-grpc-testkit" % "$project.version$" % Test - ``` - @@@ - -Java -: @@@vars - ```scala - libraryDependencies += "com.typesafe.play" %% "lagom-javadsl-grpc-testkit" % "$project.version$" % Test - ``` - @@@ - -### Unmanaged client - -You can use an unmanaged client with an idiom similar to Lagom's @java[[`server.client`](https://www.lagomframework.com/documentation/current/java/Test.html#How-to-test-one-service)]@scala[[`server.client`](https://www.lagomframework.com/documentation/current/scala/TestingServices.html#How-to-test-one-service)]. The main difference is that the gRPC unmanaged client requires manual -resource cleanup so you are responsible for invoking `close` once you are done using the client instance. This option is convenient if you want to reuse the client in multiple tests or even within the same test. - -Scala -: @@snip [HelloServiceSpec.scala](/lagom-interop-test-scala/src/test/scala/com/example/hello/impl/HelloServiceSpec.scala) { #unmanaged-client } - -Java -: @@snip [HelloServiceTest.java](/lagom-interop-test-java/src/test/java/com/lightbend/lagom/javadsl/grpc/interop/test/HelloServiceTest.java) { #unmanaged-client } - -### Managed client - -The Lagom gRPC managed client is a similar API but will handle the resource management for you. This option is convenient if you want a fresh new isntance of the client on each use, but is also more costly: - -Scala -: @@snip [HelloServiceSpec.scala](/lagom-interop-test-scala/src/test/scala/com/example/hello/impl/HelloServiceSpec.scala) { #managed-client } - -Java -: @@snip [HelloServiceTest.java](/lagom-interop-test-java/src/test/java/com/lightbend/lagom/javadsl/grpc/interop/test/HelloServiceTest.java) { #managed-client } diff --git a/docs/src/main/paradox/lagom/overview.md b/docs/src/main/paradox/lagom/overview.md deleted file mode 100644 index 266e7f52..00000000 --- a/docs/src/main/paradox/lagom/overview.md +++ /dev/null @@ -1,61 +0,0 @@ -# Lagom gRPC support overview - -## gRPC - -[gRPC](https://grpc.io/) is a transport mechanism for request/response and (non-persistent) streaming use cases. See [Akka gRPC documentation for an explanation of why gRPC](https://doc.akka.io/docs/akka-grpc/current/whygrpc.html) and when to use it as your transport. - -## How to add the sbt plugin - -To get started, for both client and server code generation, you will need to add Akka gRPC sbt plugin: - -sbt -: @@@vars - ```scala - // in project/plugins.sbt: - addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "$akka.grpc.version$") - libraryDependencies += "com.typesafe.play" %% "play-grpc-generators" % "$project.version$" - ``` - @@@ - - -And then in your `build.sbt` file, you will need to enable the plugin for the project that contains the `.proto` files, and configure the language used in project: - -Scala -: @@@vars - ```scala - // in build.sbt: - lazy val `greeter-service-impl` = (project in file("greeter-impl")) - .enablePlugins(LagomScala) - .enablePlugins(AkkaGrpcPlugin) - // enables serving HTTP/2 - .enablePlugins(PlayAkkaHttp2Support) - .settings( - libraryDependencies += "com.typesafe.play" %% "play-grpc-runtime" % "$project.version$", - // Using Scala - akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Scala), - akkaGrpcGeneratedSources := Seq(AkkaGrpc.Server, AkkaGrpc.Client), - akkaGrpcExtraGenerators in Compile += play.grpc.gen.scaladsl.PlayScalaServerCodeGenerator - ) - ``` - @@@ - -Java -: @@@vars - ```scala - // in build.sbt: - lazy val `greeter-service-impl` = (project in file("greeter-impl")) - .enablePlugins(LagomJava) - .enablePlugins(AkkaGrpcPlugin) - // enables serving HTTP/2 - .enablePlugins(PlayAkkaHttp2Support) - .settings( - libraryDependencies += "com.typesafe.play" %% "play-grpc-runtime" % "$project.version$", - // Using Java - akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Java), - akkaGrpcGeneratedSources := Seq(AkkaGrpc.Server, AkkaGrpc.Client), - akkaGrpcExtraGenerators in Compile += play.grpc.gen.javadsl.PlayJavaServerCodeGenerator - ) - ``` - @@@ - -After that, you should be able to generate and use the code to @ref[serve](serving-grpc.md) or @ref[consume](consuming-grpc.md) gRPC services. diff --git a/docs/src/main/paradox/lagom/sample-applications.md b/docs/src/main/paradox/lagom/sample-applications.md deleted file mode 100644 index ca6cb08f..00000000 --- a/docs/src/main/paradox/lagom/sample-applications.md +++ /dev/null @@ -1,15 +0,0 @@ -# Lagom gRPC sample applications - -There are also samples demonstrating the use of gRPC in Lagom in both Java and Scala. - -## Java - -- Guide: -- Download: -- Github: - -## Scala - -- Guide: -- Download: -- Github: diff --git a/docs/src/main/paradox/lagom/serving-grpc.md b/docs/src/main/paradox/lagom/serving-grpc.md deleted file mode 100644 index dd8e92f3..00000000 --- a/docs/src/main/paradox/lagom/serving-grpc.md +++ /dev/null @@ -1,64 +0,0 @@ -## Serving gRPC from Lagom - -To be able to serve gRPC from a Lagom application you must enable [Play HTTP/2 Support](https://www.playframework.com/documentation/2.8.x/AkkaHttpServer#HTTP%2F2-support-%28experimental%29) -with [HTTPS](https://www.playframework.com/documentation/2.8.x/ConfiguringHttps) and the ALPN agent. - -After @ref[adding Akka gRPC sbt plugin](overview.md) you need to enable the Play server side code generator in `build.sbt`: - -Scala -: ```scala -akkaGrpcExtraGenerators += play.grpc.gen.scaladsl.PlayScalaServerCodeGenerator -``` - -Java -: ```scala -akkaGrpcExtraGenerators += play.grpc.gen.javadsl.PlayJavaServerCodeGenerator -``` - -The plugin will look for `.proto` service descriptors in `src/main/protobuf` and output an abstract class per service -that you then implement, so for example for the following protobuf descriptor: - -Scala -: @@snip[helloworld.proto](/lagom-interop-test-scala/src/main/proto/helloworld.proto) { #protoSources } - -Java -: @@snip[helloworld.proto](/lagom-interop-test-java/src/main/proto/helloworld.proto) { #protoSources } - -You will get an abstract class named @scala[`com.lightbend.lagom.scaladsl.grpc.interop.AbstractGreeterServiceRouter`] -@java[`com.lightbend.lagom.javadsl.grpc.interop.AbstractGreeterServiceRouter`]. Create a concrete subclass implementing this -wherever you see fit in your project, let's say @scala[`com.lightbend.lagom.scaladsl.grpc.interop.test.HelloGrpcServiceImpl`]@java[`com.lightbend.lagom.javadsl.grpc.interop.test.api.HelloGrpcServiceImpl`] like so: - -Scala -: @@snip[HelloGrpcServiceImpl.scala](/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloGrpcServiceImpl.scala) { #service-impl } - -Java -: @@snip[HelloGrpcServiceImpl.java](/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/api/HelloGrpcServiceImpl.java) { #service-impl } - - -And then, you need to bind the new additional router in your project. - -@@@ div { .group-scala } - -In Scala, you use `additionalRouter` method when creating your `lagomServer` instance: - -Scala -: @@snip[HelloLoader.scala](/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloLoader.scala) { #service-additional-router } - -@@@ - -@@@ div { .group-java } - -In Java, you need to bind the service with the additional router: - -Java -: @@snip[HelloModule.java](/lagom-interop-test-java/src/main/java/HelloModule.java) { #service-additional-router } - -And finally enable this module in your `application.conf` file: - -Java -: @@snip[application.conf](/lagom-interop-test-java/src/main/resources/application.conf) { #service-module } - - -@@@ - -A gRPC client can now connect to the server and call the provided services. diff --git a/lagom-interop-test-java/src/main/java/HelloModule.java b/lagom-interop-test-java/src/main/java/HelloModule.java deleted file mode 100644 index e43d93f0..00000000 --- a/lagom-interop-test-java/src/main/java/HelloModule.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -// #service-additional-router -import com.google.inject.AbstractModule; -import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport; -import com.lightbend.lagom.javadsl.grpc.interop.test.api.HelloGrpcServiceImpl; -import com.lightbend.lagom.javadsl.grpc.interop.test.HelloServiceImpl; -import com.lightbend.lagom.javadsl.grpc.interop.test.api.api.HelloService; - -public class HelloModule extends AbstractModule implements ServiceGuiceSupport { - @Override - protected void configure() { - bindService( - // bind the lagom service - HelloService.class, - HelloServiceImpl.class, - // include additional routers (in this case a gRPC router) - additionalRouter(HelloGrpcServiceImpl.class)); - } -} -// #service-additional-router diff --git a/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/HelloServiceImpl.java b/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/HelloServiceImpl.java deleted file mode 100644 index 94261228..00000000 --- a/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/HelloServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package com.lightbend.lagom.javadsl.grpc.interop.test; - -import akka.NotUsed; -import com.lightbend.lagom.javadsl.api.ServiceCall; -import com.lightbend.lagom.javadsl.grpc.interop.test.api.api.HelloService; - -import javax.inject.Inject; -import java.util.concurrent.CompletableFuture; - -public class HelloServiceImpl implements HelloService { - - @Inject - public HelloServiceImpl() {} - - @Override - public ServiceCall hello(String id) { - return req -> CompletableFuture.completedFuture("Hi " + id + "!"); - } -} diff --git a/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/api/HelloGrpcServiceImpl.java b/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/api/HelloGrpcServiceImpl.java deleted file mode 100644 index 47e7ab5a..00000000 --- a/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/api/HelloGrpcServiceImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -// #service-impl -package com.lightbend.lagom.javadsl.grpc.interop.test.api; - -import akka.actor.ActorSystem; -import com.lightbend.lagom.javadsl.grpc.interop.AbstractGreeterServiceRouter; -import com.lightbend.lagom.javadsl.grpc.interop.HelloReply; -import com.lightbend.lagom.javadsl.grpc.interop.HelloRequest; - -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; - -@Singleton -public class HelloGrpcServiceImpl extends AbstractGreeterServiceRouter { - - @Inject - public HelloGrpcServiceImpl(ActorSystem sys) { - super(sys); - } - - @Override - public CompletionStage sayHello(HelloRequest in) { - HelloReply reply = HelloReply.newBuilder().setMessage("Hi " + in.getName() + " (gRPC)").build(); - return CompletableFuture.completedFuture(reply); - } -} -// #service-impl diff --git a/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/api/api/HelloService.java b/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/api/api/HelloService.java deleted file mode 100644 index 7cf6e04c..00000000 --- a/lagom-interop-test-java/src/main/java/com/lightbend/lagom/javadsl/grpc/interop/test/api/api/HelloService.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package com.lightbend.lagom.javadsl.grpc.interop.test.api.api; - -import akka.NotUsed; -import com.lightbend.lagom.javadsl.api.Descriptor; -import com.lightbend.lagom.javadsl.api.Service; -import com.lightbend.lagom.javadsl.api.ServiceCall; - -import static com.lightbend.lagom.javadsl.api.Service.named; -import static com.lightbend.lagom.javadsl.api.Service.pathCall; - -/** - * The Hello service interface. - * - *

This describes everything that Lagom needs to know about how to serve and consume the - * HelloService. - */ -public interface HelloService extends Service { - - /** Example: curl http://localhost:9000/api/hello/Alice */ - ServiceCall hello(String id); - - default Descriptor descriptor() { - return named("hello").withCalls(pathCall("/api/hello/:id", this::hello)).withAutoAcl(true); - } -} diff --git a/lagom-interop-test-java/src/main/proto/helloworld.proto b/lagom-interop-test-java/src/main/proto/helloworld.proto deleted file mode 100644 index 8907f5ab..00000000 --- a/lagom-interop-test-java/src/main/proto/helloworld.proto +++ /dev/null @@ -1,21 +0,0 @@ -// #protoSources -syntax = "proto3"; - -option java_multiple_files = true; -option java_package = "com.lightbend.lagom.javadsl.grpc.interop"; -option java_outer_classname = "HelloWorldProto"; - -package helloworld; - -service GreeterService { - rpc SayHello (HelloRequest) returns (HelloReply) {} -} - -message HelloRequest { - string name = 1; -} - -message HelloReply { - string message = 1; -} -// #protoSources \ No newline at end of file diff --git a/lagom-interop-test-java/src/main/resources/application.conf b/lagom-interop-test-java/src/main/resources/application.conf deleted file mode 100644 index 1ac795f2..00000000 --- a/lagom-interop-test-java/src/main/resources/application.conf +++ /dev/null @@ -1,23 +0,0 @@ -// #service-module -play.modules.enabled += HelloModule -// #service-module - -// #client-module-java -// enable the client module -play.modules.enabled += com.lightbend.lagom.javadsl.grpc.interop.AkkaGrpcClientModule -// #client-module-java - -// #service-client-conf -akka.grpc.client { - "helloworld.GreeterService" { - service-discovery { - mechanism = "com.lightbend.lagom.internal.registry.DevModeSimpleServiceDiscovery" - service-name = "helloworld.GreeterService" - port-name = "https" - } - - deadline = 5s - connection-attempts = 5 - } -} -// #service-client-conf \ No newline at end of file diff --git a/lagom-interop-test-java/src/test/java/com/lightbend/lagom/javadsl/grpc/interop/test/HelloServiceTest.java b/lagom-interop-test-java/src/test/java/com/lightbend/lagom/javadsl/grpc/interop/test/HelloServiceTest.java deleted file mode 100644 index 3cd4aa27..00000000 --- a/lagom-interop-test-java/src/test/java/com/lightbend/lagom/javadsl/grpc/interop/test/HelloServiceTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package com.lightbend.lagom.javadsl.grpc.interop.test; - -import com.lightbend.lagom.javadsl.grpc.interop.GreeterServiceClient; -import com.lightbend.lagom.javadsl.grpc.interop.HelloReply; -import com.lightbend.lagom.javadsl.grpc.interop.HelloRequest; -import com.lightbend.lagom.javadsl.testkit.grpc.AkkaGrpcClientHelpers; -import com.lightbend.lagom.javadsl.grpc.interop.test.api.api.HelloService; -import org.junit.Test; - -import static com.lightbend.lagom.javadsl.testkit.ServiceTest.defaultSetup; -import static com.lightbend.lagom.javadsl.testkit.ServiceTest.withServer; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.junit.Assert.assertEquals; - -public class HelloServiceTest { - - @Test - public void shouldSayHelloUsingALagomClient() throws Exception { - withServer( - defaultSetup(), - server -> { - HelloService service = server.client(HelloService.class); - - String msg = service.hello("Alice").invoke().toCompletableFuture().get(5, SECONDS); - assertEquals("Hi Alice!", msg); - }); - } - - @Test - public void shouldSayHelloUsingGrpc() throws Exception { - withServer( - defaultSetup().withSsl(), - server -> { - // #managed-client - AkkaGrpcClientHelpers.withGrpcClient( - server, - GreeterServiceClient::create, - serviceClient -> { - HelloReply reply = - serviceClient - .sayHello(HelloRequest.newBuilder().setName("Steve").build()) - .toCompletableFuture() - .get(5, SECONDS); - assertEquals("Hi Steve (gRPC)", reply.getMessage()); - }); - // #managed-client - }); - } - - @Test - public void shouldSayHelloUsingUnmanagedGrpc() throws Exception { - withServer( - defaultSetup().withSsl(), - server -> { - // #unmanaged-client - GreeterServiceClient client = - AkkaGrpcClientHelpers.grpcClient(server, GreeterServiceClient::create); - try { - HelloReply reply = - client - .sayHello(HelloRequest.newBuilder().setName("Steve").build()) - .toCompletableFuture() - .get(5, SECONDS); - assertEquals("Hi Steve (gRPC)", reply.getMessage()); - } finally { - client.close().toCompletableFuture().get(5, SECONDS); - } - // #unmanaged-client - }); - } -} diff --git a/lagom-interop-test-java/src/test/resources/logback.xml b/lagom-interop-test-java/src/test/resources/logback.xml deleted file mode 100644 index 697e43dd..00000000 --- a/lagom-interop-test-java/src/test/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - %date{ISO8601} %-5level %logger - %msg%n - - - - - - - - - - diff --git a/lagom-interop-test-scala/src/main/proto/helloworld.proto b/lagom-interop-test-scala/src/main/proto/helloworld.proto deleted file mode 100644 index 9bf35245..00000000 --- a/lagom-interop-test-scala/src/main/proto/helloworld.proto +++ /dev/null @@ -1,21 +0,0 @@ -// #protoSources -syntax = "proto3"; - -option java_multiple_files = true; -option java_package = "com.lightbend.lagom.scaladsl.grpc.interop"; -option java_outer_classname = "HelloWorldProto"; - -package helloworld; - -service GreeterService { - rpc SayHello (HelloRequest) returns (HelloReply) {} -} - -message HelloRequest { - string name = 1; -} - -message HelloReply { - string message = 1; -} -// #protoSources \ No newline at end of file diff --git a/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloGrpcServiceImpl.scala b/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloGrpcServiceImpl.scala deleted file mode 100644 index 5954a746..00000000 --- a/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloGrpcServiceImpl.scala +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -// #service-impl -package com.lightbend.lagom.scaladsl.grpc.interop.test - -import scala.concurrent.Future - -import akka.actor.ActorSystem -import com.lightbend.lagom.scaladsl.grpc.interop.helloworld.AbstractGreeterServiceRouter -import com.lightbend.lagom.scaladsl.grpc.interop.helloworld.HelloReply -import com.lightbend.lagom.scaladsl.grpc.interop.helloworld.HelloRequest - -class HelloGrpcServiceImpl(sys: ActorSystem) extends AbstractGreeterServiceRouter(sys) { - override def sayHello(in: HelloRequest): Future[HelloReply] = - Future.successful(HelloReply(s"Hi ${in.name}! (gRPC)")) -} -// #service-impl diff --git a/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloLoader.scala b/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloLoader.scala deleted file mode 100644 index 9b13c7e0..00000000 --- a/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloLoader.scala +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package com.lightbend.lagom.scaladsl.grpc.interop.test - -import java.time.Duration - -import akka.actor.ActorSystem -import akka.grpc.GrpcClientSettings -import com.lightbend.lagom.scaladsl.grpc.interop.GreeterService -import com.lightbend.lagom.scaladsl.grpc.interop.helloworld.GreeterServiceClient -import com.lightbend.lagom.scaladsl.server._ -import com.softwaremill.macwire._ -import play.api.libs.ws.ahc.AhcWSComponents - -import scala.concurrent.ExecutionContextExecutor - -abstract class HelloApplication(context: LagomApplicationContext) - extends LagomApplication(context) - with AhcWSComponents { - - // #service-additional-router - // Bind the service that this server provides - override lazy val lagomServer = - serverFor[HelloService](wire[HelloServiceImpl]) - .additionalRouter(wire[HelloGrpcServiceImpl]) - // #service-additional-router - - // #service-client-conf - // Implicits required by GrpcClientSettings - private implicit val dispatcher: ExecutionContextExecutor = actorSystem.dispatcher - private implicit lazy val sys: ActorSystem = actorSystem - - private lazy val settings = GrpcClientSettings - .usingServiceDiscovery(GreeterService.name) - .withServicePortName("https") - // response timeout - .withDeadline(Duration.ofSeconds(5)) - // use a small reconnectionAttempts value to - // cause a client reload in case of failure - .withConnectionAttempts(5) - // #service-client-conf - - // #service-client-creation - lazy val greeterServiceClient: GreeterServiceClient = GreeterServiceClient(settings) - // #service-client-creation - -} diff --git a/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloService.scala b/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloService.scala deleted file mode 100644 index 2bd6cc97..00000000 --- a/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloService.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package com.lightbend.lagom.scaladsl.grpc.interop.test - -import akka.NotUsed -import com.lightbend.lagom.scaladsl.api.Service -import com.lightbend.lagom.scaladsl.api.ServiceCall - -/** - * The Hello service interface. - *

- * This describes everything that Lagom needs to know about how to serve and - * consume the HelloService. - */ -trait HelloService extends Service { - - /** - * Example: curl http://localhost:9000/api/hello/Alice - */ - def hello(id: String): ServiceCall[NotUsed, String] - - final override def descriptor = { - import Service._ - named("hello-srvc") - .withCalls( - pathCall("/api/hello/:id", hello _), - ) - .withAutoAcl(true) - } -} diff --git a/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloServiceImpl.scala b/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloServiceImpl.scala deleted file mode 100644 index 3db70321..00000000 --- a/lagom-interop-test-scala/src/main/scala/com/lightbend/lagom/scaladsl/grpc/interop/test/HelloServiceImpl.scala +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package com.lightbend.lagom.scaladsl.grpc.interop.test - -import com.lightbend.lagom.scaladsl.api.ServiceCall - -import scala.concurrent.Future - -/** - * Implementation of the HelloService. - */ -class HelloServiceImpl() extends HelloService { - - override def hello(id: String) = ServiceCall { _ => - Future.successful(s"Hi $id!") - } -} diff --git a/lagom-interop-test-scala/src/test/resources/logback.xml b/lagom-interop-test-scala/src/test/resources/logback.xml deleted file mode 100644 index 697e43dd..00000000 --- a/lagom-interop-test-scala/src/test/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - %date{ISO8601} %-5level %logger - %msg%n - - - - - - - - - - diff --git a/lagom-interop-test-scala/src/test/scala/com/example/hello/impl/HelloServiceSpec.scala b/lagom-interop-test-scala/src/test/scala/com/example/hello/impl/HelloServiceSpec.scala deleted file mode 100644 index 91c0cec2..00000000 --- a/lagom-interop-test-scala/src/test/scala/com/example/hello/impl/HelloServiceSpec.scala +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package com.example.hello.impl - -import akka.actor.ActorSystem -import com.lightbend.lagom.scaladsl.grpc.interop.helloworld.GreeterServiceClient -import com.lightbend.lagom.scaladsl.grpc.interop.helloworld.HelloRequest -import com.lightbend.lagom.scaladsl.grpc.interop.test.HelloApplication -import com.lightbend.lagom.scaladsl.grpc.interop.test.HelloService -import com.lightbend.lagom.scaladsl.server.LocalServiceLocator -import com.lightbend.lagom.scaladsl.testkit.ServiceTest -import com.lightbend.lagom.scaladsl.testkit.grpc.AkkaGrpcClientHelpers -import org.scalatest.BeforeAndAfterAll -import org.scalatest.matchers.should.Matchers -import org.scalatest.wordspec.AnyWordSpec -import org.scalatest.wordspec.AsyncWordSpec - -class HelloServiceAsyncSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll { - - private val server: ServiceTest.TestServer[HelloApplication with LocalServiceLocator] = ServiceTest.startServer( - ServiceTest.defaultSetup.withSsl(true).withCluster(false), - ) { ctx => - new HelloApplication(ctx) with LocalServiceLocator - } - - implicit val sys: ActorSystem = server.actorSystem - val client: HelloService = server.serviceClient.implement[HelloService] - - // #unmanaged-client - val grpcClient: GreeterServiceClient = AkkaGrpcClientHelpers.grpcClient( - server, - GreeterServiceClient.apply, - ) - - protected override def afterAll(): Unit = { - grpcClient.close() - server.stop() - } - - // #unmanaged-client - - "Hello service (Async)" should { - - "say hello over HTTP" in { - client.hello("Alice").invoke().map { answer => - answer should ===("Hi Alice!") - } - } - - // #unmanaged-client - "say hello over gRPC (unmnanaged client)" in { - grpcClient - .sayHello(HelloRequest("Alice")) - .map { - _.message should be("Hi Alice! (gRPC)") - } - } - // #unmanaged-client - - } - -} - -class HelloServiceSpec extends AnyWordSpec with Matchers with BeforeAndAfterAll { - - private val server: ServiceTest.TestServer[HelloApplication with LocalServiceLocator] = ServiceTest.startServer( - ServiceTest.defaultSetup.withSsl(true).withCluster(false), - ) { ctx => - new HelloApplication(ctx) with LocalServiceLocator - } - - implicit val sys: ActorSystem = server.actorSystem - implicit val ctx = server.executionContext - val client: HelloService = server.serviceClient.implement[HelloService] - - protected override def afterAll(): Unit = { - server.stop() - } - - "Hello service (Sync)" should { - - // #managed-client - "say hello over gRPC (managed client)" in { - AkkaGrpcClientHelpers.withGrpcClient(server, GreeterServiceClient.apply _) { grpcClient => - grpcClient - .sayHello(HelloRequest("Alice")) - .map { - _.message should be("Hi Alice! (gRPC)") - } - } - } - // #managed-client - - } - -} diff --git a/lagom-interop-test-scala/src/test/scala/resources/logback.xml b/lagom-interop-test-scala/src/test/scala/resources/logback.xml deleted file mode 100644 index 697e43dd..00000000 --- a/lagom-interop-test-scala/src/test/scala/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - %date{ISO8601} %-5level %logger - %msg%n - - - - - - - - - - diff --git a/lagom-interop-test-scala/src/test/scala/scala/com/example/hello/impl/HelloServiceSpec.scala b/lagom-interop-test-scala/src/test/scala/scala/com/example/hello/impl/HelloServiceSpec.scala deleted file mode 100644 index f0f73148..00000000 --- a/lagom-interop-test-scala/src/test/scala/scala/com/example/hello/impl/HelloServiceSpec.scala +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package scala.com.example.hello.impl - -import akka.actor.ActorSystem -import com.lightbend.lagom.scaladsl.grpc.interop.helloworld.GreeterServiceClient -import com.lightbend.lagom.scaladsl.grpc.interop.helloworld.HelloRequest -import com.lightbend.lagom.scaladsl.grpc.interop.test.HelloApplication -import com.lightbend.lagom.scaladsl.grpc.interop.test.HelloService -import com.lightbend.lagom.scaladsl.server.LocalServiceLocator -import com.lightbend.lagom.scaladsl.testkit.ServiceTest -import com.lightbend.lagom.scaladsl.testkit.grpc.AkkaGrpcClientHelpers -import org.scalatest.BeforeAndAfterAll -import org.scalatest.matchers.should.Matchers -import org.scalatest.wordspec.AsyncWordSpec - -class HelloServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll { - - private val server: ServiceTest.TestServer[HelloApplication with LocalServiceLocator] = ServiceTest.startServer( - ServiceTest.defaultSetup.withSsl(true), - ) { ctx => - new HelloApplication(ctx) with LocalServiceLocator - } - - implicit val sys: ActorSystem = server.actorSystem - - val client: HelloService = server.serviceClient.implement[HelloService] - val grpcClient: GreeterServiceClient = AkkaGrpcClientHelpers.grpcClient( - server, - GreeterServiceClient.apply, - ) - - protected override def afterAll(): Unit = { - grpcClient.close() - server.stop() - } - - "Hello service" should { - - "say hello over HTTP" in { - client.hello("Alice").invoke().map { answer => - answer should ===("Hi Alice!") - } - } - - "say hello over gRPC" in { - grpcClient - .sayHello(HelloRequest("Alice")) - .map { - _.message should be("Hi Alice! (gRPC)") - } - } - - } -} diff --git a/lagom-javadsl-grpc-testkit/src/main/java/com/lightbend/lagom/javadsl/testkit/grpc/AkkaGrpcClientHelpers.java b/lagom-javadsl-grpc-testkit/src/main/java/com/lightbend/lagom/javadsl/testkit/grpc/AkkaGrpcClientHelpers.java deleted file mode 100644 index 428ebcb8..00000000 --- a/lagom-javadsl-grpc-testkit/src/main/java/com/lightbend/lagom/javadsl/testkit/grpc/AkkaGrpcClientHelpers.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package com.lightbend.lagom.javadsl.testkit.grpc; - -import akka.actor.ClassicActorSystemProvider; -import akka.annotation.ApiMayChange; -import akka.grpc.GrpcClientSettings; -import akka.grpc.javadsl.AkkaGrpcClient; -import akka.japi.function.Function; -import akka.japi.function.Function2; -import akka.japi.function.Function3; -import akka.japi.function.Procedure; -import com.lightbend.lagom.javadsl.testkit.ServiceTest; -import scala.concurrent.ExecutionContext; - -/** Helpers to test Java Akka gRPC clients with Lagom */ -@ApiMayChange -public class AkkaGrpcClientHelpers { - - /** - * Builds an AkkaGrpcClient for the server run during tests. The - * server must run with SSL enabled, otherwise the creation of a client will fail. - * - * @param server the ServiceTest.TestServer started to run the tests on - * @param clientFactory a factory method as create by the Akka gRPC code generators - * @param block user code that given a client will execute the test - * @param - * @throws IllegalArgumentException if the server is not setup with SSL enabled - */ - public static void withGrpcClient( - ServiceTest.TestServer server, - // TODO: replace with AkkaGrpcClientFactory - Function2 clientFactory, - Procedure block) - throws Exception { - Function f = - t -> { - block.apply(t); - return null; - }; - withGrpcClient(server, clientFactory, f); - } - - /** - * Builds an AkkaGrpcClient for the server run during tests. The - * server must run with SSL enabled, otherwise the creation of a client will fail. - * - * @param server the ServiceTest.TestServer started to run the tests on - * @param clientFactory a factory method as create by the Akka gRPC code generators - * @param block user code that given a client will execute the test - * @param - * @throws IllegalArgumentException if the server is not setup with SSL enabled - */ - public static Result withGrpcClient( - ServiceTest.TestServer server, - // TODO: replace with AkkaGrpcClientFactory - Function2 clientFactory, - Function block) - throws Exception { - T grpcClient = null; - Result result = null; - - try { - grpcClient = grpcClient(server, clientFactory); - result = block.apply(grpcClient); - } finally { - if (grpcClient != null) { - // TODO: Await until `close` completes (like play-scalatest and play-specs2) - grpcClient.close(); - } - } - - return result; - } - - /** - * Builds an AkkaGrpcClient for the server run during tests. The - * server must run with SSL enabled, otherwise the creation of a client will fail. - * - *

The returned `client` must be stopped (in an `@AfterAll` method, for example). - * - * @param server the ServiceTest.TestServer started to run the tests on - * @param clientFactory a factory method as create by the Akka gRPC code generators - * @param - * @throws IllegalArgumentException if the server is not setup with SSL enabled - */ - public static T grpcClient( - ServiceTest.TestServer server, - // TODO: replace with AkkaGrpcClientFactory - Function2 clientFactory) - throws Exception { - - if (!server.portSsl().isPresent()) - throw new IllegalArgumentException( - "Creation of a gRPC client is useless. The ServiceTest.TestServer must be setup with SSL enabled."); - - int sslPort = server.portSsl().get(); - - GrpcClientSettings settings = - GrpcClientSettings.connectToServiceAt("127.0.0.1", sslPort, server.system()) - .withSslContext(server.clientSslContext().get()) - // the authority must match the value of the SSL certificate used in - // the ServiceTest.TestServer (if/when that changes or is configurable) - // this value will have to be configurable - .withOverrideAuthority("localhost"); - - return clientFactory.apply(settings, server.system()); - } -} diff --git a/lagom-scaladsl-grpc-testkit/src/main/scala/com/lightbend/lagom/scaladsl/testkit/grpc/AkkaGrpcClientHelpers.scala b/lagom-scaladsl-grpc-testkit/src/main/scala/com/lightbend/lagom/scaladsl/testkit/grpc/AkkaGrpcClientHelpers.scala deleted file mode 100644 index cc9760b4..00000000 --- a/lagom-scaladsl-grpc-testkit/src/main/scala/com/lightbend/lagom/scaladsl/testkit/grpc/AkkaGrpcClientHelpers.scala +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. - */ -package com.lightbend.lagom.scaladsl.testkit.grpc - -import java.util.concurrent.TimeUnit - -import scala.concurrent.Await -import scala.concurrent.duration.Duration - -import akka.annotation.ApiMayChange -import akka.grpc.GrpcClientSettings -import akka.grpc.scaladsl.AkkaGrpcClient - -import com.lightbend.lagom.scaladsl.testkit.ServiceTest - -/** - * Helpers to test Java Akka gRPC clients with Lagom - */ -@ApiMayChange -object AkkaGrpcClientHelpers { - - /** - * Builds an `AkkaGrpcClient` for the `server` run during tests. The `server` - * must run with SSL enabled, otherwise the creation of a client will fail. - * - * @param server the `ServiceTest.TestServer` started to run the tests on - * @param clientFactory a factory method as create by the Akka gRPC code generators - * @return T the desired grpc client (as generated by the Akka gRPC code generators) - * @throws IllegalArgumentException if the `server` is not setup with SSL enabled - */ - def withGrpcClient[T <: AkkaGrpcClient, Q]( - server: ServiceTest.TestServer[_], - // TODO: replace with AkkaGrpcClientFactory - clientFactory: GrpcClientSettings => T, - )(block: T => Q): Q = { - var client: T = null.asInstanceOf[T] - try { - client = grpcClient[T](server, clientFactory) - block(client) - } finally { - if (client != null) { - Await.result(client.close(), grpcClientCloseTimeout) - () - } - } - } - - /** - * Builds an `AkkaGrpcClient` for the `server` run during tests. The `server` - * must run with SSL enabled, otherwise the creation of a client will fail. - * - * The returned `client` must be stopped (in an `afterAll` block, for example). - * - * @param server the `ServiceTest.TestServer` started to run the tests on - * @param clientFactory a factory method as create by the Akka gRPC code generators - * @return T the desired grpc client (as generated by the Akka gRPC code generators) - * @throws IllegalArgumentException if the `server` is not setup with SSL enabled - */ - @throws[IllegalArgumentException] - def grpcClient[T <: AkkaGrpcClient]( - server: ServiceTest.TestServer[_], - // TODO: replace with AkkaGrpcClientFactory - clientFactory: GrpcClientSettings => T, - ): T = { - - if (server.playServer.httpsPort.isEmpty) - throw new IllegalArgumentException( - "Creation of a gRPC client is useless. The ServiceTest.TestServer must be setup with SSL enabled.", - ) - - val httpsPort = server.playServer.httpsPort.get - - val settings = GrpcClientSettings - .connectToServiceAt("127.0.0.1", httpsPort)(server.actorSystem) - .withSslContext(server.clientSslContext.get) - // the authority must match the value of the SSL certificate used in - // the ServiceTest.TestServer (if/when that changes or is configurable) - // this value will have to be configurable - .withOverrideAuthority("localhost") - - clientFactory(settings) - } - - /** The close timeout used by gRPC clients. */ - protected def grpcClientCloseTimeout: Duration = Duration(30, TimeUnit.SECONDS) - -} diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 0b2686fb..df72845e 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -19,8 +19,7 @@ object Dependencies { val akkaGrpc = AkkaGrpcBuildInfo.version val grpc = AkkaGrpcBuildInfo.grpcVersion - val play = "2.8.17" - val lagom = "1.6.7" + val play = "2.8.17" val scalaTest = "3.1.4" val scalaTestPlusPlay = "5.1.0" @@ -57,9 +56,6 @@ object Dependencies { val scalaTestPlusPlay = "org.scalatestplus.play" %% "scalatestplus-play" % Versions.scalaTestPlusPlay // Apache V2 - val lagomJavadslTestKit = "com.lightbend.lagom" %% "lagom-javadsl-testkit" % Versions.lagom - val lagomScaladslTestKit = "com.lightbend.lagom" %% "lagom-scaladsl-testkit" % Versions.lagom - val macwire = "com.softwaremill.macwire" %% "macros" % Versions.macwire % "provided" }