Skip to content

shrivastavarashmi/SampleSpringBatchTimerTrigger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Deploy Spring Boot Batch Application on Azure Function using Spring Cloud Function

Spring Cloud Function enables Spring boot features on serverless providers, and includes adapters for Azure Functions. It provides out of the box mechanism to create a link between Spring Cloud Function and Azure Functions.

This quickstart shows you how to deploy Spring Boot Batch application on Azure Function. When you're finished, you can continue to manage the application via the Azure CLI or switch to using the Azure Portal.

What will you experience

You will:

  • Build existing Spring Boot Batch application.This repository consists of sample application to showcase a way to deploy Spring Boot Batch application on Azure Function invoked by timer trigger.
  • Run the application on Azure Cloud to check the functionality
  • Provision Function App Instance
  • Deploy the application to Azure Function App
  • Verify and monitor the application

What you will need

In order to deploy a Java app to cloud, you need an Azure subscription. If you do not already have an Azure subscription, you can activate your MSDN subscriber benefits or sign up for a free Azure account.

In addition, you will need the following:

| Azure CLI version 2.17.1 or higher | Java 11 | Maven | Azure Functions Core Tools, version 3.0.13901.0 or above | Azure SQL

OR Use Azure Cloud Shell Or, you can use the Azure Cloud Shell. Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use the Bash with Cloud Shell to work with Azure services. You can use the Cloud Shell pre-installed commands to run the code in this README without having to install anything on your local environment. To start Azure Cloud Shell: go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser.

To run the code in this article in Azure Cloud Shell:

Start Cloud Shell.

Select the Copy button on a code block to copy the code.

Paste the code into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux or by selecting Cmd+Shift+V on macOS.

Select Enter to run the code.

Clone and build the repo

  • Create a new folder and clone the sample app repository to your Azure Cloud account

    mkdir source-code
    git clone https://github.com/shrivastavarashmi/SampleSpringBatchTimerTrigger.git

  • Change directory to the project

    cd SampleSpringBatchTimerTrigger

  • Configure the project to use resource group and function app name as per your wish (it should be unique across Azure)

    • Open the pom.xml file

    • Customize below properties

      • functionResourceGroup(you can use the same resource group name which you used to create Azure SQL)
      • functionAppName
      • functionAppRegion
  • Configure Azure SQL Server details with Azure SQL Server details

    • Open the application.properties
    • Customize the spring.datasource.url(jdbc url), spring.datasource.username and spring.datasource.password properties with already created Azure SQL server instance details.
  • Change directory and build the project

    cd SampleSpringBatchTimerTrigger
    mvn clean package -DskipTests -Denv=cloud

This will take a few minutes.

Run the application

  • Configure Storage account key with any of your Storage Account's connection string details

    • Open the local.settings.json
    • Customize the AzureWebJobsStorage property with your storage account's connection string, the format should be like "DefaultEndpointsProtocol...."
  • You would need to check exception in Azure SQL Server to allow Azure services and resources to access it.

  • Once the application is built again after these changes, you can use below command to run the project on Azure Cloud account:

    mvn azure-functions:run

Deploy the application to Azure Functions

Deploy the application to Azure Functions by using below command :

mvn azure-functions:deploy

This command will create new resource group (if not present already) as per given details in the properties setting of pom.xml, also it will create function app, application service plan, application insight and storage account and then deploy the azure function into the Function App.

Verify and monitor application

To verify if Azure function is working or not you can check below :

  • Azure function gives facility to monitor your function for each successful or failure calls from your application, you can verify it easily and in case of any failure you can check the logs. Below are the checks you can do inside your function :

    Overview :

    image

    Monitor logs :

    image

    Errors :

    image

  • Check Azure SQL database (for data inserted from sample-data.csv file to the people table ) as below :

    image

  • Check Application insight (for the logs and application map to see the call to Azure Functions ) as below :

    image

    image

Reference Links

About

A way to deploy spring boot batch application on Azure Functions invoked by a TimerTrigger

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages