Quarkus - Azure Functions (Serverless) with Resteasy, Undertow, or Vert.x Web

    One azure function deployment can represent any number of JAX-RS, servlet, or Vert.x Web endpoints.

    To complete this guide, you need:

    • less than 15 minutes

    • JDK 1.8 (Azure requires JDK 1.8)

    • Apache Maven 3.5.3+

    • An Azure Account. Free accounts work.

    Solution

    This guide walks you through running a Maven Archetype to generate a sample project that contains three http endpointswritten with JAX-RS APIs, Servlet APIs, and Vert.x Web APIs. After building, you will then be able to deployto Azure.

    Create the azure maven project for your Quarkus application using our Maven Archetype.

    Running this command will run maven in interactive mode and it will ask you to fill in some build properties:

    • artifactId - The maven artifactId of this generated project. Type in quarkus-demo

    • version - Version of this generated project.

    • package - defaults to groupId

    • appName - Use the default value. This is the application name in Azure. It must be a unique subdomain name under *.azurewebsites.net. Otherwise deploying to Azure will fail.

    • appRegion - Defaults to . Dependent on your azure region.

    • function - Use the default which is quarkus. Name of your azure function. Can be anything you want.

    The values above are defined as properties in the generated pom.xml file.

    Login to Azure

    If you don’t login to Azure you won’t be able to deploy.

    The pom.xml you generated in the previous step pulls in the azure-functions-maven-plugin. Running maven installgenerates config files and a staging directory required by the azure-functions-maven-plugin. Here’show to execute it.

    If deployment is a success, the azure plugin will tell you the base URL to access your function.

    i.e.

    The URL to access the service would be

    https://{appName}.azurewebsites.net/api/hellohttps://{appName}.azurewebsites.net/api/vertx/hello

    Extension maven dependencies

    The sample project includes the Resteasy, Undertow, and Vert.x Web extensions. If you are only using one of thoseAPIs (i.e. jax-rs only), respectively remove the maven dependency quarkus-resteasy, quarkus-undertow, and/orquarkus-vertx-web.

    You must include the extension as this is a generic bridge between the Azure Functionsruntime and the HTTP framework you are writing your microservices in.

    Templates for Azure Functions deployment descriptors (host.json, function.json) are withinthe azure-config directory. Edit them as you need to. Rerun the build when you are ready.

    NOTE: If you change the function.json path attribute or if you add a routePrefix,your jax-rs endpoints won’t route correctly. See Configuring Root Paths for more information.

    Configuring Root Paths

    The default route prefix for an Azure Function is /api. All of your JAX-RS, Servlet, and Vert.x Web endpoints mustexplicitly take this into account.

    If you modify the path or add a routePrefix within the azure-config/function.jsondeployment descriptor, your code must also reflect any prefixes you specify for your path.