Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to migrate and scale STATEFUL Java Web apps on Azure?

License

NotificationsYou must be signed in to change notification settings

Azure-Samples/scaling-stateful-java-web-app-on-azure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

page_typelanguagesproductsdescriptionurlFragment
sample
java
azure
This guide walks you through the process of scaling stateful Java apps on Azure.
scaling-stateful-apps-java-sample

This guide walks you through the process of scalingstateful Java apps on Azure, aka:

  • Migrate or deploy stateful Java apps to App Service Linux
  • Externalize HTTP sessions to Azure Redis Cache

Table of Contents

What you will migrate to cloud

You will migrate stateful Java apps to Azure, scale itacross geographiesand demo failover across data centers. Theseapps use:

  • Java Servlet (JSR 369)
  • Java EE 7

Upon migration, you will power the apps using App Service Linux andAzure Redis Cache.

Migrated Java apps can be hosted anywhere –virtual machines,containers - AKS ormanaged Tomcat in App Service Linux.We chose the managed option.The underlying technique for migration is the SAMEregardless of a choice of where migrated apps are hosted.

What you will need

In order to deploy a Java Web app to cloud, you needan Azure subscription. If you do not already have an Azuresubscription, you can activate yourMSDN subscriber benefitsor sign up for afree Azure account.

In addition, you will need the following:

|Azure CLI|Java 8|Maven 3|Git

Getting Started

You can start from scratch and complete each step, oryou can bypass basic setup steps that you are alreadyfamiliar with. Either way, you will end up with working code.

Step ONE - Clone and Prep

git clone --recurse-submodules --remote https://github.com/Azure-Samples/scaling-stateful-java-web-app-on-azurecd scaling-stateful-java-web-app-on-azureyes| cp -rf .prep/*.

Build Scalable Layout for Stateful Java Apps on Azure

Build the Stateful Java Web App:

# change to initial directorycd initial/stateful-java-web-app# build WAR packagemvn package[INFO] Scanningfor projects...[INFO] [INFO] ------------------------------------------------------------------------[INFO] Building Stateful-Tracker 1.0.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Stateful-Tracker ---[INFO] Using'UTF-8' encoding to copy filtered resources.[INFO] Copying 1 resource[INFO] [INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ Stateful-Tracker ---[INFO] Changes detected - recompiling the module![INFO] Compiling 2source files to /Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/target/classes[INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Stateful-Tracker ---[INFO] Using'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/src/test/resources[INFO] [INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ Stateful-Tracker ---[INFO] No sources to compile[INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Stateful-Tracker ---[INFO] No tests to run.[INFO] [INFO] --- maven-war-plugin:3.2.2:war (default-war) @ Stateful-Tracker ---[INFO] Packaging webapp[INFO] Assembling webapp [Stateful-Tracker]in [/Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/target/Stateful-Tracker-1.0.0-SNAPSHOT][INFO] Processing war project[INFO] Copying webapp resources [/Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/src/main/webapp][INFO] Webapp assembledin [67 msecs][INFO] Building war: /Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/target/Stateful-Tracker-1.0.0-SNAPSHOT.war[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 2.963 s[INFO] Finished at: 2019-02-18T21:44:22-08:00[INFO] Final Memory: 20M/308M[INFO] ------------------------------------------------------------------------

Deploy the Stateful Java Web App to First Data Center:

Log into Azure using CLI

az login

Set environment variables for binding secrets at runtime,particularly:

  • Subscription ID
  • Azure Resource Group name
  • Web App Name
  • Redis Cache info (OPTIONAL - you may skip for now)
  • Traffic Manager info

You canexport them to your local environment, say using the suppliedBash shell script template.

cp set-env-variables-template.sh .scripts/set-env-variables.sh

Modify.scripts/set-env-variables.sh and set Subscription,Resource Group, Web App, Redis and Traffic Manager info.Then, set environment variables:

source .scripts/set-env-variables.sh

