问uarkus is a “next-generation Kubernetes native Java framework” which is available as open source. Quarkus promises fast boot times and low memory usages. This makes Quarkus a perfect fit for Java workloads running as microservices on Kubernetes as well as Java workloads running as serverless functions.
Read the article Why Quarkus to learn how Quarkus works. In a nutshell Quarkus compiles Java source code in native binaries via GraalVM. The Quarkus framework helps developers to easily build applications that can leverage the GraalVM benefits.
如今,大多数开发人员都使用JavaScript / Node.js来构建无服务器功能。 原因之一是Node.js应用程序通常(用于?)启动速度更快,消耗的内存更少。 由于您通常需要为云中的内存和时间付费,因此Node.js经常可以为您节省金钱并提供更好的体验。
Today I looked briefly into how to use Quarkus to build lightweight and fast Docker images which can be run as serverless functions on Apache OpenWhisk based platforms like IBM Cloud Functions. One of the great features of OpenWhisk is that you can use Docker to develop functions.
I’ve put together a little sample on GitHub.
Here is how you can try Quarkus on IBM Cloud Functions. All you need is a free IBM Cloud lite account and the ibmcloud CLI.
首先下载代码:
$ git clone https://github.com/nheidloff/openwhisk-quarkus-starter.git
$ cd openwhisk-quarkus-starter
Before the actual Docker image is built, the native binary is created. Follow the instructions on the Quarkus web site how to set up GraalVM, a Java JDK and Maven.
然后构建映像(用您的Docker名称替换'nheidloff')。
$ mvn package -Pnative -Dnative-image.docker-build=true
$ docker build -t nheidloff/quarkus-serverless:1 .
$ docker push nheidloff/quarkus-serverless:1
为了在本地调用该函数,请运行以下命令:
$ docker run -i --rm -p 8080:8080 nheidloff/quarkus-serverless
$ curl --request POST \
--url [http://localhost:8080/run](http://localhost:8080/run) \
--header 'Content-Type: application/json' \
--data '{"value":{"name":"Niklas"}}'
为了更改示例功能的实现,请使用您喜欢的Java IDE或文本编辑器。 当您运行以下命令时,每次保存文件时,应用程序都会自动更新:
$ mvn compile quarkus:dev
可以使用以下命令在IBM Cloud上创建OpenWhisk函数:
$ ibmcloud login
$ ibmcloud fn action create echo-quarkus --docker nheidloff/quarkus-serverless:1 -m 128
注意:部署的Quarkus功能仅占用128 MB内存。 我认为这真是太神奇了。
调用命令的最简单方法是通过ibmcloud CLI:
$ ibmcloud fn action invoke --blocking echo-quarkus --param name Niklas
接下来,我想更多地看一下Quarkus函数的速度。