Reader small image

You're reading from  Microservices with Azure

Product typeBook
Published inJun 2017
PublisherPackt
ISBN-139781787121140
Edition1st Edition
Right arrow
Authors (2):
Rahul Rai
Rahul Rai
author image
Rahul Rai

Rahul Rai is a technology consultant based in Sydney, Australia with over nine years of professional experience. He has been at the forefront of cloud consulting for government organizations and businesses around the world. Rahul has been working on Microsoft Azure since the service was in its infancy, delivering an ITSM tool built for and on Azure in 2008. Since then, Rahul has played the roles of a developer, a consultant, and an architect for nterprises ranging from small start-ups to multinational corporations. He worked for over five years with Microsoft Services with diverse teams to deliver innovative solutions on Microsoft Azure. In Microsoft, Rahul was a subject matter expert in Microsoft cloud technologies. Rahul has also worked as a cloud solution architect for Microsoft, for which he worked closely with some established Microsoft partners to drive joint customer transformations to cloud based architectures.
Read more about Rahul Rai

Namit Tanasseri
Namit Tanasseri
author image
Namit Tanasseri

Namit Tanasseri is a certified Microsoft cloud solutions architect with an experience of more than 11 years. He started his career as a software development engineer with Microsoft Research and Development Center in 2005. During the first five years of his career, he had opportunities to work with major Microsoft product groups, such as Microsoft Office and Windows. During this time, he strengthened his knowledge of agile software development methodologies and processes. He also earned a patent during this tenure. As a technology consultant with Microsoft, Namit worked with Microsoft Azure Services for four years. Namit is a subject matter expert in Microsoft Azure and actively contributes to the Microsoft cloud community, while delivering top quality solutions for Microsoft customers. Namit also led the Windows Azure community in Microsoft Services India. Namit currently serves as a Microsoft cloud solutions architect from Sydney, Australia, and works on large and medium-sized enterprise engagements.
Read more about Namit Tanasseri

View More author details
Right arrow

Chapter 5. Hands on with Service Fabric – Reliable Services

By now, we have set a strong foundation for us to explore the internals of Service Fabric. Let's get started by building our first Service Fabric application. We will build a simple application that will print the customary Hello World message.

The companion GitHub repository of this title contains code for all the samples that we have used in this book. You can visit https://github.com/PacktPublishing/Microservices-with-Azure to download the samples. Let's start building our application:

  1. Launch Visual Studio as an administrator. This is necessary because we are going to test our application in Service Fabric local cluster that needs administrator privileges to work.
  2. Click File| New Project | Cloud | Service Fabric Application.

 

 

  1. Name the application HelloWorldApplication and click OK.

Create new Service Fabric application

  1. On the next page, choose Stateless Service as the service type to include in your application. Name it HelloWorldService...

Exploring the Service Fabric Explorer


Service Fabric SDK installs a Service Fabric Application management tool in your system named Service Fabric Explorer (or SFX as Microsoft calls it). You can view the explorer UI by navigating to http://localhost:19080/Explorer/.

It is a two-panel web application in which the left panel displays an overview of your cluster in a tree format and the right panel displays detailed information about the currently selected item. Let's take a quick overview of the tree menu on the left:

Service Fabric Explorer overview

Application Type

This node represents the type of your application, which in the case of our sample is HelloWorldApplicationType. Defining the application type grants the flexibility for an application administrator to tailor the application type to a specific application to be deployed to a Service Fabric cluster by specifying the appropriate parameters of the ApplicationType element in the application manifest.

Application instance

Below the application...

Stateless Reliable Services


A stateless service treats each request as a separate transaction that is independent of any previous request sent to the service. This service can not maintain an internal session store. A stateless service takes all the parameters that it needs to perform an operation at once.

However, you would rarely find applications that are truly stateless. In most of the scenarios, you would find that the state is externalized and stored separately. For instance, a service might use Azure Redis Cache to store state data and not maintain state internally.

Most of the stateless services built on Service Fabric are frontend services that expose the functionality of the underlying system. Users interact with the frontend services, which then forward the call to the correct partition of appropriate stateful services.

Stateless service architecture

Reliable stateless service architecture

A stateless service implementation derives from the StatelessService class which manages the...