Deploy to Tomcat on App Service Linux. AddMaven Plugin for Azure App Serviceconfiguration to POM.xml and deploy stateful Java Web app toTomcat in App Service Linux:

<plugin>    <groupId>com.microsoft.azure</groupId>    <artifactId>azure-webapp-maven-plugin</artifactId>    <version>2.5.0</version>    <configuration><!-- Web App information-->    <schemaVersion>v2</schemaVersion>    <subscriptionId>${SUBSCRIPTION_ID}</subscriptionId>    <resourceGroup>${RESOURCEGROUP_NAME}</resourceGroup>    <appName>${WEBAPP_NAME}-${REGION}</appName>    <pricingTier>P1v2</pricingTier>    <region>${REGION}</region>    <appServicePlanName>${WEBAPP_PLAN_NAME}-${REGION}</appServicePlanName>    <appServicePlanResourceGroup>${RESOURCEGROUP_NAME}</appServicePlanResourceGroup>    <runtime>        <os>Linux</os>        <javaVersion>Java 8</javaVersion>        <webContainer>Tomcat 9.0</webContainer>    </runtime>    <deployment>        <resources>        <resource>            <directory>${project.basedir}/target</directory>            <includes>            <include>*.war</include>            </includes>        </resource>        </resources>    </deployment>        <appSettings>            <property>                <name>JAVA_OPTS</name>                <value>-Xms2048m -Xmx2048m</value>            </property>        </appSettings>    </configuration></plugin>

Deploy to Tomcat in App Service Linux, first data center:

mvn azure-webapp:deploy -DREGION=${REGION_1}[INFO] Scanningfor projects...[INFO] [INFO] ------------------------------------------------------------------------[INFO] Building Stateful-Tracker 1.0.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO] [INFO] --- azure-webapp-maven-plugin:1.5.3:deploy (default-cli) @ Stateful-Tracker ---[INFO] Authenticate with Azure CLI 2.0[INFO] Target Web App doesn't exist. Creating a new one...[INFO] Creating App Service Plan'stateful-java-web-app-appservice-plan-westus'...[INFO] Successfully created App Service Plan.[INFO] Successfully created Web App.[INFO] Trying to deploy artifact to stateful-java-web-app-westus...[INFO] Deploying the war file...[INFO] Successfully deployed the artifact to https://stateful-java-web-app-westus.azurewebsites.net[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 01:09 min[INFO] Finished at: 2019-02-18T22:03:14-08:00[INFO] Final Memory: 54M/546M[INFO] ------------------------------------------------------------------------

Deploy the Stateful Java Web App to Second Data Center:

Deploy to Tomcat in App Service Linux, first data center:

mvn azure-webapp:deploy -DREGION=${REGION_2}[INFO] Scanningfor projects...[INFO] [INFO] ------------------------------------------------------------------------[INFO] Building Stateful-Tracker 1.0.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO] [INFO] --- azure-webapp-maven-plugin:1.5.3:deploy (default-cli) @ Stateful-Tracker ---[INFO] Authenticate with Azure CLI 2.0[INFO] Target Web App doesn't exist. Creating a new one...[INFO] Creating App Service Plan'stateful-java-web-app-appservice-plan-eastus'...[INFO] Successfully created App Service Plan.[INFO] Successfully created Web App.[INFO] Trying to deploy artifact to stateful-java-web-app-eastus...[INFO] Deploying the war file...[INFO] Successfully deployed the artifact to https://stateful-java-web-app-eastus.azurewebsites.net[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 03:51 min[INFO] Finished at: 2019-02-18T22:09:11-08:00[INFO] Final Memory: 55M/648M[INFO] ------------------------------------------------------------------------

Cluster Stateful Java Web Apps Behind Traffic Manager:

Create Traffic Manager and cluster these stateful Java Web apps behindthe Traffic Manager.

