Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Cloud Functions Funqy HTTP #11880

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions docs/src/main/asciidoc/funqy-gcp-functions-http.adoc
Original file line number Diff line number Diff line change
@@ -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]
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-funqy-http</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-google-cloud-functions-http</artifactId>
</dependency>
----
27 changes: 21 additions & 6 deletions docs/src/main/asciidoc/gcp-functions-http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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`.

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions integration-tests/google-cloud-functions-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
17 changes: 17 additions & 0 deletions integration-tests/google-cloud-functions-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-web</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-funqy-http</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-google-cloud-functions-http</artifactId>
Expand Down Expand Up @@ -95,6 +99,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-funqy-http-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> funqyAsync() {
return Uni.createFrom().item(() -> "Make it funqy asynchronously");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}