Over the last few years, Docker and software container systems have become the industry standard for packaging and deploying applications. A consequence of this trend has been the development of container orchestration systems like Kubernetes and Apache Mesos. Microsoft Azure has entered the space with its own comprehensive system orchestration and management system, Azure Service Fabric.
What exactly is the value-add for Service Fabric? How do we use it to solve container-related technical challenges? This course answers both of those questions and goes even further by covering a number of relevant software design concepts. From this course, you will learn what Service Fabric does, how to use it to deploy a real application, and how Service Fabric incorporates design patterns and structures such as the actor model and collections.
By the end of the course, you should be ready to work with a team using Azure Service Fabric to create a working application.
- Use Azure Service Fabric to solve infrastructure orchestration challenges
- Learn about software concepts relevant to Service Fabric, including collections, the actor model, and stateful vs stateless services
- Deploy an application to a Service Fabric cluster
- People looking to build applications using Microsoft Azure
- People interested in container orchestration systems
- General knowledge of IT architecture
- General knowledge of software containers
Okay, so for this section, we're gonna talk a little bit about the application that we're actually going to deploy. As mentioned previously, it is a simple voting app, and there are many versions of it available on GitHub. The one we're going to deploy in the final section will be a Linux container. But, for our purposes, we're gonna look at the Java version in order to review some of the concepts we discussed. The Linux container version I believe is Python. So, this will be a Java review to go through some of the concepts we talked about earlier.
So, to see the code in GitHub, we just need to go to the repo, which we had earlier, github.com/Azure-Samples/service-fabric-java-quickstart.
Okay, so we go there, and we can start thinking about the services that we're interested in. So that's gonna be in the Voting directory. And let's think in terms of stateless versus stateful services. So we have both types in this repo here. So if we wanna start by looking at a stateless service, we wanna look at the VotingWeb directory. This is where we're gonna see our stateless service. VotingWeb, go in there, and you're gonna look for the VotingWebService.java file, this one right here. And what you're gonna see in this one is some import statements at the top. This is just kind of standard, boilerplate Java, you know, Java.util, ArrayList, loggers.
The one that we're interested in, though, is this right here. We see this import, microsoft.servicefabric.services.runtime.statelessservice. So this is where we're actually getting the relevant Service Fabric library to create our stateless service.
Now if we look at how it's implemented, it's just a few lines of Java. It's pretty straightforward. Basically, what we're gonna do is extend the stateless service class here by creating this VotingWeb service. We're gonna add a logger to it, and then we're gonna instantiate an endpoint, a listener, basically, that will respond to requests, if we go through this. You can see we have this listener here, which is ArrayList. It's gonna be taking in requests, http requests, that will be passed on to the stateful service. So that's what's going on here.
Now, if we want to see an example of a stateful service, we could go back up to Voting. And we're gonna look at the DataService. There's your clue that we're dealing with state now. So, if we look at the stateful service, VotingDataService.java, it's a similar kind of setup. We have our imports, and then we have where we actually import the stateful service class. We can see how it's set up here.
Now, one other relevant thing, to go back to our discussion of collections, we can see that there is an example of a reliable hashmap here. We're gonna be using this as part of our data management. We wanna take in data as a reliable hashmap. So, we can see that here, and in our VotingDataService, again, we're extending the StatefulService class, we're implementing a VotingRPC, and we have, you know, the same logger here. And basically what we're doing is tracking the requests that we get from the web service, and we're storing them in these hashmaps, and then we will track votes, which you can actually see if you play around with the application. So, this is a, you know, pretty straightforward Java.
If you've worked with hashmaps or web services before, it shouldn't be too complicated. Now, we'll talk a little bit about reliable actors as well. We don't have a good example of it here in this one, but we can find a good example from the documentation. Our VotingService isn't gonna use an actor model, but I wanna talk about it a little bit because it's relevant to Service Fabric and it's relevant to what we covered earlier. So we're just gonna go back into the documentation (https://docs.microsoft.com/azure/service-fabric/service-fabric-create-your-first-linux-application-with-java).
This is our Microsoft Azure documentation. This is their Service Fabric page for Linux applications. And here we have a really good example of the Actor model here. So, we can go through this here and the approach is pretty standard Java.
First, what we do is we create an interface that's to be shared by the clients, and then the actual actor class implementation. And then, in the implementation, we define what the actor does.
So right here, you have your interface, you know, your Java, public interface, extends Actor, and then we just, you know, we're not really doing other thing but managing integers. And then down here, we have our implementation of the actual class, HelloworldActorImp extending FabricActor. There's the relevant library again.
And what we're doing here is, so there's some logger up in here, you know, getting the current count value. This is again just counting integers. We don't really need this overhead for the voting application, but you can see how this would be relevant if we had to parallelize something or if we had to manage a few different threads, that we could have separate actors for different types of requests for an application. So, this is a good example.
If you wanna play around with it, you can copy and run this code on your own. But here's your basic actor model, kind of standard example. So, that's where we'll leave it.
We talked a little bit about our voting application code, and we talked a little bit about the actor model, so you can see some real examples. Very easy to just copy and play around with if you wanna dig in.
Now, I'm not sure about you, but I feel good about this, so let's move on to our next section where we actually get to deploy some software using Service Fabric. It's gonna be a blast. See you then.
Jonathan Bethune is a senior technical consultant working with several companies including TopTal, BCG, and Instaclustr. He is an experienced devops specialist, data engineer, and software developer. Jonathan has spent years mastering the art of system automation with a variety of different cloud providers and tools. Before he became an engineer, Jonathan was a musician and teacher in New York City. Jonathan is based in Tokyo where he continues to work in technology and write for various publications in his free time.