Skip to content

Latest commit

 

History

History
198 lines (137 loc) · 4.95 KB

README.adoc

File metadata and controls

198 lines (137 loc) · 4.95 KB

Quarkus Brings Serverless to Java Developers Demo

This is the source codes for the Quarkus(RHBQ) with Serverless Demo.

1. Run a RESTful API application via Quarkus Development Mode

Copy and paste the following commands in Terminal:

mvn quarkus:dev

You will see that Quarkus is ruuning as below:

__  ____  __  _____   ___  __ ____  ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2020-06-30 10:39:08,053 INFO  [io.quarkus] (main) quarkus-serverless 1.0-SNAPSHOT (powered by Quarkus xx.xx.xx) started in 0.936s. Listening on: http://0.0.0.0:8080
2020-06-30 10:39:08,056 INFO  [io.quarkus] (main) Profile dev activated. Live Coding activated.
2020-06-30 10:39:08,056 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy]

Access the endpoint via web browser or curl command:

curl http://localhost:8080/api/quarkus

Then you will see:

hello

2. Live Coding

Change the return code:

return "Welcome, Quarkus with Serverless!";

Then reload the web page or run the curl command again:

curl http://localhost:8080/api/quarkus

Then you will see:

Welcome, Quarkus with Serverless!

Awesome! Quarkus did rebuid, repackage and redeploy the application for YOU.

Stop the running Quarkus runtime in your local.

3. Package the application

Package the application via Thin Jar:

mvn clean package -DskipTests

Run the application to make sure if it works properly:

java -jar target/quarkus-serverless-1.0-SNAPSHOT-runner.jar

You will see the same result when you access the endpoint URL.

Package the application via Naitve Compilation:

mvn clean package -DskipTests -Pnative

Run the executable file:

target/quarkus-serverless-1.0-SNAPSHOT-runner

Fantastic! It only takes 0.594s to start up and this is the reason why you’re saying that Quarks fits in serverless application.

Note

If you need to deploy the native executable binary to Kubernetes cluster(i.e. OpenShift), you need to uncomment the following configuration in application.properties:

quarkus.native.container-runtime=docker

4. Deploy the App via Knative Service

Log in OpenShift cluster 4.3+ then select Deploy Image in Dev Console.

Copy the following container image that pre-pushed based Quakrus native executable binary:

danielon30/quarkus-serverless:latest

You wil see that Quarkus application is up in 60 secs. When you go to the logs in Pod, you will see 10~15 millisecs to start Quarkus.

5. Deploy the app to Azure Function

Let’s go back to your IDE and open pom.xml to uncomment the following dependency:

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-funqy-http</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-azure-functions-http</artifactId>
    </dependency>

And comment resteay dependency and instead, we will use funqy extension:

    <!-- <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency> -->

Add root path in application.properties:

quarkus.http.root-path=/api

Lastly, replace GreetingResource.java with the following codes to use *@Funq@ instead RestEasy functions:

package com.redhat.serverless.quickstart;

import io.quarkus.funqy.Funq;

public class GreetingResource {

    @Funq
    public String hello() {
        return "Welcome, Quarkus with Serverless!";
    }
}

Make sure to login Azure Cloud with your own credential:

az login

Rebuild and deploy it to Azure Cloud:

mvn clean install -DskipTests azure-functions:deploy

Once you login Azure Portal then you will see quarkus_function in Function App on the left menu.

The endpoint should be ended with /api/hello