Azure Functions (Serverless) with RESTEasy Reactive, Undertow, or Reactive Routes
previewThe quarkus-azure-functions-http extension allows you to write microservices with RESTEasy Reactive (JAX-RS),
Undertow (servlet), Reactive Routes, or Funqy HTTP and make these microservices deployable to the Azure Functions runtime.
Un despliegue de funciones azure puede representar cualquier número de endpoints JAX-RS, servlet, Reactive Routes o Funqy HTTP.
|
This technology is considered preview. In preview, backward compatibility and presence in the ecosystem is not guaranteed. Specific improvements might require changing configuration or APIs, and plans to become stable are under way. Feedback is welcome on our mailing list or as issues in our GitHub issue tracker. For a full list of possible statuses, check our FAQ entry. |
| Por el momento, sólo se admiten los tipos de medios basados en texto, ya que Azure Functions HTTP Trigger para Java no admite un formato binario |
Requisitos previos
To complete this guide, you need:
-
Roughly 15 minutes
-
An IDE
-
JDK 11+ installed with
JAVA_HOMEconfigured appropriately -
Apache Maven 3.8.6
-
Optionally the Quarkus CLI if you want to use it
-
Optionally Mandrel or GraalVM installed and configured appropriately if you want to build a native executable (or Docker if you use a native container build)
-
Una cuenta de Azure. Las cuentas gratuitas funcionan.
Solución
This guide walks you through running a Maven Archetype to generate a sample project that contains three http endpoints written with JAX-RS APIs, Servlet APIs, Reactive Routes, or Funqy HTTP APIs. After building, you will then be able to deploy to Azure.
Creación del proyecto de Maven
Create the Azure Maven project for your Quarkus application using our Maven Archetype.
mvn archetype:generate \
-DarchetypeGroupId=io.quarkus \
-DarchetypeArtifactId=quarkus-azure-functions-http-archetype \
-DarchetypeVersion=2.16.12.Final
Running this command will run maven in interactive mode and it will ask you to fill in some build properties:
-
groupId- El groupId de maven de este proyecto generado. Escriba enorg.acme. -
artifactId- The maven artifactId of this generated project. Type inquarkus-demo -
version- Version of this generated project. -
package- defaults togroupId -
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- Por defecto,westus. Depende de su región azure. -
function- Utilice el valor por defecto que esquarkus. Nombre de su función azure. Puede ser cualquier cosa que desee. -
resourceGroup- Utilice el valor por defecto. Sin embargo, cualquier valor es válido.
The values above are defined as properties in the generated pom.xml file.
Build and Deploy to Azure
The pom.xml you generated in the previous step pulls in the azure-functions-maven-plugin. Running maven install
generates config files and a staging directory required by the azure-functions-maven-plugin. Here’s
how to execute it.
./mvnw clean install azure-functions:deploy
If you haven’t already created your function up at azure, then build an uber-jar, package it, create the function at Azure, and deploy it.
If deployment is a success, the azure plugin will tell you the base URL to access your function.
i.e.
Successfully deployed the artifact to https://quarkus-demo-123451234.azurewebsites.net
The URL to access the service would be
Extension maven dependencies
The sample project includes the RESTEasy Reactive, Undertow, Reactive Routes, Funqy HTTP extensions. If you are only using one of those
APIs (i.e. jax-rs only), respectively remove the maven dependency quarkus-resteasy-reactive, quarkus-undertow, quarkus-funqy-http, and/or
quarkus-reactive-routes.
You must include the quarkus-azure-functions-http extension as this is a generic bridge between the Azure Functions
runtime and the HTTP framework you are writing your microservices in.
Descriptores de despliegue de Azure
Templates for Azure Functions deployment descriptors (host.json, function.json) are within
the 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 Configuración de las rutas de acceso a la raíz for more information.
Configuración de las rutas de acceso a la raíz
The default route prefix for an Azure Function is /api. All of your JAX-RS, Servlet, Reactive Routes, and Funqy HTTP endpoints must
explicitly take this into account. In the generated project this is handled by the
quarkus.http.root-path switch in application.properties
If you modify the path or add a routePrefix within the azure-config/function.json
deployment descriptor, your code or configuration must also reflect any prefixes you specify for your path.