Create the first Service Fabric Java application on Linux

Source: Internet
Author: User

Prerequisite

Before you begin, install the Service Fabric SDK, Azure CLI, and set up your development cluster in the Linux development environment. If you use Mac OS X, you can use Vagrant to set up a Linux development environment in a virtual machine.

You also need to configure the Azure CLI 2.0 (recommended) or Xplat CLI to deploy the application.

Create an application

A service Fabric application contains one or more services, each of which has a specific role in providing application functionality. The service Fabric SDK for Linux includes the Yeoman generator, which makes it easy to create the first service and add more services later. In addition, you can create, build, and deploy service Fabric Java applications using plug-ins for Eclipse. See Creating and deploying the first Java application using Eclipse. For this QuickStart, use Yeoman to create an application with a single service that stores and gets the get counter value.

    1. In terminal, type yo azuresfjava .
    2. Name the application.
    3. Select and name the type of the first service. For this tutorial, select the Reliable Actor service. For more information about other service types, see the Service Fabric Programming model Overview.
Building the Application

The Service Fabric Yeoman template contains Gradle build scripts that can be used to build applications from the terminal. To build and package the application, run the following command:

bash replication
cd myappgradle
deploying applications

After the application is built, you can deploy it to a local cluster.

Using the Xplat CLI
    1. Connect to the local Service Fabric cluster.

      Bash replication
      azure servicefabric cluster connect
    2. Run the installation script provided in the template to copy the application package to the cluster's image store, register the application type, and create an application instance.

      Bash replication
      ./install.sh
Using the Azure CLI 2.0

When you deploy the generated application, it is the same way you deploy any other Service Fabric application. For detailed instructions, see the documentation for how to manage service Fabric applications using the Azure CLI.

The parameters of these commands can be found in the build manifest within the application package.

After the application is deployed, open your browser and navigate to the Service Fabric Explorer with the address http://localhost:19080/Explorer. Then, expand the Applications node, note that there is now one entry for the application type, and the other entry for the first instance of the type.

Start the test client and perform a failover

The actor itself does nothing, and they require other services or clients to send messages to it. The actor template contains a simple test script that you can use to interact with the actor service.

    1. Use the monitoring utility to run the script to view the output of the actor service. The test script invokes the method on the role to setCountAsync() increment the counter, invokes the method on the role getCountAsync() to get the new counter value, and displays the value to the console.

      Bash replication
      cd myactorsvcTestClientwatch -n 1 ./testclient.sh
    2. In the Service Fabric Explorer, locate the node that hosts the primary copy of the role service. In the following screen, the node is node 3. The primary service replica handles read and write operations. The service state changes are then replicated outward to the secondary replica, which runs on nodes 0 and 1 on the lower screen.

    3. In nodes, click the node that you found in the previous step, and then choose Deactivate (restart) from the Action menu. This operation restarts the node that is running the primary service replica and forces failover to one of the secondary replicas running on the other node. The secondary copy is promoted to the primary replica, and another copy is created on the other node, and then the primary replica starts to perform read/write operations. When the node restarts, note the output from the test client, and note that the counter continues to increment, although failover occurs.

Remove an application

Use the uninstall script provided in the template to remove the application instance from the cluster's image store, unregister the application package, and remove the application package.

bash replication
./uninstall.sh

In Service Fabric Explorer, you can see that the application and application types no longer appear in the Applications node.

Next steps
    • Learn more about
Related articles
    • Getting Started with Service Fabric and Azure CLI 2.0
    • Getting started with the Service Fabric Xplat CLI

Create the first Service Fabric Java application on Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.