Skip to content

Commit c7e2d6e

Browse files
committed
Review edits on reliable services quickstart
1 parent 0537dfc commit c7e2d6e

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed
-46 KB
Loading
-44.2 KB
Loading

articles/service-fabric/service-fabric-reliable-services-quick-start.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
---
22
title: Create your first Service Fabric application in C#
33
description: Introduction to creating a Microsoft Azure Service Fabric application with stateless and stateful services.
4-
author: vturecek
5-
64
ms.topic: conceptual
75
ms.date: 07/10/2019
8-
ms.author: vturecek
6+
ms.custom: sfrev
97
---
108
# Get started with Reliable Services
9+
1110
> [!div class="op_single_selector"]
1211
> * [C# on Windows](service-fabric-reliable-services-quick-start.md)
1312
> * [Java on Linux](service-fabric-reliable-services-quick-start-java.md)
14-
>
15-
>
1613
1714
An Azure Service Fabric application contains one or more services that run your code. This guide shows you how to create both stateless and stateful Service Fabric applications with [Reliable Services](service-fabric-reliable-services-introduction.md).
1815

1916
## Basic concepts
17+
2018
To get started with Reliable Services, you only need to understand a few basic concepts:
2119

2220
* **Service type**: This is your service implementation. It is defined by the class you write that extends `StatelessService` and any other code or dependencies used therein, along with a name and a version number.
@@ -25,6 +23,7 @@ To get started with Reliable Services, you only need to understand a few basic c
2523
* **Service registration**: Registration brings everything together. The service type must be registered with the Service Fabric runtime in a service host to allow Service Fabric to create instances of it to run.
2624

2725
## Create a stateless service
26+
2827
A stateless service is a type of service that is currently the norm in cloud applications. It is considered stateless because the service itself does not contain data that needs to be stored reliably or made highly available. If an instance of a stateless service shuts down, all of its internal state is lost. In this type of service, state must be persisted to an external store, such as Azure Tables or a SQL database, for it to be made highly available and reliable.
2928

3029
Launch Visual Studio 2017 or Visual Studio 2019 as an administrator, and create a new Service Fabric application project named *HelloWorld*:
@@ -41,6 +40,7 @@ Your solution now contains two projects:
4140
* *HelloWorldStateless*. This is the service project. It contains the stateless service implementation.
4241

4342
## Implement the service
43+
4444
Open the **HelloWorldStateless.cs** file in the service project. In Service Fabric, a service can run any business logic. The service API provides two entry points for your code:
4545

4646
* An open-ended entry point method, called *RunAsync*, where you can begin executing any workloads, including long-running compute workloads.
@@ -65,11 +65,10 @@ In this tutorial, we will focus on the `RunAsync()` entry point method. This is
6565
The project template includes a sample implementation of `RunAsync()` that increments a rolling count.
6666

6767
> [!NOTE]
68-
> For details about how to work with a communication stack, see [Service Fabric Web API services with OWIN self-hosting](service-fabric-reliable-services-communication-webapi.md)
69-
>
70-
>
68+
> For details about how to work with a communication stack, see [Service communication with ASP.NET Core](service-fabric-reliable-services-communication-aspnetcore.md)
7169
7270
### RunAsync
71+
7372
```csharp
7473
protected override async Task RunAsync(CancellationToken cancellationToken)
7574
{
@@ -105,6 +104,7 @@ Cancellation of your workload is a cooperative effort orchestrated by the provid
105104
In this stateless service example, the count is stored in a local variable. But because this is a stateless service, the value that's stored exists only for the current lifecycle of its service instance. When the service moves or restarts, the value is lost.
106105

107106
## Create a stateful service
107+
108108
Service Fabric introduces a new kind of service that is stateful. A stateful service can maintain state reliably within the service itself, co-located with the code that's using it. State is made highly available by Service Fabric without the need to persist state to an external store.
109109

110110
To convert a counter value from stateless to highly available and persistent, even when the service moves or restarts, you need a stateful service.
@@ -154,9 +154,11 @@ protected override async Task RunAsync(CancellationToken cancellationToken)
154154
```
155155

156156
### RunAsync
157+
157158
`RunAsync()` operates similarly in stateful and stateless services. However, in a stateful service, the platform performs additional work on your behalf before it executes `RunAsync()`. This work can include ensuring that the Reliable State Manager and Reliable Collections are ready to use.
158159

159160
### Reliable Collections and the Reliable State Manager
161+
160162
```csharp
161163
var myDictionary = await this.StateManager.GetOrAddAsync<IReliableDictionary<string, long>>("myDictionary");
162164
```
@@ -173,6 +175,7 @@ Reliable Collections can store any .NET type, including your custom types, with
173175
The Reliable State Manager manages Reliable Collections for you. You can simply ask the Reliable State Manager for a reliable collection by name at any time and at any place in your service. The Reliable State Manager ensures that you get a reference back. We don't recommended that you save references to reliable collection instances in class member variables or properties. Special care must be taken to ensure that the reference is set to an instance at all times in the service lifecycle. The Reliable State Manager handles this work for you, and it's optimized for repeat visits.
174176

175177
### Transactional and asynchronous operations
178+
176179
```csharp
177180
using (ITransaction tx = this.StateManager.CreateTransaction())
178181
{
@@ -184,7 +187,7 @@ using (ITransaction tx = this.StateManager.CreateTransaction())
184187
}
185188
```
186189

187-
Reliable Collections have many of the same operations that their `System.Collections.Generic` and `System.Collections.Concurrent` counterparts do, except LINQ. Operations on Reliable Collections are asynchronous. This is because write operations with Reliable Collections perform I/O operations to replicate and persist data to disk.
190+
Reliable Collections have many of the same operations that their `System.Collections.Generic` and `System.Collections.Concurrent` counterparts do, except for Language Integrated Query (LINQ). Operations on Reliable Collections are asynchronous. This is because write operations with Reliable Collections perform I/O operations to replicate and persist data to disk.
188191

189192
Reliable Collection operations are *transactional*, so that you can keep state consistent across multiple Reliable Collections and operations. For example, you may dequeue a work item from a Reliable Queue, perform an operation on it, and save the result in a Reliable Dictionary, all within a single transaction. This is treated as an atomic operation, and it guarantees that either the entire operation will succeed or the entire operation will roll back. If an error occurs after you dequeue the item but before you save the result, the entire transaction is rolled back and the item remains in the queue for processing.
190193

0 commit comments

Comments
 (0)