# create traffic manager profileaz network traffic-manager profile create \    --resource-group${RESOURCEGROUP_NAME} \    --name${TRAFFIC_MANAGER_PROFILE_NAME} \    --routing-method Weighted \    --unique-dns-name${TRAFFIC_MANAGER_DNS_NAME} \    --ttl 30 --protocol HTTP --port 80 --path"/"# create first endpointaz network traffic-manager endpoint create \    --resource-group${RESOURCEGROUP_NAME} \    --profile-name${TRAFFIC_MANAGER_PROFILE_NAME} \    --name${WEBAPP_NAME}-${REGION_1} \    --type azureEndpoints \    --target-resource-id${TARGET_RESOURCE_ID_1} \    --weight 50 \    --endpoint-status enabled# create second endpointaz network traffic-manager endpoint create \    --resource-group${RESOURCEGROUP_NAME} \    --profile-name${TRAFFIC_MANAGER_PROFILE_NAME} \    --name${WEBAPP_NAME}-${REGION_2} \    --type azureEndpoints \    --target-resource-id${TARGET_RESOURCE_ID_2} \    --weight 50 \    --endpoint-status enabled

Traffic manager profile should look like this:

# open the traffic manageropen http://stateful-java-web-app.trafficmanager.net

Let's stop one of the stateful Java Web app and check howfailover happens:

az webapp stop -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_1}

Failover failed because the session tracking begins from scratch,particularly, once the connection breaks, the clientis round robined to another server in East US data center,then the correlation is lost.

Restart the stopped server:

az webapp start -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_1}

Scale Stateful Java Apps on Azure

External data stores, such as Redis Cache, Mongo DB or MySQL,can be used as an external cache for containers, such as Spring Boot,Tomcat and WildFly/JBoss. This allows external data store to storeHTTP Sessions, among other data, independent of the application layer,which provides multiple benefits:

Application Composability - Multiple Apps of Service

By externalizing sessions and using multiple apps that form a service andbouncing users across these apps, youcan realize scenarios such as shopping cart statetraveling with users as they navigate experiencesthrough multiple apps.

Application Elasticity

By making the application stateless additional Web apps may be added tothe service cluster without expensive data rebalancing operations. Theservice cluster may also be replaced without downtime by keeping thestate in the external data store, as upgraded Web apps may be broughtonline and retrieve the sessions.

Failover Across Data Centers

Should a data center become unavailable the session data persists,as it is stored safely within the external data store. This allows aload balancer to redirect incoming requests to a second cluster toretrieve the session information.

Reduced Memory Footprint

There is reduced memory pressure, resulting in shorter garbagecollection time and frequency of collections, as the HTTP Sessionshave been moved out of the application layer and into the backing caches.

Flexibility of External Data Store

External data store such as Azure Redis Cache is available inmultiple tiers.“Premium tier Caches support more features and have higher throughput withlower latencies.” SeeWhat Azure Cache for Redis offering and size should I use?

Externalize Sessions to Azure Redis Cache

Create Redis Cache

# create redis cacheaz redis create \    --name${REDIS_CACHE_NAME} \    --resource-group${RESOURCEGROUP_NAME} \    --location${REGION_1} \    --vm-size C1 --sku Standard \    --enable-non-ssl-portaz redis show \    --name${REDIS_CACHE_NAME} \    --resource-group${RESOURCEGROUP_NAME}# get redis passwordaz redis list-keys \    --name${REDIS_CACHE_NAME} \    --resource-group${RESOURCEGROUP_NAME}{"primaryKey":"======= MASKED =======","secondaryKey":"======= MASKED ======="}

Copy the primary key and set it asREDIS_PASSWORD in the'.scripts/set-env-variables.sh' file and export it to theenvironment.

source .scripts/set-env-variables.sh

Externalize Sessions to Redis Cache

Configure Tomcat's 'src/main/webapp/META-INF/context.xml' toexternalize sessions to Redis Cache:

