Getting started with Service Fabric with Java

Vaclav Turecek 提供
在 GitHub 上编辑

This repository contains a set of simple sample projects to help you getting started with Service Fabric on Linux using java as the development language. As a pre requisite ensure you have the Service Fabric Java SDK installed on ubuntu box.

How the samples are organized

The samples are divided by the category and Service Fabric programming model that they focus on: Reliable Actors, Reliable Services. Note that most real applications will include a mixture of the concepts and programming models.

Actor samples


Actor counter provides an example of a very simple actor which implements a counter. Once the service is deployed you can run the testclient to see the effect of counter incrementing.


This sample project uses Paper.js to render a set of objects. Each object is represented by an Actor, where the location and trajectory of each is calculated on the server side by the Actor representing the object.

This sample creates multiple Visual actor which keeps on moving in the plane. To run the sample, execute gradle and install application by executing Once the application has started, go to http://localhost:8507/index.html. Try opening it in multiple browser windows or on multiple machines to see how the server side calculation produces the same result on every screen.

It also provides a clear demonstration of how Service Fabric performs rolling upgrades as the behavior of the shapes can be seen to gradually change as the upgrade proceeds across the upgrade domains in the cluster. To see how to perform a rolling upgrade using the Visual Objects sample, see the application upgrade tutorial.

Service Samples


This stateless service sample demostrates a simple web server. Go to EchoServer1.0 and after deploying application, go to browser and type in http://localhost:8508/getMessage, you should see '[version 1.0]Hello World !!!'. If you type in http://localhost:8508/getMessage/?Raunak, you should see '[version 1.0]Hello Raunak!!!'

EchoServer2.0 sample demostrates upgrade of stateless service. Both the applications are almost same except for the version number returned back upon web query. Run the to upgrade from version 1.0 to version 2.0. After upgrading the application, go to the browser and type in http://localhost:8508/getMessage, to see '[version 2.0]Hello World !!!'. If you type in http://localhost:8508/getMessage/?Raunak, you should see '[version 2.0]Hello Raunak!!!'


This stateless service sample demostrates writing a web frontend for your actor service. This is currently acting as gateway for the Actor Counter application. Once you have deployed the Actor Counter and Gateway application go to url http://localhost:12346/Actor/Actor1 to see the counter value being fetched from the actor service. Refresh the web page to see how the counter value getting incremented.


This stateless service demostrates a watch dog application which is monitoring the EchoServer application. Once you have depployed EchoServer and WatchDog application, you would see that if EchoServer application goes down or for some reason the applications web endpoint is not reachable, an error health is reported by WatchDog for the EchoServer application in the Service Fabric health subsystem. Apart from this, this application also shows inter service communication by forwarding the web requests to Echo Server application. You can view this by going to browser @ http://localhost:12345/getMessage to see the output coming from EchoServer.

Compiling the samples

For compiling the samples use gradle. This should be configured as part of the Service Fabric Java SDK installation.

Deploying the samples

All the samples once compiled can be deployed immediately using the scripts provided along with the sample. These scripts underneath uses azurecli. Before running the scripts you need to first connect to the cluster using azurecli.

More information

The Service Fabric documentation includes a rich set of tutorials and conceptual articles, which serve as a good complement to the samples.

更多示例由 Vaclav Turecek 提供