0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Java の Maven で Azure Functions を試してみた

Posted at

いつもは .NET で Azure Functions を使っていますが、ふと Java だとどうやって作るのだろうと疑問に思ったので試してみました。

動作環境

bash
$ java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)

$ mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Default locale: ja_JP, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

$ func --version
4.0.5801

$ az version
{
  "azure-cli": "2.61.0",
  "azure-cli-core": "2.61.0",
  "azure-cli-telemetry": "1.1.0",
  "extensions": {}
}

検証用 Functions を作成

bash
$ mvn archetype:generate \
  -DarchetypeGroupId=com.microsoft.azure \
  -DarchetypeArtifactId=azure-functions-archetype \
  -DjavaVersion=11

途中で下記の情報を入力。

Prompt Value
groupId com.mnrsdev
artifactId mnrfjava
version 1.0-SNAPSHOT
package com.mnrsdev

Functions 作成後のファイル構成

bash
$ cd mnrfjava

$ tree
.
├── host.json
├── local.settings.json
├── pom.xml
└── src
    ├── main
    │   └── java
    │       └── com
    │           └── mnrsdev
    │               └── Function.java
    └── test
        └── java
            └── com
                └── mnrsdev
                    ├── FunctionTest.java
                    └── HttpResponseMessageMock.java

10 directories, 6 files

Functions ローカル実行

bash
$ mvn clean package

$ mvn azure-functions:run

$ curl "http://localhost:7071/api/HttpExample?name=Functions"
Hello, Functions

Azure へのデプロイ準備

pom.xmlで下記項目を自分の環境にあわせて修正。

pom.xml
<functionAppName>mnrfjava</functionAppName>

<resourceGroup>mnrfjava-rg</resourceGroup>
<appServicePlanName>mnrfjava-asp</appServicePlanName>
<region>japaneast</region>
<disableAppInsights>true</disableAppInsights>
<runtime>
    <os>linux</os>
    <javaVersion>11</javaVersion>
</runtime>

Azure へデプロイし動作確認

bash
$ mvn azure-functions:deploy

$ curl "https://mnrfjava.azurewebsites.net/api/httpexample?name=Functions"
Hello, Functions

Azure 上に作成されたリソース

azure-functions-java-mvn-01.png

後片付け

bash
$ az group delete --name mnrfjava-rg --yes

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?