Reliable Services communication


Azure Service Fabric gives you the flexibility to implement custom communication stacks using protocols of your choice. To implement a custom communication stack, you need to implement the ICommunicationListener interface. The Reliable Services application framework provides a couple of inbuilt communication stacks that you can use, such as the default stack built on RPC proxy, WCF, REST (Web API), and HTTP (ASP.NET).

Let us build a custom stack using ASP.NET, Web API, and open web interface for .NET (OWIN) self-hosting in Service Fabric stateless Reliable Service.

Note

This sample is inspired from the official Service Fabric Web API services with OWIN self-hosting sample from MSDN: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-services-communication-webapi/.If you are not familiar with Web API. This is a great link to start: https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api...

Exploring the application model


A service fabric application is made up of several Microservices. A Microservice is further made up of three parts:

  • Code: These are the executable binaries of the Microservice. The binaries are packaged in code package.
  • Configuration: These are the settings that can be used by your Microservices at run time. These are packaged into a configuration package.
  • Data: Any static data that is used by the Microservice is packaged in data package.

A Service Fabric application is described by a set of versioned manifests, an application manifest, and several service manifests, one each for each of the Microservices that make up the application. Let's explore the components of a Service Fabric application by navigating through the Service Fabric application package.

To package your application, right click on your Service Fabric application project and click on the Package option:

Package application

Once the application has finished packaging, open the package folder by navigating...

Stateful service


A stateful Microservice stores state information stored in a consistent and highly available manner using reliable data structure. By default, the state data is saved on the disk of the compute node. However, you can write your own state providers to store state data externally and consume it. Service Fabric ensures that your state data is consistent and highly available so that, in case of failure of primary compute node, a secondary node can resume processing without loss of data.

Stateful service architecture

A stateful service takes requests from clients through the ICommunicationListener interface:

Stateful Reliable Service architecture

The implementation of a stateful reliable service derives from StatefulService class. Service Fabric runtime manages the lifetime of your stateful Microservice through the StatefulService class. The service can use Reliable Collections to persist state information, which are similar to collections in System.Collections namespace but with...

Summary


We started this chapter by building our first Service Fabric stateless application. After which we took a thorough look at the Service Fabric Explorer. Next, we studied stateless and stateful service architecture and lifecycles using Service Fabric Reliable Services. Lastly, we looked at service partition and replicas in detail.

In the next chapter we will discuss another programming model of Service Fabric knows as Reliable Actors.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Microservices with Azure
Published in: Jun 2017Publisher: PacktISBN-13: 9781787121140
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Rahul Rai

Rahul Rai is a technology consultant based in Sydney, Australia with over nine years of professional experience. He has been at the forefront of cloud consulting for government organizations and businesses around the world. Rahul has been working on Microsoft Azure since the service was in its infancy, delivering an ITSM tool built for and on Azure in 2008. Since then, Rahul has played the roles of a developer, a consultant, and an architect for nterprises ranging from small start-ups to multinational corporations. He worked for over five years with Microsoft Services with diverse teams to deliver innovative solutions on Microsoft Azure. In Microsoft, Rahul was a subject matter expert in Microsoft cloud technologies. Rahul has also worked as a cloud solution architect for Microsoft, for which he worked closely with some established Microsoft partners to drive joint customer transformations to cloud based architectures.
Read more about Rahul Rai

author image
Namit Tanasseri

Namit Tanasseri is a certified Microsoft cloud solutions architect with an experience of more than 11 years. He started his career as a software development engineer with Microsoft Research and Development Center in 2005. During the first five years of his career, he had opportunities to work with major Microsoft product groups, such as Microsoft Office and Windows. During this time, he strengthened his knowledge of agile software development methodologies and processes. He also earned a patent during this tenure. As a technology consultant with Microsoft, Namit worked with Microsoft Azure Services for four years. Namit is a subject matter expert in Microsoft Azure and actively contributes to the Microsoft cloud community, while delivering top quality solutions for Microsoft customers. Namit also led the Windows Azure community in Microsoft Services India. Namit currently serves as a Microsoft cloud solutions architect from Sydney, Australia, and works on large and medium-sized enterprise engagements.
Read more about Namit Tanasseri