<?xml version="1.0" encoding="UTF-8"?><Contextpath=""><!-- Specify Redis Store-->    <ValveclassName="com.gopivotal.manager.SessionFlushValve" />    <ManagerclassName="org.apache.catalina.session.PersistentManager">        <StoreclassName="com.gopivotal.manager.redis.RedisStore"connectionPoolSize="20"host="${REDIS_CACHE_NAME}.redis.cache.windows.net"port="${REDIS_PORT}"password="${REDIS_PASSWORD}"sessionKeyPrefix="${REDIS_SESSION_KEY_PREFIX}"timeout="2000"        />    </Manager></Context>

Create an XML file 'context.xml' with the above contents inthe 'src/main/webapp/META-INF/' directory.

Upload Redis Cache Session Manager Binary to App Service Linux

We will usePivotal Session Manager - Redis Storeto externalize sessions. Upload Pivotal Session Manage toApp Service Linux. You can find the JAR at thePivotal GitHub Repo.For your convenience, you will find the JAR ininitial/stateful-java-web-app/.scripts folder.

Upload Session Manager Binary Artifact to First App through FTP

Use Azure CLI to get FTP deployment credentials:

az webapp deployment list-publishing-profiles -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_1}[   ..."profileName":"stateful-java-web-app-eastus - FTP","publishMethod":"FTP","publishUrl":"ftp://waws-prod-blu-089.ftp.azurewebsites.windows.net/site/wwwroot","userName":"stateful-java-web-app-eastus\\$stateful-java-web-app-eastus","userPWD":"======= MASKED =======","webSystem":"WebSites"  }]

Open an FTP connection to App Service Linux to upload artifacts:

cd .scriptsftp> open waws-prod-blu-089.ftp.azurewebsites.windows.netTrying 52.168.126.86...Connected to waws-prod-blu-089.drip.azurewebsites.windows.net.220 Microsoft FTP ServiceName (waws-prod-blu-089.ftp.azurewebsites.windows.net:selvasingh): stateful-java-web-app-eastus\\$stateful-java-web-app-eastus331 Password requiredPassword:230 User logged in.Remote systemtype is Windows_NT.ftp> mkdir tomcat257"tomcat" directory created.ftp>cd tomcat250 CWDcommand successful.ftp> mkdir lib257"lib" directory created.ftp>cd lib250 CWDcommand successful.ftp> bin200 Typeset to I.ftp> put redis-store-1.3.2.RELEASE.jarlocal: redis-store-1.3.2.RELEASE.jar remote: redis-store-1.3.2.RELEASE.jar229 Entering Extended Passive Mode (|||10167|)125 Data connection already open; Transfer starting.100%|*********************************************************|   794 KiB  563.15 KiB/s    00:00 ETA226 Transfer complete.813185 bytes sentin 00:01 (498.59 KiB/s)ftp> bye221 Goodbye.
Upload Session Manager Binary Artifact to Second App through FTP

Similarly, upload session manager binary artifact to second app:

az webapp deployment list-publishing-profiles -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_2}...ftp> open waws-prod-blu-089.ftp.azurewebsites.windows.net...ftp> put redis-store-1.3.2.RELEASE.jarlocal: redis-store-1.3.2.RELEASE.jar remote: redis-store-1.3.2.RELEASE.jar229 Entering Extended Passive Mode (|||10167|)125 Data connection already open; Transfer starting.100%|*********************************************************|   794 KiB  563.15 KiB/s    00:00 ETA226 Transfer complete.813185 bytes sentin 00:01 (498.59 KiB/s)ftp> bye221 Goodbye.

Disable Session Affinity Cookie (ARR cookie) for App Service Linux

az webapp update -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_1} --client-affinity-enabledfalseaz webapp update -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_2} --client-affinity-enabledfalse

Setup Redis Cache Firewall Rules for Java Web Apps

Setup Redis Cache firewall rules for Java Web apps to access the cache.

Retrieve Java Web Apps Outbound IP Addresses

You can get a list of possible outbound IP addresses forJava Web Apps using the Azure Portal - Web App => Properties:

Each Web app has 9 possible outbound IP address. Write them down for bothJava Web apps.

