vertx-lambda-runtime

Boilerplate for a native vert.x lambda

Лицензия

Лицензия

Группа

Группа

xyz.jetdrone
Идентификатор

Идентификатор

vertx.lambda
Последняя версия

Последняя версия

0.0.8
Дата

Дата

Тип

Тип

jar
Описание

Описание

vertx-lambda-runtime
Boilerplate for a native vert.x lambda
Ссылка на сайт

Ссылка на сайт

https://github.com/pmlopes/aws-lambda-native-vertx
Система контроля версий

Система контроля версий

https://github.com/pmlopes/vertx-lambda-runtime

Скачать vertx.lambda

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/xyz.jetdrone/vertx.lambda/ -->
<dependency>
    <groupId>xyz.jetdrone</groupId>
    <artifactId>vertx.lambda</artifactId>
    <version>0.0.8</version>
</dependency>
// https://jarcasting.com/artifacts/xyz.jetdrone/vertx.lambda/
implementation 'xyz.jetdrone:vertx.lambda:0.0.8'
// https://jarcasting.com/artifacts/xyz.jetdrone/vertx.lambda/
implementation ("xyz.jetdrone:vertx.lambda:0.0.8")
'xyz.jetdrone:vertx.lambda:jar:0.0.8'
<dependency org="xyz.jetdrone" name="vertx.lambda" rev="0.0.8">
  <artifact name="vertx.lambda" type="jar" />
</dependency>
@Grapes(
@Grab(group='xyz.jetdrone', module='vertx.lambda', version='0.0.8')
)
libraryDependencies += "xyz.jetdrone" % "vertx.lambda" % "0.0.8"
[xyz.jetdrone/vertx.lambda "0.0.8"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
io.vertx : vertx-core jar
io.vertx : vertx-web-client jar

provided (2)

Идентификатор библиотеки Тип Версия
com.oracle.substratevm : svm-driver jar 19.2.1
io.vertx : vertx-codegen Необязательный jar

test (2)

Идентификатор библиотеки Тип Версия
io.vertx : vertx-unit jar
junit : junit jar 4.12

Модули Проекта

Данный проект не имеет модулей.

vertx lambda

Run native Lambda's with Vert.x

Disclaimer - This project should be considered a POC and has not been tested or verified for production use. If you decided to run this on production systems you do so at your own risk.

Building this Runtime

This runtime should give you all the boilerplate code for:

  • AWS Lambda
  • Knative
  • OpenFaaS

Compile the Runtime Classes

$ mvn package

Writing your lambda

Create a project and add the dependency:

<dependency>
  <groupId>xyz.jetdrone</groupId>
  <artifactId>vertx.lambda</artifactId>
  <version>LATEST</version>
</dependency>

Create a lambda as:

package com.example;

import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import xyz.jetdrone.vertx.lambda.Lambda;

public class MyLambda implements Lambda<Buffer> {
  @Override
  public void handle(Message<Buffer> event) {
    System.out.println("HEADERS: " + event.headers());
    System.out.println("BODY: " + event.body());

    // Here your business logic...

    event.reply("OK");
  }
}

And register your class in the service loader src/main/resources/META-INF/services/xyz.jetdrone.vertx.lambda.Lambda:

# List all available Lambdas here
com.example.knativelambda.MyLambda

Build

AWS Lambda

In your pom.xml add the plugins:

<build>
  <plugins>
    <plugin>
      <groupId>com.oracle.substratevm</groupId>
      <artifactId>native-image-maven-plugin</artifactId>
      <version>${graal.version}</version>
      <executions>
        <execution>
          <goals>
            <goal>native-image</goal>
          </goals>
          <phase>package</phase>
        </execution>
      </executions>
      <configuration>
        <mainClass>xyz.jetdrone.vertx.lambda.knative.Bootstrap</mainClass>
        <imageName>bootstrap</imageName>
        <buildArgs>--report-unsupported-elements-at-runtime --allow-incomplete-classpath --no-server</buildArgs>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>3.1.1</version>
      <dependencies>
        <dependency>
          <groupId>xyz.jetdrone</groupId>
          <artifactId>vertx.lambda</artifactId>
          <version>LATEST</version>
        </dependency>
      </dependencies>
      <configuration>
        <descriptorRefs>
          <descriptorRef>aws-function</descriptorRef>
        </descriptorRefs>
      </configuration>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

The first plugin will compile your code to a native-image and the second will zip your function as required by AWS.

Knative

In your pom.xml add the plugins:

<build>
  <plugins>
    <plugin>
      <groupId>com.oracle.substratevm</groupId>
      <artifactId>native-image-maven-plugin</artifactId>
      <version>${graal.version}</version>
      <executions>
        <execution>
          <goals>
            <goal>native-image</goal>
          </goals>
          <phase>package</phase>
        </execution>
      </executions>
      <configuration>
        <mainClass>xyz.jetdrone.vertx.lambda.knative.Bootstrap</mainClass>
        <imageName>bootstrap</imageName>
        <buildArgs>--report-unsupported-elements-at-runtime --allow-incomplete-classpath --no-server</buildArgs>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>3.1.1</version>
      <executions>
        <execution>
          <id>unpack</id>
          <phase>package</phase>
          <goals>
            <goal>unpack</goal>
          </goals>
          <configuration>
            <artifactItems>
              <artifactItem>
                <groupId>xyz.jetdrone</groupId>
                <artifactId>vertx.lambda</artifactId>
                <version>LATEST</version>
                <type>jar</type>
                <overWrite>false</overWrite>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <includes>**/knative/*</includes>
              </artifactItem>
            </artifactItems>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

The first plugin will compile your code to a native-image and the second will unpack a default service.yaml to be used to deploy your lambda.

OpenFaaS

In your pom.xml add the plugin:

<build>
  <plugins>
    <plugin>
      <groupId>com.oracle.substratevm</groupId>
      <artifactId>native-image-maven-plugin</artifactId>
      <version>${graal.version}</version>
      <executions>
        <execution>
          <goals>
            <goal>native-image</goal>
          </goals>
          <phase>package</phase>
        </execution>
      </executions>
      <configuration>
        <mainClass>xyz.jetdrone.vertx.lambda.knative.Bootstrap</mainClass>
        <imageName>bootstrap</imageName>
        <buildArgs>--report-unsupported-elements-at-runtime --allow-incomplete-classpath --no-server</buildArgs>
      </configuration>
    </plugin>
  </plugins>
</build>

The plugin will compile your code to a native-image.

Next steps

Lambdas are exposed to vert.x event bus, however for knative and openFaaS you might need to map the functions to URLs too. In this case you can override the method alias:

public class MyLambda implements Lambda<Buffer> {
  @Override
  public String alias() {
    return "/";
  }
}

In this case the mapping is not base on the fully qualified class name, but on the given alias.

Finally

Deploy and profit!

Версии библиотеки

Версия
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3