Git Product home page Git Product logo

service-fabric-java-quickstart's Introduction

Create a Java Application

Azure Service Fabric is a distributed systems platform for deploying and managing microservices and containers.

This quickstart shows how to deploy your first Java application to Service Fabric using the Eclipse IDE on a Linux developer machine. When you're finished, you have a voting application with a Java web front end that saves voting results in a stateful back-end service in the cluster.

Prerequisites

To complete this quickstart:

  1. Install Service Fabric SDK & Service Fabric Command Line Interface (CLI)
  2. Install Git
  3. Install Eclipse
  4. Set up Java Environment, making sure to follow the optional steps to install the Eclipse plug-in

Download the sample

In a command window, run the following command to clone the sample app repository to your local machine.

git clone https://github.com/Azure-Samples/service-fabric-java-quickstart.git

Run the application locally

  1. Start your local cluster by running the following command:
sudo /opt/microsoft/sdk/servicefabric/common/clustersetup/devclustersetup.sh

The startup of the local cluster takes some time. To confirm that the cluster is fully up, access the Service Fabric Explorer at http://localhost:19080. The five healthy nodes indicate the local cluster is up and running.

  1. Open Eclipse.
  2. Click File -> Open Projects from File System...
  3. Click Directory and choose the Voting directory from the service-fabric-java-quickstart folder you cloned from Github. Click Finish.
  4. You now have the Voting project in the Package Explorer for Eclipse.
  5. Right click on the project and select Publish Application... under the Service Fabric dropdown. Choose PublishProfiles/Local.json as the Target Profile and click Publish.
  6. Open your favorite web browser and access the application by accessing http://localhost:8080.

You can now add a set of voting options,and start taking votes. The application runs and stores all data in your Service Fabric cluster, without the need for a separate database.

Deploy the application to Azure

Set up your Azure Service Fabric Cluster

To deploy the application to a cluster in Azure, create your own cluster or use a Party Cluster.

Party clusters are free, limited-time Service Fabric clusters hosted on Azure. They are run by the Service Fabric team where anyone can deploy applications and learn about the platform. To get access to a Party Cluster, follow the instructions.

For information about creating your own cluster, see Create your first Service Fabric cluster on Azure.

The web front-end service is configured to listen on port 8080 for incoming traffic. Make sure that port is open in your cluster. If you are using the Party Cluster, this port is open.

Deploy the application using Eclipse

Now that the application and your cluster are ready, you can deploy it to the cluster directly from Eclipse.

  1. Open the Cloud.json file under the PublishProfiles directory and fill in the ConnectionIPOrURL and ConnectionPort fields appropriately. An example is provided:
{
     "ClusterConnectionParameters": 
     {
        "ConnectionIPOrURL": "lnxxug0tlqm5.westus.cloudapp.azure.com",
        "ConnectionPort": "19080",
        "ClientKey": "",
        "ClientCert": ""
     }
}
  1. Right click on the project and select Publish Application... under the Service Fabric dropdown. Choose PublishProfiles/Cloud.json as the Target Profile and click Publish.

  2. Open your favorite web browser and access the application by accessing http://<ConnectionIPOrURL>:8080.

Scale applications and services in a cluster

Services can be scaled across a cluster to accommodate for a change in the load on the services. You scale a service by changing the number of instances running in the cluster. You have multiple ways of scaling your services, you can use scripts or commands from Service Fabric CLI (sfctl). In this example,we are using Service Fabric Explorer.

Service Fabric Explorer runs in all Service Fabric clusters and can be accessed from a browser, by browsing to the clusters HTTP management port (19080), for example, http://lnxxug0tlqm5.westus.cloudapp.azure.com:19080.

To scale the web front-end service, do the following steps:

  1. Open Service Fabric Explorer in your cluster - for example, http://lnxxug0tlqm5.westus.cloudapp.azure.com:19080.

  2. Click on the ellipsis (three dots) next to the fabric:/Voting/VotingWeb node in the treeview and choose Scale Service.

    You can now choose to scale the number of instances of the web front-end service.

  3. Change the number to 2 and click Scale Service.

  4. Click on the fabric:/Voting/VotingWeb node in the tree-view and expand the partition node (represented by a GUID).

    You can now see that the service has two instances, and in the tree view you see which nodes the instances run on.

By this simple management task, we doubled the resources available for our front-end service to process user load. It's important to understand that you do not need multiple instances of a service to have it run reliably. If a service fails, Service Fabric makes sure a new service instance runs in the cluster.

service-fabric-java-quickstart's People

Contributors

suhuruli avatar

Watchers

mjunaidi avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.