Coder Social home page Coder Social logo

quarkus-knative-demo's Introduction

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

quarkus-knative-demo's People

Contributors

danieloh30 avatar pkstaz avatar rbaumgar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.