This repository contains a set of simple sample projects to help you get started with Service Fabric. If you are looking for larger samples, please take a look at some of the other Service Fabric samples available in the Azure samples gallery.
The samples are divided by the category and Service Fabric programming model that they focus on: Reliable Actors, Reliable Services, custom application orchestration, and Service Fabric management tasks. Note that most real applications will include a mixture of the concepts and programming models so once you have reviewed these samples, you are encouraged to look at the more complex samples which combine the two frameworks.
VoicemailBox provides an example of a simple actor, representing a voicemail account. The actor interface defines methods for adding, deleting, and querying messages and for managing the account's greeting. The application includes a web UI accessible at http://<clusteraddress>:8081/voicemailbox/ and a set of web APIs that can be used to interact with the actor methods.
The VisualObjects sample provides a visual representation of how actors provide full encapsulation of behavior and state.
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.
AlphabetPartitions provides an example of creating a partitioned, scaled-out service with 26 partitions, one for each letter in the alphabet. The partitionKey to call a particular partition from the Web service to the Processing service is created by simply looking that the first letter in the lastname parameter that is supplied in the URL.
To demonstrate this service, open up a browser and type http://localhost:8081/alphabetpartitions?lastname=FUSSELL
In the reply you should see something similar to below, with a different partition ID and service replica address
Result: User FUSSELL successfully added
Partition key: 'Microsoft.ServiceFabric.Services.Client.ServicePartitionKey' generated from the first letter 'F' of input value 'FUSSELL'.
Processing service partition ID: 446847de-9131-4670-bc02-408d5bafb5bd.
Processing service replica address: Http://localhost:8089/446847de-9131-4670-bc02-408d5bafb5bd/131036145073838836-396b611d-9b91-4d78-8393-c3217221c422
The partitionKey generation is in the Web.cs file in the solution. This is simple approach to partitioning your compute and data. Typically you perform a hash function on some data from the client to choose a particular partition. See the "Scale Apps" section in the documentation for more information.
Chatter is currently being upgraded to ASP.NET Core 1.0 and will return soon.
ReliableQueue and then keeps track of their count in a
ReliableDictionary. The total count, plus a per-partition count, are shown in the web UI at http://<clusteraddress>:8081/WordCount/.
Calculator Service provides a way to integrate your existing WCF Services with service fabric framework .This shows how to create Stateless Service using communication as WCF Http binding.
This shows how to create WCF Client and how to connect the the service endpoint. CalculatorClient is a Wcf Client uses ClientFactoryBase which in turn provides various features like resolving endpoints during Service Failover , ExceptionHandling and maintains a cache of communication clients and attempts to reuse the clients for requests to the same service endpoint. It is using BasicHttpBinding . Any WCF binding can be chosen. It should be compatible with service binding.
The simple guest executable sample shows how to take an arbitrary EXE that is not built on Actors, Services, or any Service Fabric APIs and deploy it to a Service Fabric cluster. The EXE it uses is SimpleWebServer.exe, which is a simple web server that listens on port 8080 and returns the machine name based on a query string parameter.
ClusterMonitor shows how to use the REST APIs provided by Service Fabric to query the state of the cluster and its running applications. It is also useful as a tool for learning how concepts like partitioning and failover work. The application's web UI is accessible at http://<clusteraddress>:8081/cluster/ and shows the cluster with all deployed replicas represented within the node that is currently hosting them.
To see how Service Fabric automatically rebalances replicas in the cluster when a node fails, do the following:
With the exception of VisualObjects, which requires a small amount of setup, all of the samples can be loaded and deployed immediately using Visual Studio. To deploy on the local cluster, you can simply hit F5 to debug the sample. If you'd like to try publishing the sample to an Azure cluster:
The Service Fabric documentation includes a rich set of tutorials and conceptual articles, which serve as a good complement to the samples.