Quarkus的轻量级无服务器Java函数

问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函数的速度。

from: https://dev.to//nheidloff/lightweight-serverless-java-functions-with-quarkus-4ejd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值