Setup Redis Cache Firewall Rules for Outbound IP Addresses

Use Azure CLI to create Redis Cache firewall rules for all18 possible outbound IP addresses:

# firewall rules for the first Java Web appaz redis firewall-rules create \    --name${REDIS_CACHE_NAME} \    --resource-group${RESOURCEGROUP_NAME} \    --rule-name${WEBAPP_NAME}-${REGION_1}-IP1 \    --start-ip<ip-address-1> \    --end-ip<ip-address-1>......az redis firewall-rules create \    --name${REDIS_CACHE_NAME} \    --resource-group${RESOURCEGROUP_NAME} \    --rule-name${WEBAPP_NAME}-${REGION_1}-IP9 \    --start-ip<ip-address-9> \    --end-ip<ip-address-9># firewall rules for the second Java Web appaz redis firewall-rules create \    --name${REDIS_CACHE_NAME} \    --resource-group${RESOURCEGROUP_NAME} \    --rule-name${WEBAPP_NAME}-${REGION_2}-IP1 \    --start-ip<ip-address-1> \    --end-ip<ip-address-1>......az redis firewall-rules create \    --name${REDIS_CACHE_NAME} \    --resource-group${RESOURCEGROUP_NAME} \    --rule-name${WEBAPP_NAME}-${REGION_2}-IP9 \    --start-ip<ip-address-9> \    --end-ip<ip-address-9>

Rebuild and Re-deploy the Stateful Java Web App to First Data Center

