01. 개요
02. 사전조건
- JAVA_HOME 환경변수 설정
- IntelliJ Community
- Azure Account
- Subscription
- Azure CLI for Windows
- Azure Functions Core 도구 for Windows
03. Azure Functions 프로젝트 생성
- New Project로 Azure Functions를 찾고, HttpTrigger를 선택합니다.
- Application을 정의하고 Next를 선택합니다.
- Project이름과, Project Location을 정의 합니다.
- Project가 생성되면 다음과 같이 보여집니다.
04. Azure Functions 코드 살펴보기
package org.example.functions; import com.microsoft.azure.functions.ExecutionContext; import com.microsoft.azure.functions.HttpMethod; import com.microsoft.azure.functions.HttpRequestMessage; import com.microsoft.azure.functions.HttpResponseMessage; import com.microsoft.azure.functions.HttpStatus; import com.microsoft.azure.functions.annotation.AuthorizationLevel; import com.microsoft.azure.functions.annotation.FunctionName; import com.microsoft.azure.functions.annotation.HttpTrigger; import java.util.Optional; /** * Azure Functions with HTTP Trigger. */ public class HttpTriggerFunction { /** * This function listens at endpoint "/api/HttpExample". Two ways to invoke it using "curl" command in bash: * 1. curl -d "HTTP Body" {your host}/api/HttpExample * 2. curl "{your host}/api/HttpExample?name=HTTP%20Query" */ @FunctionName("HttpExample") public HttpResponseMessage run( @HttpTrigger( name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, final ExecutionContext context) { context.getLogger().info("Java HTTP trigger processed a request."); // Parse query parameter final String query = request.getQueryParameters().get("name"); final String name = request.getBody().orElse(query); if (name == null) { return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build(); } else { return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build(); } } }
05. Azure Functions 앱 실행
- Maven명령으로 Azure-functions를 실행 합니다.
C:\workspace\azure-function-examples>mvn clean package azure-functions:run [INFO] Scanning for projects... [INFO] [INFO] ----------------< com.example:azure-function-examples >----------------- [INFO] Building Azure Java Functions 1.0.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- ~~~~~~~~~~~~~~~~~~~~~ 중략 ~~~~~~~~~~~~~~~~~~~~~~~~ HttpExample: [GET,POST] http://localhost:7071/api/HttpExample
- Browser에서 결과를 확인 합니다.
06. Deploy Azure Functions