diff --git a/.travis.yml b/.travis.yml
index 7b9253d3..6dc4127b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,6 +13,7 @@ env:
global:
- TRAVIS_JDK=11
- JABBA_HOME=$HOME/.jabba
+ - RUN_DROP_TRAVIS_CACHES_STAGE=true
before_install:
# See https://github.com/travis-ci/travis-ci/issues/4629#issuecomment-239493916
@@ -42,6 +43,17 @@ before_cache:
jobs:
include:
+
+ - stage: drop-travis-caches
+ # Introduced 2020-10-19 as we noticed serious problems with Travis' caching
+ script:
+ - rm -rf $HOME/.cache/coursier
+ - rm -rf $HOME/.ivy2/cache
+ - rm -rf $HOME/.jabba
+ - rm -rf $HOME/.sbt
+ - rm -rf $HOME/.m2/repository
+ name: "drop-travis-caches"
+
# Mixed Persistence Samples
- stage: test-java-11
name: "Run tests Mixed Persistence (java)"
@@ -141,10 +153,18 @@ jobs:
- docker-compose -f couchbase-persistence/docker/docker-compose.yml up -d couchbase
- sleep 30s
- "cd couchbase-persistence/couchbase-persistence-scala-sbt && sbt test stage"
+
stages:
- - test-java-11
- - test-java-8
+ - name: drop-travis-caches
+ # to drop caches trigger a custom build with
+ # env:
+ # global:
+ # - RUN_DROP_TRAVIS_CACHES_STAGE=true
+ if: env(RUN_DROP_TRAVIS_CACHES_STAGE) = true
+ - name: test-java-11
+ - name: test-java-8
+
notifications:
webhooks:
diff --git a/grpc-example/grpc-example-java/build.sbt b/grpc-example/grpc-example-java/build.sbt
index 645e8dfd..0f1f6b5a 100644
--- a/grpc-example/grpc-example-java/build.sbt
+++ b/grpc-example/grpc-example-java/build.sbt
@@ -9,9 +9,7 @@ version in ThisBuild := "1.0-SNAPSHOT"
// the Java version that will be used for cross-compiled libraries
scalaVersion in ThisBuild := "2.12.12"
-lagomServiceEnableSsl in ThisBuild := true
-val `hello-impl-HTTPS-port` = 11000
-
+val `hello-impl-HTTP-port` = 11000
val playGrpcRuntime = "com.lightbend.play" %% "play-grpc-runtime" % BuildInfo.playGrpcVersion
val lagomGrpcTestkit = "com.lightbend.play" %% "lagom-javadsl-grpc-testkit" % BuildInfo.playGrpcVersion % Test
// TODO remove after upgrade Akka gRPC
@@ -44,7 +42,7 @@ lazy val `hello-impl` = (project in file("hello-impl"))
// WORKAROUND: Lagom still can't register a service under the gRPC name so we hard-code
// the port and the use the value to add the entry on the Service Registry
- lagomServiceHttpsPort := `hello-impl-HTTPS-port`,
+ lagomServiceHttpPort := `hello-impl-HTTP-port`,
libraryDependencies ++= Seq(
lagomJavadslTestKit,
@@ -75,6 +73,7 @@ lazy val `hello-proxy-impl` = (project in file("hello-proxy-impl"))
libraryDependencies ++= Seq(
lagomJavadslTestKit,
lagomLogback,
+ playGrpcRuntime,
akkaHttp
)
)
@@ -91,9 +90,8 @@ lagomKafkaEnabled in ThisBuild := false
// This adds an entry on the LagomDevMode Service Registry. With this information on
// the Service Registry a client using Service Discovery to Lookup("helloworld.GreeterService")
-// will get "https://localhost:11000" and then be able to send a request.
-// See declaration and usages of `hello-impl-HTTPS-port`.
-lagomUnmanagedServices in ThisBuild := Map("helloworld.GreeterService" -> s"https://localhost:${`hello-impl-HTTPS-port`}")
+// will get "http://localhost:11000" and then be able to send a request.
+lagomUnmanagedServices in ThisBuild := Map("helloworld.GreeterService" -> s"http://127.0.0.1:${`hello-impl-HTTP-port`}")
def common = Seq(
diff --git a/grpc-example/grpc-example-java/docs/src/main/paradox/index.md b/grpc-example/grpc-example-java/docs/src/main/paradox/index.md
index 15b37523..cab9736f 100644
--- a/grpc-example/grpc-example-java/docs/src/main/paradox/index.md
+++ b/grpc-example/grpc-example-java/docs/src/main/paradox/index.md
@@ -16,29 +16,26 @@ cd grpc-example/grpc-example-java
## Running the example
-Using gRPC in Lagom requires adding a Java Agent to the runtime. In order to handle this setting we provide a script that will
-download the ALPN Java Agent and start an interactive `sbt` console properly set up. Use the `ssl-lagom`
-script:
+You can run it like any Lagom application.
+
+In Maven,
```bash
-./ssl-lagom
+mvn lagom:runAll
```
-The first time you run the script it will take some time to resolve and download some dependencies. Once
-ready you'll be at the `sbt` console. Use the `runAll` command to start the Lagom gRPC Example:
+In sbt,
```bash
-sbt:lagom-java-grpc-example> runAll
+sbt runAll
```
The `runAll` command starts Lagom in development mode. Once all the services are started you will see Lagom's start message:
-```
+```bash
...
-[info] Service hello-proxy-impl listening for HTTP on 127.0.0.1:54328
-[info] Service hello-proxy-impl listening for HTTPS on 127.0.0.1:65108
-[info] Service hello-impl listening for HTTP on 127.0.0.1:65499
-[info] Service hello-impl listening for HTTPS on 127.0.0.1:11000
+[INFO] Service hello-impl listening for HTTP on 127.0.0.1:11000
+[INFO] Service hello-proxy-impl listening for HTTP on 127.0.0.1:54328
[info] (Services started, press enter to stop and go back to the console...)
```
@@ -56,7 +53,7 @@ Hi Steve! (gRPC)
This application is built with two Lagom services (`hello` and `hello-proxy`) exposing the following endpoints:
-```
+```bash
GET /proxy/rest-hello/:id # served by hello-proxy-service (HTTP-JSON)
GET /proxy/grpc-hello/:id # served by hello-proxy-service (HTTP-JSON)
GET /api/hello/:id # served by hello-service (HTTP-JSON)
@@ -64,7 +61,7 @@ GET /api/hello/:id # served by hello-service (HTTP-JSON)
And also:
-```
+```bash
/helloworld.GreetingsService/sayHello # served by hello-service (gRPC)
```
@@ -82,7 +79,7 @@ curl http://localhost:9000/proxy/rest-hello/Alice
The following happens:
-```
+```bash
curl --(http)--> service gateway --(http)--> hello-proxy-service --(http)--> hello-service
```
@@ -94,40 +91,31 @@ curl http://localhost:9000/proxy/grpc-hello/Alice
The following happens
-```
-curl --(http)--> service gateway --(http)--> hello-proxy-service --(gRPC/https)--> hello-service
+```bash
+curl --(http)--> service gateway --(http)--> hello-proxy-service --(gRPC/http)--> hello-service
```
## Testing the gRPC endpoints
The gRPC endpoints are not accessible via the Lagom Service Gateway so it's only possible to consume them from
-another Lagom service or pointing a client directly to the `https - HTTP/2` port of the Lagom Service. Earlier we
+another Lagom service or pointing a client directly to the `HTTP/2` port of the Lagom Service. Earlier we
saw that Lagom informs of the following bindings:
-```
+```bash
...
-[info] Service hello-proxy-impl listening for HTTP on 127.0.0.1:54328
-[info] Service hello-proxy-impl listening for HTTPS on 127.0.0.1:65108
-[info] Service hello-impl listening for HTTP on 127.0.0.1:65499
-[info] Service hello-impl listening for HTTPS on 127.0.0.1:11000
+[INFO] Service hello-impl listening for HTTP on 127.0.0.1:11000
+[INFO] Service hello-proxy-impl listening for HTTP on 127.0.0.1:54328
[info] (Services started, press enter to stop and go back to the console...)
```
-You can test the gRPC endpoint using [grpcc](https://github.com/njpatel/grpcc). Because Lagom uses self-signed
-certificates, you will have to export and trust the CA certificate:
-
-```bash
-keytool -export -alias sslconfig-selfsigned -keystore target/dev-mode/selfsigned.keystore -storepass "" -file trustedCA.crt
-openssl x509 -in trustedCA.crt -out trustedCA.pem -inform DER -outform PEM
-```
-
-Once the CA certificate is extracted we can use `grpcc` to test the application:
+You can test the gRPC endpoint using [gRPCurl](https://github.com/fullstorydev/grpcurl).
+Note that for simplicity, this sample is disabling TLS, therefore it's possbile to call the `HTTP/2` endpoint without using https.
```bash
-$ grpcc --proto hello-impl/src/main/protobuf/helloworld.proto \
- --address localhost:11000 \
- --eval 'client.sayHello({name:"Katherine"}, printReply)' \
- --root_cert ./trustedCA.pem
+$ grpcurl --proto hello-impl/src/main/protobuf/helloworld.proto \
+ -d '{"name": "Katherine" }' \
+ -plaintext 127.0.0.1:11000 \
+ helloworld.GreeterService.SayHello
{
"message": "Hi Katherine! (gRPC)"
}
@@ -136,8 +124,8 @@ $ grpcc --proto hello-impl/src/main/protobuf/helloworld.proto \
The command above:
1. Uses the gRPC description on `hello-impl/src/main/protobuf/helloworld.proto`
-2. Connects to the `hello-impl` service using `https` at `localhost:11000` (trusting the CA used to build the `localhost:11000` certificate)
-3. Sends a gRPC call `client.sayHello({name:"Katherine"},...)` (`grpcc` requires registering a callback, in this case `printReply` to send the response to the `stdout`).
+1. Connects to the `hello-impl` service at `127.0.0.1:11000` using plaintext over `http`.
+1. Sends a gRPC call `helloworld.GreeterService.SayHello` with `{"name": "Katherine" }` payload.
## References
diff --git a/grpc-example/grpc-example-java/hello-impl/pom.xml b/grpc-example/grpc-example-java/hello-impl/pom.xml
index 86fdd712..35eccc79 100644
--- a/grpc-example/grpc-example-java/hello-impl/pom.xml
+++ b/grpc-example/grpc-example-java/hello-impl/pom.xml
@@ -104,9 +104,8 @@
lagom-maven-plugin
true
- ${hello-impl.https.port}
+ ${hello-impl.http.port}
127.0.0.1
- true
diff --git a/grpc-example/grpc-example-java/hello-impl/src/main/resources/logback.xml b/grpc-example/grpc-example-java/hello-impl/src/main/resources/logback.xml
new file mode 100644
index 00000000..1b1d8a3f
--- /dev/null
+++ b/grpc-example/grpc-example-java/hello-impl/src/main/resources/logback.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ %date{"HH:mm:ss.SSS"} %coloredLevel %logger [%mdc] - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/grpc-example/grpc-example-java/hello-impl/src/test/java/com/example/hello/impl/HelloServiceTest.java b/grpc-example/grpc-example-java/hello-impl/src/test/java/com/example/hello/impl/HelloServiceTest.java
index 679400f2..a9bae113 100644
--- a/grpc-example/grpc-example-java/hello-impl/src/test/java/com/example/hello/impl/HelloServiceTest.java
+++ b/grpc-example/grpc-example-java/hello-impl/src/test/java/com/example/hello/impl/HelloServiceTest.java
@@ -2,7 +2,7 @@
import akka.grpc.GrpcClientSettings;
import com.example.hello.api.HelloService;
-import com.lightbend.lagom.javadsl.testkit.grpc.AkkaGrpcClientHelpers;
+import com.lightbend.lagom.javadsl.testkit.ServiceTest;
import example.myapp.helloworld.grpc.GreeterServiceClient;
import example.myapp.helloworld.grpc.HelloReply;
import example.myapp.helloworld.grpc.HelloRequest;
@@ -28,20 +28,16 @@ public void shouldSayHelloUsingALagomClient() throws Exception {
@Test
public void shouldSayHelloUsingGrpc() throws Exception {
- withServer(defaultSetup().withSsl(), server -> {
- AkkaGrpcClientHelpers
- .withGrpcClient(
- server,
- GreeterServiceClient::create,
- serviceClient -> {
- HelloRequest request =
- HelloRequest.newBuilder().setName("Steve").build();
- HelloReply reply = serviceClient
- .sayHello(request)
- .toCompletableFuture()
- .get(5, SECONDS);
- assertEquals("Hi Steve (gRPC)", reply.getMessage());
- });
+ withServer(defaultSetup(), server -> {
+ GreeterServiceClient serviceClient = createServiceClient(server);
+
+ HelloRequest request =
+ HelloRequest.newBuilder().setName("Steve").build();
+ HelloReply reply = serviceClient
+ .sayHello(request)
+ .toCompletableFuture()
+ .get(5, SECONDS);
+ assertEquals("Hi Steve (gRPC)", reply.getMessage());
});
}
@@ -51,11 +47,7 @@ public void shouldSayHelloUsingGrpc() throws Exception {
@Test
public void shouldSayHelloUsingGrpcNoSsl() throws Exception {
withServer(defaultSetup(), server -> {
- GrpcClientSettings settings = GrpcClientSettings
- .connectToServiceAt("127.0.0.1", server.port(), server.system())
- .withTls(false);
- GreeterServiceClient serviceClient = GreeterServiceClient.create(settings, server.system());
-
+ GreeterServiceClient serviceClient = createServiceClient(server);
HelloRequest request =
HelloRequest.newBuilder().setName("Steve").build();
HelloReply reply = serviceClient
@@ -66,4 +58,10 @@ public void shouldSayHelloUsingGrpcNoSsl() throws Exception {
});
}
+ private GreeterServiceClient createServiceClient(ServiceTest.TestServer server) {
+ GrpcClientSettings settings = GrpcClientSettings
+ .connectToServiceAt("127.0.0.1", server.port(), server.system())
+ .withTls(false);
+ return GreeterServiceClient.create(settings, server.system());
+ }
}
diff --git a/grpc-example/grpc-example-java/hello-proxy-impl/pom.xml b/grpc-example/grpc-example-java/hello-proxy-impl/pom.xml
index 8c600855..7c77e6fd 100644
--- a/grpc-example/grpc-example-java/hello-proxy-impl/pom.xml
+++ b/grpc-example/grpc-example-java/hello-proxy-impl/pom.xml
@@ -69,7 +69,6 @@
lagom-maven-plugin
true
- true
diff --git a/grpc-example/grpc-example-java/hello-proxy-impl/src/main/resources/application.conf b/grpc-example/grpc-example-java/hello-proxy-impl/src/main/resources/application.conf
index d99f7628..fd255755 100644
--- a/grpc-example/grpc-example-java/hello-proxy-impl/src/main/resources/application.conf
+++ b/grpc-example/grpc-example-java/hello-proxy-impl/src/main/resources/application.conf
@@ -9,12 +9,12 @@ akka.grpc.client {
service-discovery {
mechanism = "lagom-dev-mode"
service-name = "helloworld.GreeterService"
- port-name = "https"
+ port-name = "http"
}
override-authority = "localhost"
deadline = 5s
connection-attempts = 5
+ use-tls = false
}
}
-
diff --git a/grpc-example/grpc-example-java/hello-proxy-impl/src/main/resources/logback.xml b/grpc-example/grpc-example-java/hello-proxy-impl/src/main/resources/logback.xml
new file mode 100644
index 00000000..c699abe6
--- /dev/null
+++ b/grpc-example/grpc-example-java/hello-proxy-impl/src/main/resources/logback.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ %date{"HH:mm:ss.SSS"} %coloredLevel %logger [%mdc] - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/grpc-example/grpc-example-java/hello-proxy-impl/src/test/java/com/example/helloproxy/impl/HelloProxyServiceImplTest.java b/grpc-example/grpc-example-java/hello-proxy-impl/src/test/java/com/example/helloproxy/impl/HelloProxyServiceImplTest.java
index 54dadf8e..35c66d10 100644
--- a/grpc-example/grpc-example-java/hello-proxy-impl/src/test/java/com/example/helloproxy/impl/HelloProxyServiceImplTest.java
+++ b/grpc-example/grpc-example-java/hello-proxy-impl/src/test/java/com/example/helloproxy/impl/HelloProxyServiceImplTest.java
@@ -32,8 +32,6 @@ public class HelloProxyServiceImplTest {
@BeforeClass
public static void setUp() {
ServiceTest.Setup setup = defaultSetup()
- .withCluster(false)
- .withSsl(false)
.configureBuilder(builder ->
builder
.disable(AkkaGrpcClientModule.class)
diff --git a/grpc-example/grpc-example-java/pom.xml b/grpc-example/grpc-example-java/pom.xml
index e1fe1817..42d21d8b 100644
--- a/grpc-example/grpc-example-java/pom.xml
+++ b/grpc-example/grpc-example-java/pom.xml
@@ -36,7 +36,7 @@
false
false
- https://127.0.0.1:${hello-impl.https.port}
+ http://127.0.0.1:${hello-impl.http.port}
@@ -82,6 +82,6 @@
1.0.2
0.9.1
- 11000
+ 11000
diff --git a/grpc-example/grpc-example-java/ssl-lagom b/grpc-example/grpc-example-java/ssl-lagom
deleted file mode 100755
index 626bab6f..00000000
--- a/grpc-example/grpc-example-java/ssl-lagom
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-## Based on https://github.com/playframework/play-scala-tls-example/edit/2.5.x/play
-## All JVM_XXX options are removed because Lagom does a different handling of SSL
-## than Play. Only the ALPN Agent setup is relevant for Lagom.
-
-# ssl-play requires an ALPN Agent. This is downdloaded and stored in the target
-# folder of each subproject that needs ALPN enabled.
-# This snippet detects when the ALPN agent hasn't been downloaded yet and runs
-# `sbt stage` to obtain it.
-export AGENT_TEST=$(pwd)/$(find . -name 'jetty-alpn-agent-*.jar')
-export NUM_AGENTS_FOUND=$(echo $AGENT_TEST| grep target | wc -l)
-
-if [ $NUM_AGENTS_FOUND -eq "0" ]; then
- sbt stage;
-fi
-
-# Start `sbt` with the JVM_OPTIONS and the ALPN agent
-export AGENT=$(pwd)/$(find . -name 'jetty-alpn-agent-*.jar' | head -1)
-echo "Detected ALPN Agent: $AGENT "
-export SBT_OPTS="$SBT_OPTS -javaagent:$AGENT"
-# Run Play
-sbt $JVM_OPTIONS $*;
diff --git a/grpc-example/grpc-example-scala/build.sbt b/grpc-example/grpc-example-scala/build.sbt
index 4826e39a..fd460a04 100644
--- a/grpc-example/grpc-example-scala/build.sbt
+++ b/grpc-example/grpc-example-scala/build.sbt
@@ -14,8 +14,7 @@ val lagomGrpcTestkit = "com.lightbend.play" %% "lagom-scaladsl-grpc-testkit" % B
// TODO remove after upgrade Akka gRPC
val akkaHttp = "com.typesafe.akka" %% "akka-http2-support" % "10.1.12"
-lagomServiceEnableSsl in ThisBuild := true
-val `hello-impl-HTTPS-port` = 11000
+val `hello-impl-HTTP-port` = 11000
def dockerSettings = Seq(
dockerUpdateLatest := true,
@@ -24,13 +23,6 @@ def dockerSettings = Seq(
dockerRepository := sys.props.get("docker.registry")
)
-// ALL SETTINGS HERE ARE TEMPORARY WORKAROUNDS FOR KNOWN ISSUES OR WIP
-def workaroundSettings: Seq[sbt.Setting[_]] = Seq(
- // Lagom still can't register a service under the gRPC name so we hard-code
- // the port and use the value to add the entry on the Service Registry
- lagomServiceHttpsPort := `hello-impl-HTTPS-port`
-)
-
lazy val `lagom-scala-grpc-example` = (project in file("."))
.aggregate(`hello-api`, `hello-impl`, `hello-proxy-api`, `hello-proxy-impl`)
@@ -51,9 +43,11 @@ lazy val `hello-impl` = (project in file("hello-impl"))
AkkaGrpc.Client // the client is only used in tests. See https://github.com/akka/akka-grpc/issues/410
),
akkaGrpcExtraGenerators in Compile += PlayScalaServerCodeGenerator,
- ).settings(
- workaroundSettings:_*
- ).settings(
+
+ // WORKAROUND: Lagom still can't register a service under the gRPC name so we hard-code
+ // the port and the use the value to add the entry on the Service Registry
+ lagomServiceHttpPort := `hello-impl-HTTP-port`,
+
libraryDependencies ++= Seq(
lagomScaladslTestKit,
macwire,
@@ -81,6 +75,7 @@ lazy val `hello-proxy-impl` = (project in file("hello-proxy-impl"))
libraryDependencies ++= Seq(
lagomScaladslAkkaDiscovery,
lagomScaladslTestKit,
+ playGrpcRuntime,
akkaHttp,
macwire,
scalaTest
@@ -101,13 +96,11 @@ lagomKafkaEnabled in ThisBuild := false
// This adds an entry on the LagomDevMode Service Registry. With this information on
// the Service Registry a client using Service Discovery to Lookup("helloworld.GreeterService")
-// will get "https://localhost:11000" and then be able to send a request.
-// See declaration and usages of `hello-impl-HTTPS-port`.
-lagomUnmanagedServices in ThisBuild := Map("helloworld.GreeterService" -> s"https://localhost:${`hello-impl-HTTPS-port`}")
+// will get "http://127.0.0.1:11000" and then be able to send a request.
+lagomUnmanagedServices in ThisBuild := Map("helloworld.GreeterService" -> s"http://127.0.0.1:${`hello-impl-HTTP-port`}")
//----------------------------------
-
// Documentation for this project:
// sbt "project docs" "~ paradox"
// open docs/target/paradox/site/main/index.html
diff --git a/grpc-example/grpc-example-scala/docs/src/main/paradox/index.md b/grpc-example/grpc-example-scala/docs/src/main/paradox/index.md
index 6e324977..e5dfe53f 100644
--- a/grpc-example/grpc-example-scala/docs/src/main/paradox/index.md
+++ b/grpc-example/grpc-example-scala/docs/src/main/paradox/index.md
@@ -1,13 +1,13 @@
# Lagom gRPC Example (Scala)
[Lagom](https://www.lagomframework.com/) is an open source framework (built on [Akka](https://akka.io/) and [Play](https://www.playframework.com/)) for developing reactive microservice systems in Java or Scala.
-[Akka gRPC](https://developer.lightbend.com/docs/akka-grpc/current/overview.html) is a toolkit for building streaming gRPC servers and clients on top of Akka Streams.
+[Akka gRPC](https://developer.lightbend.com/docs/akka-grpc/current/overview.html) and [Play gRPC](https://developer.lightbend.com/docs/play-grpc/current/) are toolkits for building streaming gRPC servers and clients on top of Akka Streams and Play.
This Guide will show you how to use Akka gRPC as an alternate RPC library to communicate two microservices developed using Lagom.
-## Downloading the example.
+## Downloading the example
-The Lagom gRPC Example is the [Lagom Samples GitHub repository](https://github.com/lagom/lagom-samples) that you can clone locally:
+The Lagom gRPC Example is in the [Lagom Samples GitHub repository](https://github.com/lagom/lagom-samples) that you can clone locally:
```bash
git clone https://github.com/lagom/lagom-samples.git
@@ -16,29 +16,18 @@ cd grpc-example/grpc-example-scala
## Running the example
-Using gRPC in Lagom requires adding a Java Agent to the runtime. In order to handle this setting we provide a script that will
-download the ALPN Java Agent and start an interactive `sbt` console properly set up. Use the `ssl-lagom`
-script:
+You can run it like any Lagom application.
-```
-./ssl-lagom
-```
-
-The first time you run the script it will take some time to resolve and download some dependencies. Once
-ready you'll be at the `sbt` console. Use the `runAll` command to start the Lagom gRPC Example:
-
-```
-sbt:lagom-scala-grpc-example> runAll
+```bash
+sbt runAll
```
The `runAll` command starts Lagom in development mode. Once all the services are started you will see Lagom's start message:
-```
+```bash
...
-[info] Service hello-proxy-impl listening for HTTP on 127.0.0.1:54328
-[info] Service hello-proxy-impl listening for HTTPS on 127.0.0.1:65108
-[info] Service hello-impl listening for HTTP on 127.0.0.1:65499
-[info] Service hello-impl listening for HTTPS on 127.0.0.1:11000
+[INFO] Service hello-impl listening for HTTP on 127.0.0.1:11000
+[INFO] Service hello-proxy-impl listening for HTTP on 127.0.0.1:54328
[info] (Services started, press enter to stop and go back to the console...)
```
@@ -52,12 +41,11 @@ $ curl http://localhost:9000/proxy/grpc-hello/Steve
Hi Steve! (gRPC)
```
-
## Application Structure
This application is built with two Lagom services (`hello` and `hello-proxy`) exposing the following endpoints:
-```
+```bash
GET /proxy/rest-hello/:id # served by hello-proxy-service (HTTP-JSON)
GET /proxy/grpc-hello/:id # served by hello-proxy-service (HTTP-JSON)
GET /api/hello/:id # served by hello-service (HTTP-JSON)
@@ -65,7 +53,7 @@ GET /api/hello/:id # served by hello-service (HTTP-JSON)
And also
-```
+```bash
/helloworld.GreetingsService/sayHello # served by hello-service (gRPC)
```
@@ -78,64 +66,61 @@ values the `hello-proxy` always forwards the request downstream to `hello-servic
So when you invoke:
-```
+```bash
$ curl http://localhost:9000/proxy/rest-hello/Alice
```
The following happens:
-```
+```bash
curl --(http)--> service gateway --(http)--> hello-proxy-service --(http)--> hello-service
```
Alternatively:
-```
+```bash
$ curl http://localhost:9000/proxy/grpc-hello/Alice
```
The following happens
-```
- curl --(http)--> service gateway --(http)--> hello-proxy-service --(gRPC/https)--> hello-service
+```bash
+ curl --(http)--> service gateway --(http)--> hello-proxy-service --(gRPC/http)--> hello-service
```
## Testing the gRPC endpoints
The gRPC endpoints are not accessible via the Lagom Service Gateway so it's only possible to consume them from
-another Lagom service or pointing a client directly to the `https - HTTP/2` port of the Lagom Service. Earlier we
+another Lagom service or pointing a client directly to the `HTTP/2` port of the Lagom Service. Earlier we
saw that Lagom informs of the following bindings:
-```
+```bash
...
-[info] Service hello-proxy-impl listening for HTTP on 127.0.0.1:54328
-[info] Service hello-proxy-impl listening for HTTPS on 127.0.0.1:65108
-[info] Service hello-impl listening for HTTP on 127.0.0.1:65499
-[info] Service hello-impl listening for HTTPS on 127.0.0.1:11000
+[INFO] Service hello-impl listening for HTTP on 127.0.0.1:11000
+[INFO] Service hello-proxy-impl listening for HTTP on 127.0.0.1:54328
[info] (Services started, press enter to stop and go back to the console...)
```
-You can test the gRPC endpoint using [grpcc](https://github.com/njpatel/grpcc). Because Lagom uses self-signed
-certificates, you will have to export and trust the CA certificate:
+You can test the gRPC endpoint using [gRPCurl](https://github.com/fullstorydev/grpcurl).
+Note that for simplicity, this sample is disabling TLS, therefore it's possbile to call the `HTTP/2` endpoint without using https.
```bash
-keytool -export -alias sslconfig-selfsigned -keystore target/dev-mode/selfsigned.keystore -storepass "" -file trustedCA.crt
-openssl x509 -in trustedCA.crt -out trustedCA.pem -inform DER -outform PEM
-```
-
-Once the CA certificate is extracted we can use `grpcc` to test the application:
-
-```bash
-$ grpcc --proto hello-impl/src/main/protobuf/helloworld.proto \
- --address localhost:11000 \
- --eval 'client.sayHello({name:"Katherine"}, printReply)' \
- --root_cert ./trustedCA.pem
+$ grpcurl --proto hello-impl/src/main/protobuf/helloworld.proto \
+ -d '{"name": "Katherine" }' \
+ -plaintext 127.0.0.1:11000 \
+ helloworld.GreeterService.SayHello
{
"message": "Hi Katherine! (gRPC)"
}
```
The command above:
- 1. uses the gRPC description on `hello-impl/src/main/protobuf/helloworld.proto`,
- 1. connects to the `hello-impl` service using `https` at `localhost:11000` (trusting the CA used to build the `localhost:11000` certificate), and
- 1. sends a gRPC call `client.sayHello({name:"Katherine"},...)` (`grpcc` requires registering a callback, in this case `printReply` to send the response to the `stdout`).
+
+1. Uses the gRPC description on `hello-impl/src/main/protobuf/helloworld.proto`
+1. Connects to the `hello-impl` service at `127.0.0.1:11000` using plaintext over `http`.
+1. Sends a gRPC call `helloworld.GreeterService.SayHello` with `{"name": "Katherine" }` payload.
+
+## References
+
+- [Akka gRPC](https://developer.lightbend.com/docs/akka-grpc/current/)
+- [Play gRPC](https://developer.lightbend.com/docs/play-grpc/current/)
diff --git a/grpc-example/grpc-example-scala/hello-impl/src/main/resources/logback.xml b/grpc-example/grpc-example-scala/hello-impl/src/main/resources/logback.xml
new file mode 100644
index 00000000..1b1d8a3f
--- /dev/null
+++ b/grpc-example/grpc-example-scala/hello-impl/src/main/resources/logback.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ %date{"HH:mm:ss.SSS"} %coloredLevel %logger [%mdc] - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/grpc-example/grpc-example-scala/hello-impl/src/test/scala/com/example/hello/impl/HelloServiceNoSslSpec.scala b/grpc-example/grpc-example-scala/hello-impl/src/test/scala/com/example/hello/impl/HelloServiceNoSslSpec.scala
deleted file mode 100644
index ca9491ee..00000000
--- a/grpc-example/grpc-example-scala/hello-impl/src/test/scala/com/example/hello/impl/HelloServiceNoSslSpec.scala
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.example.hello.impl
-
-import akka.actor.ActorSystem
-import akka.grpc.GrpcClientSettings
-import com.example.hello.api._
-import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
-import com.lightbend.lagom.scaladsl.testkit.ServiceTest
-import example.myapp.helloworld.grpc.{GreeterServiceClient, HelloRequest}
-import org.scalatest.BeforeAndAfterAll
-import org.scalatest.matchers.should.Matchers
-import org.scalatest.wordspec.AsyncWordSpec
-
-/**
- * Illustrate deliberate use of the gRPC client without TLS.
- */
-class HelloServiceNoSslSpec 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 = {
- val httpPort = server.playServer.httpPort.get
-
- val settings = GrpcClientSettings
- .connectToServiceAt("127.0.0.1", httpPort)(server.actorSystem)
- .withTls(false)
-
- GreeterServiceClient(settings)
- }
-
-
- override protected 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/grpc-example/grpc-example-scala/hello-impl/src/test/scala/com/example/hello/impl/HelloServiceSpec.scala b/grpc-example/grpc-example-scala/hello-impl/src/test/scala/com/example/hello/impl/HelloServiceSpec.scala
index 11550872..86c114b2 100644
--- a/grpc-example/grpc-example-scala/hello-impl/src/test/scala/com/example/hello/impl/HelloServiceSpec.scala
+++ b/grpc-example/grpc-example-scala/hello-impl/src/test/scala/com/example/hello/impl/HelloServiceSpec.scala
@@ -1,30 +1,35 @@
package com.example.hello.impl
import akka.actor.ActorSystem
+import akka.grpc.GrpcClientSettings
import com.example.hello.api._
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import com.lightbend.lagom.scaladsl.testkit.grpc.AkkaGrpcClientHelpers
-import example.myapp.helloworld.grpc.{ GreeterServiceClient, HelloRequest }
+import example.myapp.helloworld.grpc.{GreeterServiceClient, HelloRequest}
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
- }
+ private val server: ServiceTest.TestServer[HelloApplication with LocalServiceLocator] =
+ ServiceTest.startServer(ServiceTest.defaultSetup) { 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,
- )
+ val grpcClient: GreeterServiceClient = {
+ val httpPort = server.playServer.httpPort.get
+
+ val settings = GrpcClientSettings
+ .connectToServiceAt("127.0.0.1", httpPort)(server.actorSystem)
+ .withTls(false)
+
+ GreeterServiceClient(settings)
+ }
override protected def afterAll(): Unit = {
diff --git a/grpc-example/grpc-example-scala/hello-proxy-impl/src/main/resources/logback.xml b/grpc-example/grpc-example-scala/hello-proxy-impl/src/main/resources/logback.xml
index f4d2d2cb..1b1d8a3f 100644
--- a/grpc-example/grpc-example-scala/hello-proxy-impl/src/main/resources/logback.xml
+++ b/grpc-example/grpc-example-scala/hello-proxy-impl/src/main/resources/logback.xml
@@ -1,13 +1,23 @@
+
+
-
- %d{HH:mm:ss.SSS} XXX [%thread] %-5level %logger{36} - %msg%n
+ %date{"HH:mm:ss.SSS"} %coloredLevel %logger [%mdc] - %msg%n
+
+
+
+
+
+
+
+
+
+
diff --git a/grpc-example/grpc-example-scala/ssl-lagom b/grpc-example/grpc-example-scala/ssl-lagom
deleted file mode 100755
index 626bab6f..00000000
--- a/grpc-example/grpc-example-scala/ssl-lagom
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-## Based on https://github.com/playframework/play-scala-tls-example/edit/2.5.x/play
-## All JVM_XXX options are removed because Lagom does a different handling of SSL
-## than Play. Only the ALPN Agent setup is relevant for Lagom.
-
-# ssl-play requires an ALPN Agent. This is downdloaded and stored in the target
-# folder of each subproject that needs ALPN enabled.
-# This snippet detects when the ALPN agent hasn't been downloaded yet and runs
-# `sbt stage` to obtain it.
-export AGENT_TEST=$(pwd)/$(find . -name 'jetty-alpn-agent-*.jar')
-export NUM_AGENTS_FOUND=$(echo $AGENT_TEST| grep target | wc -l)
-
-if [ $NUM_AGENTS_FOUND -eq "0" ]; then
- sbt stage;
-fi
-
-# Start `sbt` with the JVM_OPTIONS and the ALPN agent
-export AGENT=$(pwd)/$(find . -name 'jetty-alpn-agent-*.jar' | head -1)
-echo "Detected ALPN Agent: $AGENT "
-export SBT_OPTS="$SBT_OPTS -javaagent:$AGENT"
-# Run Play
-sbt $JVM_OPTIONS $*;