mvn package[INFO] Scanningfor projects...[INFO] [INFO] ------------------------------------------------------------------------[INFO] Building Stateful-Tracker 1.0.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Stateful-Tracker ---[INFO] Using'UTF-8' encoding to copy filtered resources.[INFO] Copying 1 resource[INFO] [INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ Stateful-Tracker ---[INFO] Changes detected - recompiling the module![INFO] Compiling 2source files to /Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/target/classes[INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Stateful-Tracker ---[INFO] Using'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/src/test/resources[INFO] [INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ Stateful-Tracker ---[INFO] No sources to compile[INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Stateful-Tracker ---[INFO] No tests to run.[INFO] [INFO] --- maven-war-plugin:3.2.2:war (default-war) @ Stateful-Tracker ---[INFO] Packaging webapp[INFO] Assembling webapp [Stateful-Tracker]in [/Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/target/Stateful-Tracker-1.0.0-SNAPSHOT][INFO] Processing war project[INFO] Copying webapp resources [/Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/src/main/webapp][INFO] Webapp assembledin [131 msecs][INFO] Building war: /Users/selvasingh/scaling-stateful-java-web-app-on-azure/initial/stateful-java-web-app/target/Stateful-Tracker-1.0.0-SNAPSHOT.war[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 2.330 s[INFO] Finished at: 2019-02-18T23:01:36-08:00[INFO] Final Memory: 18M/214M[INFO] ------------------------------------------------------------------------

Update thepom.xml to upload app settings, particularly secretsto connect with Azure Redis Cache:

<plugin>    <groupId>com.microsoft.azure</groupId>             <artifactId>azure-webapp-maven-plugin</artifactId>             <version>1.5.3</version>             <configuration><!-- Web App information-->                 <resourceGroup>${RESOURCEGROUP_NAME}</resourceGroup>                 <appServicePlanName>${WEBAPP_PLAN_NAME}-${REGION}</appServicePlanName>                 <appName>${WEBAPP_NAME}-${REGION}</appName>                 <region>${REGION}</region>                 <linuxRuntime>tomcat 9.0-jre8</linuxRuntime>                          <appSettings>                     <property>                         <name>REDIS_CACHE_NAME</name>                         <value>${REDIS_CACHE_NAME}</value>                     </property>                     <property>                         <name>REDIS_PORT</name>                         <value>${REDIS_PORT}</value>                     </property>                     <property>                         <name>REDIS_PASSWORD</name>                         <value>${REDIS_PASSWORD}</value>                     </property>                     <property>                         <name>REDIS_SESSION_KEY_PREFIX</name>                         <value>${REDIS_SESSION_KEY_PREFIX}</value>                     </property>                     <property>                         <name>JAVA_OPTS</name>                         <value>-Xms2048m -Xmx2048m -DREDIS_CACHE_NAME=${REDIS_CACHE_NAME} -DREDIS_PORT=${REDIS_PORT} -DREDIS_PASSWORD=${REDIS_PASSWORD} -DREDIS_SESSION_KEY_PREFIX=${REDIS_SESSION_KEY_PREFIX}</value>                     </property>                          </appSettings>                      </configuration>         </plugin>

Re-deploy the stateful Java Web app to the first data center:

mvn azure-webapp:deploy -DREGION=${REGION_1}[INFO] Scanningfor projects...[INFO] [INFO] ------------------------------------------------------------------------[INFO] Building Stateful-Tracker 1.0.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO] [INFO] --- azure-webapp-maven-plugin:1.5.3:deploy (default-cli) @ Stateful-Tracker ---[INFO] Authenticate with Azure CLI 2.0[INFO] Updating target Web App...[INFO] Successfully updated Web App.[INFO] Trying to deploy artifact to stateful-java-web-app-westus...[INFO] Deploying the war file...[INFO] Successfully deployed the artifact to https://stateful-java-web-app-westus.azurewebsites.net[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 55.494 s[INFO] Finished at: 2019-02-18T23:11:31-08:00[INFO] Final Memory: 68M/646M[INFO] ------------------------------------------------------------------------# stop and start the first appaz webapp stop -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_1}az webapp start -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_1}

Re-deploy the Stateful Java Web App to Second Data Center

Similarly, redeploy the stateful Java Web app to second data center:

mvn azure-webapp:deploy -DREGION=${REGION_2}[INFO] Scanningfor projects...[INFO] [INFO] ------------------------------------------------------------------------[INFO] Building Stateful-Tracker 1.0.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO] [INFO] --- azure-webapp-maven-plugin:1.5.3:deploy (default-cli) @ Stateful-Tracker ---[INFO] Authenticate with Azure CLI 2.0[INFO] Updating target Web App...[INFO] Successfully updated Web App.[INFO] Trying to deploy artifact to stateful-java-web-app-eastus...[INFO] Deploying the war file...[INFO] Successfully deployed the artifact to https://stateful-java-web-app-eastus.azurewebsites.net[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 50.840 s[INFO] Finished at: 2019-02-18T23:24:16-08:00[INFO] Final Memory: 67M/645M[INFO] ------------------------------------------------------------------------# stop and start the first appaz webapp stop -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_2}az webapp start -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_2}

Open Scaled Stateful Java Web Apps on Azure

Open the Traffic Manager profile endpoint:

open http://stateful-java-web-app.trafficmanager.net

Let us stop one of the stateful Java Web app and check howfailover happens:

az webapp stop -g${RESOURCEGROUP_NAME} -n${WEBAPP_NAME}-${REGION_1}

Traffic Manager Profile should look like this:

Refresh the browser:

Failover SUCCEEDED because the session tracking begins,particularly, once the connection breaks, the clientis round robined to another server in East US data center,then the correlation is continued, tracks toNumber of Visits = 2,using externalized sessions.

When you are finished, you can check your resultsagainst YOUR code inscaling-stateful-java-web-app-on-azure/complete.

Congratulations!

Congratulations!! You migratedexisting Java enterprise workloads to Azure, aka stateful Java app to App Service Linux andapp's externalized session store to Azure Redis Cache.

Resources

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to aContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant usthe rights to use your contribution. For details, visithttps://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to providea CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructionsprovided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted theMicrosoft Open Source Code of Conduct.For more information see theCode of Conduct FAQ orcontactopencode@microsoft.com with any additional questions or comments.

Packages

No packages published

Contributors8

Languages


[8]ページ先頭

©2009-2025 Movatter.jp