BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Nimbus: New Framework for Building Java Serverless Applications

Nimbus: New Framework for Building Java Serverless Applications

Leia em Português

This item in japanese

Bookmarks

The Nimbus framework is a Java framework that aims to ease the development, testing, and deployment of Function-as-a-Service (FaaS) applications in the cloud. Nimbus provides a cloud-agnostic, common interface for interacting with cloud providers’ serverless functionality.

In a recent Medium post, Thomas Allerton, the author of the framework, states that "[f]or newcomers looking to make simple applications, there can be a very steep learning curve, having to learn the cloud lingo when all you really want is to deploy a few HTTP endpoints with somewhere to store the data." As an alternative to learning cloud configuration syntax and FaaS APIs, Nimbus makes use of annotations to support several common backend operations that are used when building function-based applications.

Allerton argues that the main advantage of Nimbus is not having to create a configuration file in order to declare cloud resources (like AWS SAM or the Serverless framework). In turn, developers "are much less prone to making mistakes by forgetting parameters". Additionally, Nimbus does compile-time checking of deployment parameters with the goal of detecting mistakes as early as possible.

To get a better feel for how the framework is used, consider the following example which utilizes the @HttpServerlessFunction annotation to create a very simple REST API.

public class RestApi {

    @HttpServerlessFunction(path="getOsTypes", method= HttpMethod.GET)
    public List<String> currentOsTypes() {
           return Arrays.asList(new String[] {"Windows", "Mac", "Linux"});
    }
}

Nimbus also supports other operations:

In addition to support for different types of operations, Nimbus also comes with support for several types of datastores should a serverless application require some sort of persistence. The following example shows setting up a document store using the @DocumentStore annotation.

@DocumentStore
public class OsPreference {

    @Key
    private String id;

    @Attribute
    private String preference;

    public OsPreference(String id, String preference) {
           this.id = id;
           this.preference = preference;
    }
    
    // ...
    // getters & setters
    // ...
}

With the document store setup, the DocumentStoreClient can then be used to persist data to it.

private DocumentStoreClient<OsPreference> client =
   ClientBuilder.getDocumentStoreClient(OsPreference.class);

@HttpServerlessFunction(path="setOsPreference", method= HttpMethod.POST)
@UsesDocumentStore(OsPreference.class)
public String setOsPreference(OsPreference osPreference) {
   client.put(osPreference);
   return "Success";
}

Support for additional data stores (and clients) include: relational store for storing relational data; key-value store for storing data to a key-value store; and a file store for object storage (with explicit support for static website hosting and file uploads)

Another common challenge of building serverless applications is testing. Nimbus provides explicit support for both unit and integration testing. The unit testing support adds the ability to create a local mock deployment of any of the operations listed above, which can accept requests and verify that functions are invoked correctly or that data is stored appropriately. The integration-testing support is somewhat more limited than the unit-testing support, and only supports HTTP-based tests. These tests add the ability to start a local web server which can be used to verify that requests invoke the expected function.

Currently, as part of the initial release, only AWS is supported. However, support for other cloud providers is planned.

To learn more about Nimbus, be sure to read the Getting Started guide, visit the reference documentation, or clone the source on GitHub.

Rate this Article

Adoption
Style

BT