From 2c2eab1bb7d8f13a582e31a7cc209cc7c652e065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 8 Sep 2020 14:50:57 +0200 Subject: [PATCH] Google Cloud Functions Funqy HTTP --- .../asciidoc/funqy-gcp-functions-http.adoc | 55 +++++++++++++++++++ .../src/main/asciidoc/gcp-functions-http.adoc | 27 +++++++-- .../google-cloud-functions-http/README.md | 7 +-- .../google-cloud-functions-http/pom.xml | 17 ++++++ .../it/gcp/functions/http/GreetingFunqy.java | 17 ++++++ .../it/gcp/functions/http/GreetingTest.java | 2 + 6 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 docs/src/main/asciidoc/funqy-gcp-functions-http.adoc create mode 100644 integration-tests/google-cloud-functions-http/src/main/java/io/quarkus/it/gcp/functions/http/GreetingFunqy.java diff --git a/docs/src/main/asciidoc/funqy-gcp-functions-http.adoc b/docs/src/main/asciidoc/funqy-gcp-functions-http.adoc new file mode 100644 index 0000000000000..132cf6b8a99b9 --- /dev/null +++ b/docs/src/main/asciidoc/funqy-gcp-functions-http.adoc @@ -0,0 +1,55 @@ +//// +This guide is maintained in the main Quarkus repository +and pull requests should be submitted there: +https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc +//// += Quarkus - Funqy HTTP Binding with Google Cloud Functions +:extension-status: experimental + +include::./attributes.adoc[] + +If you want to allow HTTP clients to invoke your Funqy functions on Google Cloud Functions, Quarkus allows you to expose multiple +Funqy functions through HTTP deployed as one Google Cloud Function. This approach does add overhead over the +regular Funqy Google Cloud Function integration. + +include::./status-include.adoc[] + +Follow the link:gcp-functions-http[Google Cloud Functions Http Guide]. It walks through using a variety of HTTP +frameworks on Google Cloud Functions, including Funqy. + +WARNING: The Funqy HTTP + Google Cloud Functions binding is not a replacement for REST over HTTP. Because Funqy +needs to be portable across a lot of different protocols and function providers its HTTP binding +is very minimalistic and you will lose REST features like linking and the ability to leverage +HTTP features like cache-control and conditional GETs. You may want to consider using Quarkus's +JAX-RS, Spring MVC, or Vert.x Web Reactive Route link:gcp-functions-http[support] instead. They also work with Quarkus and Google Cloud Functions. + +== An additional Quickstart + +Beyond generating a Google Cloud Functions project that is covered in the link:gcp-functions-http[Google Cloud Functions HTTP Guide], +there's also a quickstart for running Funqy HTTP on Google Cloud Functions. + +Clone the Git repository: `git clone {quickstarts-clone-url}`, or download an {quickstarts-archive-url}[archive]. + +The solution is located in the `funqy-google-cloud-functions-http-quickstart` {quickstarts-tree-url}/funqy-quickstarts/funqy-google-cloud-functions-http-quickstart[directory]. + +== The Code + +There is nothing special about the code and more importantly nothing Google Cloud specific. Funqy functions can be deployed to many different +environments and Google Cloud Functions is one of them. The Java code is actually the same exact code as the {quickstarts-tree-url}/funqy-quickstarts/funqy-http-quickstart[funqy-http-quickstart]. + +== Getting Started + +The steps to get this quickstart running are exactly the same as defined in the link:gcp-functions-http[Google Cloud Functions HTTP Guide]. +This differences are that you are running from a quickstart and the Maven dependencies are slightly different. + +[source, xml] +---- + + io.quarkus + quarkus-funqy-http + + + io.quarkus + quarkus-google-cloud-functions-http + +---- diff --git a/docs/src/main/asciidoc/gcp-functions-http.adoc b/docs/src/main/asciidoc/gcp-functions-http.adoc index 922eb2af1544b..c47d7fe60ffd5 100644 --- a/docs/src/main/asciidoc/gcp-functions-http.adoc +++ b/docs/src/main/asciidoc/gcp-functions-http.adoc @@ -9,9 +9,9 @@ https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc include::./attributes.adoc[] The `quarkus-google-cloud-functions-http` extension allows you to write microservices with RESTEasy (JAX-RS), -Undertow (Servlet) or Vert.x Web, and make these microservices deployable to the Google Cloud Functions runtime. +Undertow (Servlet), Vert.x Web, or link:funqy-http[Funqy HTTP], and make these microservices deployable to the Google Cloud Functions runtime. -One Google Cloud Functions deployment can represent any number of JAX-RS, Servlet, or Vert.x Web endpoints. +One Google Cloud Functions deployment can represent any number of JAX-RS, Servlet, Vert.x Web, or link:funqy-http[Funqy HTTP] endpoints. As the Google Cloud Function Java engine is a new Beta feature of Google Cloud, this extension is flagged as experimental. @@ -30,7 +30,7 @@ To complete this guide, you need: == Solution This guide walks you through generating a sample project followed by creating three HTTP endpoints -written with JAX-RS APIs, Servlet APIs or Vert.x Web APIs. Once built, you will be able to deploy +written with JAX-RS APIs, Servlet APIs, Vert.x Web, or link:funqy-http[Funqy HTTP] APIs. Once built, you will be able to deploy the project to Google Cloud. If you don't want to follow all these steps, you can go right to the completed example. @@ -51,7 +51,7 @@ mvn io.quarkus:quarkus-maven-plugin:{quarkus-version}:create \ -DprojectArtifactId=google-cloud-functions-http \ -DclassName="org.acme.quickstart.GreetingResource" \ -Dpath="/hello" \ - -Dextensions="google-cloud-functions-http,resteasy-json,undertow,vertx-web" + -Dextensions="google-cloud-functions-http,resteasy-json,undertow,vertx-web,funqy-http" ---- == Login to Google Cloud @@ -72,8 +72,8 @@ gcloud components install beta == Creating the endpoints -For this example project, we will create three endpoints, one for RESTEasy (JAX-RS), one for Undertow (Servlet) -and one for Vert.x Web (reactive routes). +For this example project, we will create four endpoints, one for RESTEasy (JAX-RS), one for Undertow (Servlet), +one for Vert.x Web (reactive routes) and one for link:funqy-http[Funqy HTTP]. If you don't need endpoints of each type, you can remove the corresponding extensions from your `pom.xml`. @@ -146,6 +146,20 @@ public class GreetingRoutes { } ---- +=== The Funqy HTTP endpoint + +[source,java] +---- +import io.quarkus.funqy.Funq; + +public class GreetingFunqy { + @Funq + public String funqy() { + return "Make it funqy"; + } +} +---- + == Build and Deploy to Google Cloud NOTE: Quarkus forces a packaging of type `uber-jar` for your function as Google Cloud Function deployment requires a single JAR. @@ -185,6 +199,7 @@ You can then call your endpoints via: - For JAX-RS: {httpsTrigger.url}/hello - For servlet: {httpsTrigger.url}/servlet/hello - For Vert.x Web: {httpsTrigger.url}/vertx/hello +- For Funqy: {httpsTrigger.url}/funqy == Testing locally diff --git a/integration-tests/google-cloud-functions-http/README.md b/integration-tests/google-cloud-functions-http/README.md index 3b97ce68bd9ca..1b87f5bd2e5a6 100644 --- a/integration-tests/google-cloud-functions-http/README.md +++ b/integration-tests/google-cloud-functions-http/README.md @@ -10,19 +10,17 @@ First, you need to log in to Google Cloud: gcloud auth login ``` -Then you need to use Maven to build the artifact and put it in a directory where it will be the only file. +Then you need to use Maven to build the artifact, the build will automatically copy it inside `target/deployment`. ```shell script -mkdir deployment mvn clean package -cp target/quarkus-integration-test-google-cloud-functions-http-999-SNAPSHOT-runner.jar deployment/ ``` Finally, you need to use `gcloud` to deploy the function to Google Cloud ```shell script gcloud beta functions deploy quarkus-example-http --entry-point=io.quarkus.gcp.functions.http.QuarkusHttpFunction \ - --runtime=java11 --trigger-http --source=deployment + --runtime=java11 --trigger-http --source=target/deployment ``` ## Testing the endpoints @@ -35,4 +33,5 @@ You can issue the following `curl` commands to test it: curl -v {httpsTrigger.url}/hello curl -v {httpsTrigger.url}/servlet/hello curl -v {httpsTrigger.url}/vertx/hello +curl -v {httpsTrigger.url}/funqy ``` diff --git a/integration-tests/google-cloud-functions-http/pom.xml b/integration-tests/google-cloud-functions-http/pom.xml index 53dd380f4cec9..a7b3254d0d3ea 100644 --- a/integration-tests/google-cloud-functions-http/pom.xml +++ b/integration-tests/google-cloud-functions-http/pom.xml @@ -25,6 +25,10 @@ io.quarkus quarkus-vertx-web + + io.quarkus + quarkus-funqy-http + io.quarkus quarkus-google-cloud-functions-http @@ -95,6 +99,19 @@ + + io.quarkus + quarkus-funqy-http-deployment + ${project.version} + pom + test + + + * + * + + + diff --git a/integration-tests/google-cloud-functions-http/src/main/java/io/quarkus/it/gcp/functions/http/GreetingFunqy.java b/integration-tests/google-cloud-functions-http/src/main/java/io/quarkus/it/gcp/functions/http/GreetingFunqy.java new file mode 100644 index 0000000000000..4926fb497c9f6 --- /dev/null +++ b/integration-tests/google-cloud-functions-http/src/main/java/io/quarkus/it/gcp/functions/http/GreetingFunqy.java @@ -0,0 +1,17 @@ +package io.quarkus.it.gcp.functions.http; + +import io.quarkus.funqy.Funq; +import io.smallrye.mutiny.Uni; + +public class GreetingFunqy { + + @Funq + public String funqy() { + return "Make it funqy"; + } + + @Funq + public Uni funqyAsync() { + return Uni.createFrom().item(() -> "Make it funqy asynchronously"); + } +} diff --git a/integration-tests/google-cloud-functions-http/src/test/java/io/quarkus/it/gcp/functions/http/GreetingTest.java b/integration-tests/google-cloud-functions-http/src/test/java/io/quarkus/it/gcp/functions/http/GreetingTest.java index 75690af738183..ede7a0a3268a5 100644 --- a/integration-tests/google-cloud-functions-http/src/test/java/io/quarkus/it/gcp/functions/http/GreetingTest.java +++ b/integration-tests/google-cloud-functions-http/src/test/java/io/quarkus/it/gcp/functions/http/GreetingTest.java @@ -16,5 +16,7 @@ public void testGreeting() { when().get("/servlet/hello").then().statusCode(200); when().get("/vertx/hello").then().statusCode(200); + + when().get("/funqy").then().statusCode(200); } }