Join Chander Dhall for an in-depth discussion in this video Create a stateless service, part of Microservices and Azure Service Fabric Basics for Developers.
- [Narrator] Now it's time to create a "Hello World" on Visual Studio. Keep in mind you might want to run your Visual Studio as an administrator or you will get an error. When I hit new project I'm going to go to cloud Service Fabric Application. We're going to call the solution Linkedin and hit OK. And we can come pick what we really want to do. We can either have a stateless service or a stateful service or the actor service or even a web API you can also do ASPNET Core.
For now we're going to select Stateless application, so we're going to call it StatelessApp. This is where we get the overview document we're not going to need this and then here's our StatelessApp. You can see that LinkedIn project is really not our service StatelessApp is where our service lives. So what is this project? The application project has few different things for example, it has the ApplicationManifest.xml which is part of the application package root and then you have application parameters which define the application and allow us to configure it for a specific environment so for example if you have a local one note environment you're going to use this one and then you have another XML file for local environment with five notes and then you also have the cloud XML right there.
The application manifest has service manifest and in this case the name of the service manifest is StatelessAppPkg. And we also have the version which in this case is 1.O.O and it tells you that the StatelessApp has a service type name StatelessAppType. You can see this name is the same name as the name of the project right there. Then we have the published profiles which are used to manage tooling preferences for different environments.
And then we have a power shell script right here. Now this is a script that you can use for deploying and upgrading your applications. Visual Studio uses the same script behind the scenes. This script can be easily invoked at the command line. At the service level you can go to PackageRoot and then click ServiceManifest.xml as you can see we have the stateless service type right here which is called StatelessAppType. And then inside the code package you can see the exe which is our executable.
Now we can go to Program.cs and we can see that StatelessAppType has been registered right here. And inside StatelessApp which is sealed class we have something called RunAsync which takes a cancellation token. So for example at any given point of time you want to stop your service you're going to have to send it a command saying stop doing whatever you're doing so we can either restart it or upgrade the particular environment.
So that is the cancellation token. So this method will be called whenever we have a cancellation token. And now service will try to wrap up whatever it's doing as soon as possible and then it will be stopped. And once it's upgraded the service will be back up and running. So in this case it's a very simple task that we're doing here. We're really writing to our diagnostic events the number, every time this iteration is called. So since it's a stateless service they're really not going to be at any state or maintain any state all that happens is every time you have this while loop call it's going to start saying working one, two, three, and that's it.
So let's try to run this and see what happens. So if I go back to my solution press f5 or say start it should start my cluster locally. Now, first time, when you're doing this it might take a few minutes and you can see that they're copying the application to the image store and now your application is ready. So in order to check what's going on I'm going to right-click and say manage local cluster and that takes me to local host 19080 and I can see I have one application here.
I can go in here and click on application. It gives me the type of application which in this case is LinkedInType and then Service Fabric has this particular grid assigned to it. If I were to look at my notes I've got about four, five different nodes that are running the same application. You can see it says the health state is ok and I can check any kind of details I need including the code version, the IP address, and configuration version and a lot of other things.
And then we have the system services that are run by Service Fabric Explorer to get it's job done. Another really important window to keep in mind is the diagnostic events window. It automatically comes up anytime you stop running the solution. So you can see here that that particular iteration is now about 151. If I were to go ahead and pause this you'll see that there's really nothing happening here because I've paused my diagnostic events.
- Reviewing microservices vs. monolithic architecture
- Reviewing microservices and Azure Service Fabric basics
- Programming model architecture
- Creating a stateless service and a stateful service
- Creating a cluster in Azure
- Adding security to a cluster
- Finalizing cluster creation
- Deploying to an Azure cluster
- Debugging an application remotely