├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── Elasticsearch └── ElasticsearchObjects.json ├── Entities ├── Entities.csproj ├── JsonSerializerHelper.cs ├── Message.cs ├── Payload.cs ├── Properties │ └── AssemblyInfo.cs ├── Result.cs ├── Statistics.cs └── packages.config ├── EventCollectorService ├── App.config ├── DeleteEtwSessions.ps1 ├── EventCollectorService.cs ├── EventCollectorService.csproj ├── PackageRoot │ ├── Config │ │ ├── Settings.xml │ │ └── eventFlowConfig.json │ └── ServiceManifest.xml ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Setup.bat ├── eventFlowConfig.json └── packages.config ├── Framework.Interfaces ├── Framework.Interfaces.csproj ├── ICircularQueueActor.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── Framework ├── ActorEventSource.cs ├── CircularQueueActor.cs ├── Framework.csproj ├── Properties │ └── AssemblyInfo.cs ├── ServiceEventSource.cs ├── app.config └── packages.config ├── GatewayService ├── App.config ├── App_Start │ └── BrowserJsonFormatter.cs ├── Controllers │ └── GatewayController.cs ├── EventSourceFilter.cs ├── GatewayService.cs ├── GatewayService.csproj ├── IOwinAppBuilder.cs ├── OwinCommunicationListener.cs ├── PackageRoot │ ├── Config │ │ └── Settings.xml │ └── ServiceManifest.xml ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Startup.cs └── packages.config ├── Images ├── ApplicationInsights.png ├── Architecture.png ├── Client.png ├── Elasticsearch.png ├── Parallel.png ├── Sequential.png └── concurrency.png ├── LICENSE ├── LongRunningActors.docx ├── LongRunningActors.sln ├── LongRunningActors ├── ApplicationPackageRoot │ └── ApplicationManifest.xml ├── ApplicationParameters │ ├── Cloud.xml │ ├── CloudNoPlacementConstraints.xml │ ├── Local.1Node.xml │ └── Local.5Node.xml ├── LongRunningActors.sfproj ├── PublishProfiles │ ├── Cloud.xml │ ├── Local.1Node.xml │ └── Local.5Node.xml ├── Scripts │ └── Deploy-FabricApplication.ps1 ├── app.config └── packages.config ├── Powershell └── RemoveEtwSessions.ps1 ├── README.md ├── ServiceFabricServicesBackup ├── EventCollectorService │ ├── App.config │ ├── DeleteEtwSessions.ps1 │ ├── EventCollectorService.cs │ ├── EventCollectorService.csproj │ ├── PackageRoot │ │ ├── Config │ │ │ ├── Settings.xml │ │ │ └── eventFlowConfig.json │ │ └── ServiceManifest.xml │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Setup.bat │ ├── eventFlowConfig.json │ └── packages.config ├── GatewayService │ ├── App.config │ ├── App_Start │ │ └── BrowserJsonFormatter.cs │ ├── Controllers │ │ └── GatewayController.cs │ ├── EventSourceFilter.cs │ ├── GatewayService.cs │ ├── GatewayService.csproj │ ├── IOwinAppBuilder.cs │ ├── OwinCommunicationListener.cs │ ├── PackageRoot │ │ ├── Config │ │ │ └── Settings.xml │ │ └── ServiceManifest.xml │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Startup.cs │ └── packages.config └── WorkerActorService │ ├── App.config │ ├── PackageRoot │ ├── Config │ │ └── Settings.xml │ └── ServiceManifest.xml │ ├── ProcessorActor.cs │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── QueueActor.cs │ ├── WorkerActor.cs │ ├── WorkerActorService.cs │ ├── WorkerActorService.csproj │ └── packages.config ├── TestClient ├── App.config ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── TestClient.csproj └── packages.config ├── Visio └── LongRunningActors.vsdx ├── WorkerActorService.Interfaces ├── IProcessorActor.cs ├── IQueueActor.cs ├── IWorkerActor.cs ├── IWorkerActorEvents.cs ├── Properties │ └── AssemblyInfo.cs ├── WorkerActorService.Interfaces.csproj ├── app.config └── packages.config └── WorkerActorService ├── App.config ├── PackageRoot ├── Config │ └── Settings.xml └── ServiceManifest.xml ├── ProcessorActor.cs ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── QueueActor.cs ├── WorkerActor.cs ├── WorkerActorService.cs ├── WorkerActorService.csproj └── packages.config /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | # DNX 42 | project.lock.json 43 | artifacts/ 44 | 45 | *_i.c 46 | *_p.c 47 | *_i.h 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.svclog 68 | *.scc 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | 86 | # TFS 2012 Local Workspace 87 | $tf/ 88 | 89 | # Guidance Automation Toolkit 90 | *.gpState 91 | 92 | # ReSharper is a .NET coding add-in 93 | _ReSharper*/ 94 | *.[Rr]e[Ss]harper 95 | *.DotSettings.user 96 | 97 | # JustCode is a .NET coding add-in 98 | .JustCode 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | _NCrunch_* 108 | .*crunch*.local.xml 109 | 110 | # MightyMoose 111 | *.mm.* 112 | AutoTest.Net/ 113 | 114 | # Web workbench (sass) 115 | .sass-cache/ 116 | 117 | # Installshield output folder 118 | [Ee]xpress/ 119 | 120 | # DocProject is a documentation generator add-in 121 | DocProject/buildhelp/ 122 | DocProject/Help/*.HxT 123 | DocProject/Help/*.HxC 124 | DocProject/Help/*.hhc 125 | DocProject/Help/*.hhk 126 | DocProject/Help/*.hhp 127 | DocProject/Help/Html2 128 | DocProject/Help/html 129 | 130 | # Click-Once directory 131 | publish/ 132 | 133 | # Publish Web Output 134 | *.[Pp]ublish.xml 135 | *.azurePubxml 136 | ## TODO: Comment the next line if you want to checkin your 137 | ## web deploy settings but do note that will include unencrypted 138 | ## passwords 139 | #*.pubxml 140 | 141 | *.publishproj 142 | 143 | # NuGet Packages 144 | *.nupkg 145 | # The packages folder can be ignored because of Package Restore 146 | **/packages/* 147 | # except build/, which is used as an MSBuild target. 148 | !**/packages/build/ 149 | # Uncomment if necessary however generally it will be regenerated when needed 150 | #!**/packages/repositories.config 151 | 152 | # Windows Azure Build Output 153 | csx/ 154 | *.build.csdef 155 | 156 | # Windows Store app package directory 157 | AppPackages/ 158 | 159 | # Visual Studio cache files 160 | # files ending in .cache can be ignored 161 | *.[Cc]ache 162 | # but keep track of directories ending in .cache 163 | !*.[Cc]ache/ 164 | 165 | # Others 166 | ClientBin/ 167 | [Ss]tyle[Cc]op.* 168 | ~$* 169 | *~ 170 | *.dbmdl 171 | *.dbproj.schemaview 172 | *.pfx 173 | *.publishsettings 174 | node_modules/ 175 | orleans.codegen.cs 176 | 177 | # RIA/Silverlight projects 178 | Generated_Code/ 179 | 180 | # Backup & report files from converting an old project file 181 | # to a newer Visual Studio version. Backup files are not needed, 182 | # because we have git ;-) 183 | _UpgradeReport_Files/ 184 | Backup*/ 185 | UpgradeLog*.XML 186 | UpgradeLog*.htm 187 | 188 | # SQL Server files 189 | *.mdf 190 | *.ldf 191 | 192 | # Business Intelligence projects 193 | *.rdl.data 194 | *.bim.layout 195 | *.bim_*.settings 196 | 197 | # Microsoft Fakes 198 | FakesAssemblies/ 199 | 200 | # Node.js Tools for Visual Studio 201 | .ntvs_analysis.dat 202 | 203 | # Visual Studio 6 build log 204 | *.plg 205 | 206 | # Visual Studio 6 workspace options file 207 | *.opt 208 | 209 | # LightSwitch generated files 210 | GeneratedArtifacts/ 211 | _Pvt_Extensions/ 212 | ModelManifest.xml 213 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Azure samples 2 | 3 | Thank you for your interest in contributing to Azure samples! 4 | 5 | ## Ways to contribute 6 | 7 | You can contribute to [Azure samples](https://azure.microsoft.com/documentation/samples/) in a few different ways: 8 | 9 | - Submit feedback on [this sample page](https://azure.microsoft.com/documentation/samples/service-fabric-dotnet-asynchronous-computing-actors/) whether it was helpful or not. 10 | - Submit issues through [issue tracker](https://github.com/Azure-Samples/service-fabric-dotnet-asynchronous-computing-actors/issues) on GitHub. We are actively monitoring the issues and improving our samples. 11 | - If you wish to make code changes to samples, or contribute something new, please follow the [GitHub Forks / Pull requests model](https://help.github.com/articles/fork-a-repo/): Fork the sample repo, make the change and propose it back by submitting a pull request. -------------------------------------------------------------------------------- /Entities/Entities.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {36C131BF-5573-4295-B6D9-3121B762B33E} 8 | Library 9 | Properties 10 | Microsoft.AzureCat.Samples.Entities 11 | Microsoft.AzureCat.SamplesEntities 12 | v4.5.1 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | x64 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll 37 | True 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 67 | -------------------------------------------------------------------------------- /Entities/JsonSerializerHelper.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System; 23 | using System.IO; 24 | using Newtonsoft.Json; 25 | using Newtonsoft.Json.Linq; 26 | 27 | #endregion 28 | 29 | namespace Microsoft.AzureCat.Samples.Entities 30 | { 31 | public static class JsonSerializerHelper 32 | { 33 | /// 34 | /// Serialize an object using the DataContractJsonSerializer. 35 | /// 36 | /// The object that must be serialized 37 | /// Indicates out the output is formatted 38 | /// A Json representation of the object passed as an argument. 39 | public static string Serialize(object item, Formatting formatting = default(Formatting)) 40 | { 41 | if (item == null) 42 | throw new ArgumentException("The item argument cannot be null."); 43 | 44 | var json = JsonConvert.SerializeObject(item, formatting); 45 | return json; 46 | } 47 | 48 | /// 49 | /// Deserialize a JSON string into an object using the JavaScriptSerializer. 50 | /// 51 | /// The string that must be deserialized. 52 | /// The object deserialized. 53 | public static T Deserialize(string item) 54 | { 55 | if (item == null) 56 | throw new ArgumentException("The item argument cannot be null."); 57 | return JsonConvert.DeserializeObject(item); 58 | } 59 | 60 | /// 61 | /// Deserialize a JSON string into an object using the JavaScriptSerializer. 62 | /// 63 | /// The string that must be deserialized. 64 | /// The object deserialized. 65 | public static JObject Deserialize(string item) 66 | { 67 | if (item == null) 68 | throw new ArgumentException("The item argument cannot be null."); 69 | return JsonConvert.DeserializeObject(item) as JObject; 70 | } 71 | 72 | /// 73 | /// Deserialize an Json string into an object using the JavaScriptSerializer. 74 | /// 75 | /// The stream that must be deserialized. 76 | /// The object deserialized. 77 | public static T Deserialize(Stream stream) 78 | { 79 | if (stream == null) 80 | throw new ArgumentException("The stream argument cannot be null."); 81 | 82 | string item; 83 | using (var reader = new StreamReader(stream)) 84 | { 85 | item = reader.ReadToEnd(); 86 | } 87 | return Deserialize(item); 88 | } 89 | 90 | /// 91 | /// Checks if the string is in JSON format. 92 | /// 93 | /// The string that must be deserialized. 94 | /// Returns true if the object is in JSON format, false otherwise. 95 | public static bool IsJson(string item) 96 | { 97 | if (item == null) 98 | throw new ArgumentException("The item argument cannot be null."); 99 | try 100 | { 101 | var obj = JToken.Parse(item); 102 | return obj != null; 103 | } 104 | catch (Exception) 105 | { 106 | return false; 107 | } 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /Entities/Message.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System.Collections.Generic; 23 | using Newtonsoft.Json; 24 | 25 | #endregion 26 | 27 | namespace Microsoft.AzureCat.Samples.Entities 28 | { 29 | /// 30 | /// Represents messages elaborated by the worker and processor actors. 31 | /// 32 | public class Message 33 | { 34 | /// 35 | /// Gets or sets the message id. 36 | /// 37 | [JsonProperty(PropertyName = "messageId", Order = 1)] 38 | public string MessageId { get; set; } 39 | 40 | /// 41 | /// Gets or sets the message body. 42 | /// 43 | [JsonProperty(PropertyName = "body", Order = 2)] 44 | public string Body { get; set; } 45 | 46 | /// 47 | /// Gets or sets the message properties 48 | /// 49 | [JsonProperty(PropertyName = "properties", Order = 3)] 50 | public IDictionary Properties { get; set; } 51 | } 52 | } -------------------------------------------------------------------------------- /Entities/Payload.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using Newtonsoft.Json; 23 | 24 | #endregion 25 | 26 | namespace Microsoft.AzureCat.Samples.Entities 27 | { 28 | /// 29 | /// Represents messages sent to the gateway service. 30 | /// 31 | public class Payload 32 | { 33 | /// 34 | /// Gets or sets the worker actor id. 35 | /// 36 | [JsonProperty(PropertyName = "workerId", Order = 1)] 37 | public string WorkerId { get; set; } 38 | 39 | /// 40 | /// Gets or sets the message sent to the worker actor. 41 | /// 42 | [JsonProperty(PropertyName = "message", Order = 2)] 43 | public Message Message { get; set; } 44 | } 45 | } -------------------------------------------------------------------------------- /Entities/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | 13 | [assembly: AssemblyTitle("Entities")] 14 | [assembly: AssemblyDescription("")] 15 | [assembly: AssemblyConfiguration("")] 16 | [assembly: AssemblyCompany("")] 17 | [assembly: AssemblyProduct("Entities")] 18 | [assembly: AssemblyCopyright("Copyright © 2016")] 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | 30 | [assembly: Guid("36c131bf-5573-4295-b6d9-3121b762b33e")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | 43 | [assembly: AssemblyVersion("1.0.0.0")] 44 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Entities/Result.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using Newtonsoft.Json; 23 | 24 | #endregion 25 | 26 | namespace Microsoft.AzureCat.Samples.Entities 27 | { 28 | public class Result 29 | { 30 | /// 31 | /// Gets or sets the message id. 32 | /// 33 | [JsonProperty(PropertyName = "messageId", Order = 1)] 34 | public string MessageId { get; set; } 35 | 36 | /// 37 | /// Gets or sets the result. 38 | /// 39 | [JsonProperty(PropertyName = "returnValue", Order = 2)] 40 | public long ReturnValue { get; set; } 41 | } 42 | } -------------------------------------------------------------------------------- /Entities/Statistics.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System.Collections.Generic; 23 | using Newtonsoft.Json; 24 | 25 | #endregion 26 | 27 | namespace Microsoft.AzureCat.Samples.Entities 28 | { 29 | /// 30 | /// Represents the worker actor statistics. 31 | /// 32 | public class Statistics 33 | { 34 | /// 35 | /// Gets or sets the number of received messages. 36 | /// 37 | [JsonProperty(PropertyName = "received", Order = 1)] 38 | public long Received { get; set; } 39 | 40 | /// 41 | /// Gets or sets the number of complete messages. 42 | /// 43 | [JsonProperty(PropertyName = "complete", Order = 2)] 44 | public long Complete { get; set; } 45 | 46 | /// 47 | /// Gets or sets the number of stopped messages. 48 | /// 49 | [JsonProperty(PropertyName = "stopped", Order = 3)] 50 | public long Stopped { get; set; } 51 | 52 | /// 53 | /// Gets or sets the min value. 54 | /// 55 | [JsonProperty(PropertyName = "min", Order = 4)] 56 | public long MinValue { get; set; } 57 | 58 | /// 59 | /// Gets or sets the max value. 60 | /// 61 | [JsonProperty(PropertyName = "max", Order = 5)] 62 | public long MaxValue { get; set; } 63 | 64 | /// 65 | /// Gets or sets the total value. 66 | /// 67 | [JsonProperty(PropertyName = "tot", Order = 6)] 68 | public long TotalValue { get; set; } 69 | 70 | /// 71 | /// Gets or sets the average value. 72 | /// 73 | [JsonProperty(PropertyName = "avg", Order = 7)] 74 | public double AverageValue { get; set; } 75 | 76 | /// 77 | /// Gets or sets the average value. 78 | /// 79 | [JsonProperty(PropertyName = "results", Order = 8)] 80 | public IEnumerable Results { get; set; } 81 | } 82 | } -------------------------------------------------------------------------------- /Entities/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /EventCollectorService/DeleteEtwSessions.ps1: -------------------------------------------------------------------------------- 1 | [string[]]$EtwSessions = Get-EtwTraceSession -Name "*"| Where-Object {$_.Name -like "EventFlow-EtwInput-*"} | Select-Object -ExpandProperty Name 2 | if ($EtwSessions -ne $null) 3 | { 4 | Remove-EtwTraceSession -Name $EtwSessions 5 | } -------------------------------------------------------------------------------- /EventCollectorService/PackageRoot/Config/Settings.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 9 |
10 | 11 |
12 |
13 | -------------------------------------------------------------------------------- /EventCollectorService/PackageRoot/Config/eventFlowConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "type": "ETW", 5 | "providers": [ 6 | { 7 | "providerName": "Microsoft-ServiceFabric-Services", 8 | "level": "servicefabric:/DiagnosticPipelineParametersConfig/TraceLevel" 9 | }, 10 | { 11 | "providerName": "Microsoft-ServiceFabric-Actors", 12 | "level": "servicefabric:/DiagnosticPipelineParametersConfig/TraceLevel" 13 | }, 14 | { 15 | "providerName": "LongRunningActors-Framework-Service", 16 | "level": "servicefabric:/DiagnosticPipelineParametersConfig/TraceLevel" 17 | }, 18 | { 19 | "providerName": "LongRunningActors-Framework-Actor", 20 | "level": "servicefabric:/DiagnosticPipelineParametersConfig/TraceLevel" 21 | } 22 | ] 23 | } 24 | ], 25 | "filters": [ 26 | { 27 | "type": "drop", 28 | "include": "Level == Verbose" 29 | }, 30 | { 31 | "type": "drop", 32 | "include": "ProviderName == System.Threading.Tasks.TplEventSource" 33 | }, 34 | { 35 | "type": "drop", 36 | "include": "ProviderName == Microsoft-ServiceFabric-Services && EventName == ManifestData" 37 | }, 38 | { 39 | "type": "drop", 40 | "include": "ProviderName == Microsoft-ServiceFabric-Actors && EventName == ManifestData" 41 | }, 42 | { 43 | "type": "drop", 44 | "include": "ProviderName == LongRunningActors-Framework-Service && EventName == ManifestData" 45 | }, 46 | { 47 | "type": "drop", 48 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ManifestData" 49 | } 50 | ], 51 | "outputs": [ 52 | { 53 | "type": "EventHub", 54 | "eventHubName": "diagnosticseventfloweventhub", 55 | "connectionString": "", 56 | "filters": [ 57 | { 58 | "type": "drop", 59 | "include": "ProviderName == Microsoft-ServiceFabric-Services || ProviderName == Microsoft-ServiceFabric-Actors" 60 | } 61 | ] 62 | }, 63 | { 64 | "type": "ElasticSearch", 65 | "indexNamePrefix": "LongRunningActors-", 66 | "serviceUri": "http://localhost:9200", 67 | "filters": [ 68 | { 69 | "type": "metadata", 70 | "metadata": "request", 71 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == RequestComplete", 72 | "requestNameProperty": "requestName", 73 | "isSuccessProperty": "isSuccess", 74 | "durationProperty": "duration", 75 | "durationUnit": "milliseconds", 76 | "responseCodeProperty": "response" 77 | }, 78 | { 79 | "type": "metadata", 80 | "metadata": "request", 81 | "include": "ProviderName == LongRunningActors-Framework-Service && EventName == RequestComplete", 82 | "requestNameProperty": "requestName", 83 | "isSuccessProperty": "isSuccess", 84 | "durationProperty": "duration", 85 | "durationUnit": "milliseconds", 86 | "responseCodeProperty": "response" 87 | }, 88 | { 89 | "type": "metadata", 90 | "metadata": "metric", 91 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ReceivedMessage", 92 | "metricName": "ReceivedMessages", 93 | "metricValue": "1.0" 94 | }, 95 | { 96 | "type": "metadata", 97 | "metadata": "metric", 98 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == StoppedMessage", 99 | "metricName": "StoppedMessages", 100 | "metricValue": "1.0" 101 | }, 102 | { 103 | "type": "metadata", 104 | "metadata": "metric", 105 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ProcessedMessage", 106 | "metricName": "ProcessedMessages", 107 | "metricValue": "1.0" 108 | } 109 | ] 110 | }, 111 | { 112 | "type": "ApplicationInsights", 113 | "instrumentationKey": "", 114 | "filters": [ 115 | { 116 | "type": "metadata", 117 | "metadata": "request", 118 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == RequestComplete", 119 | "requestNameProperty": "requestName", 120 | "isSuccessProperty": "isSuccess", 121 | "durationProperty": "duration", 122 | "durationUnit": "milliseconds", 123 | "responseCodeProperty": "response" 124 | }, 125 | { 126 | "type": "metadata", 127 | "metadata": "request", 128 | "include": "ProviderName == LongRunningActors-Framework-Service && EventName == RequestComplete", 129 | "requestNameProperty": "requestName", 130 | "isSuccessProperty": "isSuccess", 131 | "durationProperty": "duration", 132 | "durationUnit": "milliseconds", 133 | "responseCodeProperty": "response" 134 | }, 135 | { 136 | "type": "metadata", 137 | "metadata": "dependency", 138 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == Dependency", 139 | "isSuccessProperty": "isSuccess", 140 | "durationProperty": "duration", 141 | "durationUnit": "milliseconds", 142 | "responseCodeProperty": "response", 143 | "targetProperty": "target", 144 | "dependencyType": "type" 145 | }, 146 | { 147 | "type": "metadata", 148 | "metadata": "dependency", 149 | "include": "ProviderName == LongRunningActors-Framework-Service && EventName == Dependency", 150 | "isSuccessProperty": "isSuccess", 151 | "durationProperty": "duration", 152 | "durationUnit": "milliseconds", 153 | "responseCodeProperty": "response", 154 | "targetProperty": "target", 155 | "dependencyType": "type" 156 | }, 157 | { 158 | "type": "metadata", 159 | "metadata": "metric", 160 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ReceivedMessage", 161 | "metricName": "ReceivedMessages", 162 | "metricValue": "1.0" 163 | }, 164 | { 165 | "type": "metadata", 166 | "metadata": "metric", 167 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == StoppedMessage", 168 | "metricName": "StoppedMessages", 169 | "metricValue": "1.0" 170 | }, 171 | { 172 | "type": "metadata", 173 | "metadata": "metric", 174 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ProcessedMessage", 175 | "metricName": "ProcessedMessages", 176 | "metricValue": "1.0" 177 | } 178 | ] 179 | } 180 | ], 181 | "schemaVersion": "2016-08-11", 182 | "settings": { 183 | "pipelineBufferSize": "10000", 184 | "maxEventBatchSize": "1000", 185 | "maxBatchDelayMsec": "500", 186 | "maxConcurrency": "10", 187 | "pipelineCompletionTimeoutMsec": "30000" 188 | }, 189 | "extensions": [] 190 | } -------------------------------------------------------------------------------- /EventCollectorService/PackageRoot/ServiceManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Setup.bat 18 | CodePackage 19 | 20 | 21 | 22 | 23 | EventCollectorService.exe 24 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /EventCollectorService/Program.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | using System; 22 | using System.Diagnostics; 23 | using System.Threading; 24 | using Microsoft.ServiceFabric.Services.Runtime; 25 | using Microsoft.AzureCat.Samples.Framework; 26 | 27 | #endregion 28 | namespace Microsoft.AzureCat.Samples.EventCollectorService 29 | { 30 | internal static class Program 31 | { 32 | /// 33 | /// This is the entry point of the service host process. 34 | /// 35 | private static void Main() 36 | { 37 | try 38 | { 39 | // The ServiceManifest.XML file defines one or more service type names. 40 | // Registering a service maps a service type name to a .NET type. 41 | // When Service Fabric creates an instance of this service type, 42 | // an instance of the class is created in this host process. 43 | 44 | ServiceRuntime.RegisterServiceAsync("EventCollectorServiceType", 45 | context => new EventCollectorService(context)).GetAwaiter().GetResult(); 46 | 47 | ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(EventCollectorService).Name); 48 | 49 | // Prevents this host process from terminating so services keep running. 50 | Thread.Sleep(Timeout.Infinite); 51 | } 52 | catch (Exception e) 53 | { 54 | ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString()); 55 | throw; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /EventCollectorService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EventCollectorService")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("EventCollectorService")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("79684a1f-bc90-4dcf-88c6-bb08a198c462")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /EventCollectorService/Setup.bat: -------------------------------------------------------------------------------- 1 | powershell.exe -ExecutionPolicy Bypass -Command ".\DeleteEtwSessions.ps1" -------------------------------------------------------------------------------- /EventCollectorService/eventFlowConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | // { 4 | // "type": "EventSource", 5 | // "sources": [ 6 | // { "providerName": "Microsoft-Windows-ASPNET" } 7 | // ] 8 | // }, 9 | { 10 | "type": "Trace", 11 | "traceLevel": "Warning" 12 | } 13 | ], 14 | "filters": [ 15 | { 16 | "type": "drop", 17 | "include": "Level == Verbose" 18 | } 19 | ], 20 | "outputs": [ 21 | // Please update the instrumentationKey. 22 | { 23 | "type": "ApplicationInsights", 24 | "instrumentationKey": "00000000-0000-0000-0000-000000000000" 25 | } 26 | ], 27 | "schemaVersion": "2016-08-11", 28 | // "healthReporter": { 29 | // "type": "CsvHealthReporter", 30 | // "logFileFolder": ".", 31 | // "logFilePrefix": "HealthReport", 32 | // "minReportLevel": "Warning", 33 | // "throttlingPeriodMsec": "1000" 34 | // }, 35 | // "settings": { 36 | // "pipelineBufferSize": "1000", 37 | // "maxEventBatchSize": "100", 38 | // "maxBatchDelayMsec": "500", 39 | // "maxConcurrency": "8", 40 | // "pipelineCompletionTimeoutMsec": "30000" 41 | // }, 42 | "extensions": [] 43 | } -------------------------------------------------------------------------------- /EventCollectorService/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Framework.Interfaces/ICircularQueueActor.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System.Collections.Generic; 23 | using System.Threading.Tasks; 24 | using Microsoft.AzureCat.Samples.Entities; 25 | using Microsoft.ServiceFabric.Actors; 26 | 27 | #endregion 28 | 29 | namespace Microsoft.AzureCat.Samples.Framework.Interfaces 30 | { 31 | public interface ICircularQueueActor : IActor 32 | { 33 | /// 34 | /// Gets the count of the items contained in the circular queue. 35 | /// 36 | Task Count { get; } 37 | 38 | /// 39 | /// Adds an object to the end of the circular queue. 40 | /// 41 | /// The object to add to the circular queue. The value cannot be null. 42 | /// The asynchronous result of the operation. 43 | Task EnqueueAsync(Message item); 44 | 45 | /// 46 | /// Removes and returns the object at the beginning of the circular queue. 47 | /// 48 | /// The object that is removed from the beginning of the circular queue. 49 | Task DequeueAsync(); 50 | 51 | /// 52 | /// Removes and returns a collection collection containing all the objects in the circular queue. 53 | /// 54 | /// A collection containing all the objects in the queue. 55 | Task> DequeueAllAsync(); 56 | 57 | /// 58 | /// Returns the object at the beginning of the circular queue without removing it. 59 | /// 60 | /// The object at the beginning of the circular queue. 61 | Task PeekAsync(); 62 | } 63 | } -------------------------------------------------------------------------------- /Framework.Interfaces/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | 13 | [assembly: AssemblyTitle("Framework.Interfaces")] 14 | [assembly: AssemblyDescription("")] 15 | [assembly: AssemblyConfiguration("")] 16 | [assembly: AssemblyCompany("")] 17 | [assembly: AssemblyProduct("Framework.Interfaces")] 18 | [assembly: AssemblyCopyright("Copyright © 2016")] 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | 30 | [assembly: Guid("342acfeb-a2cb-4574-bf14-9078f55041a2")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | 43 | [assembly: AssemblyVersion("1.0.0.0")] 44 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Framework.Interfaces/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Framework/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | 13 | [assembly: AssemblyTitle("StateManagerHelper")] 14 | [assembly: AssemblyDescription("")] 15 | [assembly: AssemblyConfiguration("")] 16 | [assembly: AssemblyCompany("")] 17 | [assembly: AssemblyProduct("StateManagerHelper")] 18 | [assembly: AssemblyCopyright("Copyright © 2016")] 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | 30 | [assembly: Guid("8c0488ce-bac2-43c1-9173-8d1b0362017d")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | 43 | [assembly: AssemblyVersion("1.0.0.0")] 44 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Framework/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Framework/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /GatewayService/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /GatewayService/App_Start/BrowserJsonFormatter.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | #region Using Directives 7 | 8 | #endregion 9 | 10 | using System; 11 | using System.Net.Http.Formatting; 12 | using System.Net.Http.Headers; 13 | using Newtonsoft.Json; 14 | 15 | namespace Microsoft.AzureCat.Samples.GatewayService 16 | { 17 | public class BrowserJsonFormatter : JsonMediaTypeFormatter 18 | { 19 | public BrowserJsonFormatter() 20 | { 21 | SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); 22 | SerializerSettings.Formatting = Formatting.Indented; 23 | } 24 | 25 | public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, 26 | MediaTypeHeaderValue mediaType) 27 | { 28 | base.SetDefaultContentHeaders(type, headers, mediaType); 29 | headers.ContentType = new MediaTypeHeaderValue("application/json"); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /GatewayService/EventSourceFilter.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | 21 | #region Using Directives 22 | 23 | using System; 24 | using System.Diagnostics; 25 | using System.Linq; 26 | using System.Text; 27 | using System.Web.Http.Controllers; 28 | using System.Web.Http.Filters; 29 | using Microsoft.AzureCat.Samples.Framework; 30 | 31 | #endregion 32 | 33 | namespace Microsoft.AzureCat.Samples.GatewayService 34 | { 35 | public class EventSourceFilter : ActionFilterAttribute 36 | { 37 | #region Private Constants 38 | 39 | private const string StopwatchKey = "StopwatchFilter.Value"; 40 | private const string Prefix = "Gateway"; 41 | 42 | #endregion 43 | 44 | #region ActionFilterAttribute Overridden Methods 45 | 46 | public override void OnActionExecuting(HttpActionContext actionContext) 47 | { 48 | base.OnActionExecuting(actionContext); 49 | actionContext.Request.Properties[StopwatchKey] = Stopwatch.StartNew(); 50 | } 51 | 52 | public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) 53 | { 54 | base.OnActionExecuted(actionExecutedContext); 55 | var stopwatch = (Stopwatch) actionExecutedContext.Request.Properties[StopwatchKey]; 56 | stopwatch.Stop(); 57 | ServiceEventSource.Current.RequestComplete(GetRequestName(actionExecutedContext.Request.RequestUri), 58 | actionExecutedContext.Response.IsSuccessStatusCode, 59 | stopwatch.ElapsedMilliseconds, 60 | $"{actionExecutedContext.Response.StatusCode}"); 61 | } 62 | 63 | #endregion 64 | 65 | #region Private Static Methods 66 | 67 | private static string GetRequestName(Uri uri) 68 | { 69 | if (string.IsNullOrEmpty(uri?.AbsolutePath)) 70 | { 71 | return "UNKNOWN"; 72 | } 73 | var segmentList = 74 | uri.Segments.Select(s => s.Replace("/", "")).Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); 75 | var index = 76 | segmentList.FindIndex(s => string.Compare(s, "api", StringComparison.InvariantCultureIgnoreCase) == 0); 77 | var stringBuilder = new StringBuilder(Prefix); 78 | for (var i = index + 1; i < segmentList.Count; i++) 79 | { 80 | stringBuilder.Append(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(segmentList[i])); 81 | } 82 | return stringBuilder.ToString(); 83 | } 84 | 85 | #endregion 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /GatewayService/IOwinAppBuilder.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | #region Using Directives 7 | 8 | #endregion 9 | 10 | using Owin; 11 | 12 | namespace Microsoft.AzureCat.Samples.GatewayService 13 | { 14 | public interface IOwinAppBuilder 15 | { 16 | void Configuration(IAppBuilder appBuilder); 17 | } 18 | } -------------------------------------------------------------------------------- /GatewayService/OwinCommunicationListener.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | #region Using Directives 7 | 8 | #endregion 9 | 10 | using System; 11 | using System.Fabric; 12 | using System.Globalization; 13 | using System.Linq; 14 | using System.Threading; 15 | using System.Threading.Tasks; 16 | using Microsoft.AzureCat.Samples.Framework; 17 | using Microsoft.Owin.Hosting; 18 | using Microsoft.ServiceFabric.Services.Communication.Runtime; 19 | 20 | namespace Microsoft.AzureCat.Samples.GatewayService 21 | { 22 | public class OwinCommunicationListener : ICommunicationListener 23 | { 24 | #region Public Constructor 25 | 26 | public OwinCommunicationListener(string appRoot, IOwinAppBuilder startup, StatelessServiceContext context) 27 | { 28 | this.startup = startup; 29 | this.appRoot = appRoot; 30 | this.context = context; 31 | } 32 | 33 | #endregion 34 | 35 | #region Public Static Properties 36 | 37 | public static string WorkerActorServiceUri { get; private set; } 38 | 39 | #endregion 40 | 41 | #region Private Methods 42 | 43 | private void StopWebServer() 44 | { 45 | if (serverHandle == null) 46 | return; 47 | try 48 | { 49 | serverHandle.Dispose(); 50 | } 51 | catch (ObjectDisposedException) 52 | { 53 | // no-op 54 | } 55 | } 56 | 57 | #endregion 58 | 59 | #region Private Constants 60 | 61 | //************************************ 62 | // Parameters 63 | //************************************ 64 | private const string ConfigurationPackage = "Config"; 65 | private const string ConfigurationSection = "GatewayServiceConfig"; 66 | private const string DeviceActorServiceUriParameter = "WorkerActorServiceUri"; 67 | 68 | #endregion 69 | 70 | #region Private Fields 71 | 72 | private readonly IOwinAppBuilder startup; 73 | private readonly string appRoot; 74 | private readonly StatelessServiceContext context; 75 | private IDisposable serverHandle; 76 | private string listeningAddress; 77 | 78 | #endregion 79 | 80 | #region ICommunicationListener Methods 81 | 82 | public Task OpenAsync(CancellationToken cancellationToken) 83 | { 84 | try 85 | { 86 | // Read settings from the DeviceActorServiceConfig section in the Settings.xml file 87 | var activationContext = context.CodePackageActivationContext; 88 | var config = activationContext.GetConfigurationPackageObject(ConfigurationPackage); 89 | var section = config.Settings.Sections[ConfigurationSection]; 90 | 91 | // Check if a parameter called WorkerActorServiceUri exists in the DeviceActorServiceConfig config section 92 | if (section.Parameters.Any( 93 | p => string.Compare( 94 | p.Name, 95 | DeviceActorServiceUriParameter, 96 | StringComparison.InvariantCultureIgnoreCase) == 0)) 97 | { 98 | var parameter = section.Parameters[DeviceActorServiceUriParameter]; 99 | WorkerActorServiceUri = !string.IsNullOrWhiteSpace(parameter?.Value) 100 | ? parameter.Value 101 | : 102 | // By default, the current service assumes that if no URI is explicitly defined for the actor service 103 | // in the Setting.xml file, the latter is hosted in the same Service Fabric application. 104 | $"fabric:/{context.ServiceName.Segments[1]}WorkerActorService"; 105 | } 106 | else 107 | { 108 | // By default, the current service assumes that if no URI is explicitly defined for the actor service 109 | // in the Setting.xml file, the latter is hosted in the same Service Fabric application. 110 | WorkerActorServiceUri = $"fabric:/{context.ServiceName.Segments[1]}WorkerActorService"; 111 | } 112 | 113 | var serviceEndpoint = context.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); 114 | var port = serviceEndpoint.Port; 115 | 116 | listeningAddress = string.Format( 117 | CultureInfo.InvariantCulture, 118 | "http://+:{0}/{1}", 119 | port, 120 | string.IsNullOrWhiteSpace(appRoot) 121 | ? string.Empty 122 | : appRoot.TrimEnd('/') + '/'); 123 | serverHandle = WebApp.Start(listeningAddress, appBuilder => startup.Configuration(appBuilder)); 124 | var publishAddress = listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); 125 | 126 | ServiceEventSource.Current.Message($"Listening on [{publishAddress}]"); 127 | 128 | return Task.FromResult(publishAddress); 129 | } 130 | catch (Exception ex) 131 | { 132 | ServiceEventSource.Current.Message(ex.Message); 133 | throw; 134 | } 135 | } 136 | 137 | public Task CloseAsync(CancellationToken cancellationToken) 138 | { 139 | ServiceEventSource.Current.Message("Close"); 140 | 141 | StopWebServer(); 142 | 143 | return Task.FromResult(true); 144 | } 145 | 146 | public void Abort() 147 | { 148 | ServiceEventSource.Current.Message("Abort"); 149 | 150 | StopWebServer(); 151 | } 152 | 153 | #endregion 154 | } 155 | } -------------------------------------------------------------------------------- /GatewayService/PackageRoot/Config/Settings.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | 6 |
7 | 8 | 9 | 10 | 11 |
12 |
-------------------------------------------------------------------------------- /GatewayService/PackageRoot/ServiceManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | GatewayService.exe 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /GatewayService/Program.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | #region Using Directives 7 | 8 | #endregion 9 | 10 | using System; 11 | using System.Diagnostics; 12 | using System.Threading; 13 | using Microsoft.AzureCat.Samples.Framework; 14 | using Microsoft.ServiceFabric.Services.Runtime; 15 | 16 | namespace Microsoft.AzureCat.Samples.GatewayService 17 | { 18 | internal static class Program 19 | { 20 | /// 21 | /// This is the entry point of the service host process. 22 | /// 23 | private static void Main() 24 | { 25 | try 26 | { 27 | // The ServiceManifest.XML file defines one or more service type names. 28 | // Registering a service maps a service type name to a .NET type. 29 | // When Service Fabric creates an instance of this service type, 30 | // an instance of the class is created in this host process. 31 | 32 | ServiceRuntime.RegisterServiceAsync( 33 | "GatewayServiceType", 34 | context => new GatewayService(context)).GetAwaiter().GetResult(); 35 | 36 | ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, 37 | typeof(GatewayService).Name); 38 | 39 | // Prevents this host process from terminating so services keep running. 40 | Thread.Sleep(Timeout.Infinite); 41 | } 42 | catch (Exception e) 43 | { 44 | ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString()); 45 | throw; 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /GatewayService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | 13 | [assembly: AssemblyTitle("GatewayService")] 14 | [assembly: AssemblyDescription("")] 15 | [assembly: AssemblyConfiguration("")] 16 | [assembly: AssemblyCompany("")] 17 | [assembly: AssemblyProduct("GatewayService")] 18 | [assembly: AssemblyCopyright("Copyright © 2016")] 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | 30 | [assembly: Guid("5f7b01c9-c373-45b0-b7c8-42eeda51c890")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | 43 | [assembly: AssemblyVersion("1.0.0.0")] 44 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /GatewayService/Startup.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2015 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System.Web.Http; 23 | using Owin; 24 | 25 | #endregion 26 | 27 | namespace Microsoft.AzureCat.Samples.GatewayService 28 | { 29 | public class Startup : IOwinAppBuilder 30 | { 31 | public void Configuration(IAppBuilder app) 32 | { 33 | var httpConfiguration = new HttpConfiguration(); 34 | httpConfiguration.MapHttpAttributeRoutes(); 35 | httpConfiguration.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", 36 | new {id = RouteParameter.Optional}); 37 | httpConfiguration.Filters.Add(new EventSourceFilter()); 38 | httpConfiguration.Formatters.Add(new BrowserJsonFormatter()); 39 | app.UseWebApi(httpConfiguration); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /GatewayService/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Images/ApplicationInsights.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paolosalvatori/servicefabricasynchronouscomputingactors/3418dc77102468e22e76eb3e210338d27c6b7779/Images/ApplicationInsights.png -------------------------------------------------------------------------------- /Images/Architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paolosalvatori/servicefabricasynchronouscomputingactors/3418dc77102468e22e76eb3e210338d27c6b7779/Images/Architecture.png -------------------------------------------------------------------------------- /Images/Client.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paolosalvatori/servicefabricasynchronouscomputingactors/3418dc77102468e22e76eb3e210338d27c6b7779/Images/Client.png -------------------------------------------------------------------------------- /Images/Elasticsearch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paolosalvatori/servicefabricasynchronouscomputingactors/3418dc77102468e22e76eb3e210338d27c6b7779/Images/Elasticsearch.png -------------------------------------------------------------------------------- /Images/Parallel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paolosalvatori/servicefabricasynchronouscomputingactors/3418dc77102468e22e76eb3e210338d27c6b7779/Images/Parallel.png -------------------------------------------------------------------------------- /Images/Sequential.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paolosalvatori/servicefabricasynchronouscomputingactors/3418dc77102468e22e76eb3e210338d27c6b7779/Images/Sequential.png -------------------------------------------------------------------------------- /Images/concurrency.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paolosalvatori/servicefabricasynchronouscomputingactors/3418dc77102468e22e76eb3e210338d27c6b7779/Images/concurrency.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Microsoft Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /LongRunningActors.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paolosalvatori/servicefabricasynchronouscomputingactors/3418dc77102468e22e76eb3e210338d27c6b7779/LongRunningActors.docx -------------------------------------------------------------------------------- /LongRunningActors/ApplicationPackageRoot/ApplicationManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | 32 |
33 |
34 |
35 |
36 | 37 | 38 | 39 |
40 | 41 | 42 | 43 | 44 | 45 |
46 | 47 |
48 |
49 |
50 |
51 |
52 | 53 | 54 | 55 | 56 | 57 |
58 | 59 | 60 | 61 |
62 |
63 |
64 |
65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | [QueueActorService_PlacementConstraints] 76 | 79 | 82 | 83 | 84 | 85 | 86 | 87 | [ProcessorActorService_PlacementConstraints] 88 | 89 | 90 | 91 | 92 | 93 | [WorkerActorService_PlacementConstraints] 94 | 95 | 96 | 97 | 98 | 99 | [GatewayService_PlacementConstraints] 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 |
-------------------------------------------------------------------------------- /LongRunningActors/ApplicationParameters/Cloud.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LongRunningActors/ApplicationParameters/CloudNoPlacementConstraints.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LongRunningActors/ApplicationParameters/Local.1Node.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /LongRunningActors/ApplicationParameters/Local.5Node.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /LongRunningActors/LongRunningActors.sfproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 5814dfeb-b132-4604-b0d4-778bbb79eb18 6 | 1.6 7 | 1.5 8 | 9 | 10 | 11 | Debug 12 | x64 13 | 14 | 15 | Release 16 | x64 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Service Fabric Tools\Microsoft.VisualStudio.Azure.Fabric.ApplicationProject.targets 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /LongRunningActors/PublishProfiles/Cloud.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LongRunningActors/PublishProfiles/Local.1Node.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /LongRunningActors/PublishProfiles/Local.5Node.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /LongRunningActors/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /LongRunningActors/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Powershell/RemoveEtwSessions.ps1: -------------------------------------------------------------------------------- 1 |  2 | # Get all ETW Sessions with a name like EventFlow-EtwInput-* 3 | Get-EtwTraceSession | Where-Object {$_.Name -like "EventFlow-EtwInput-*"} | Format-Table -Property Name 4 | 5 | # Remove all ETW Sessions with a name like EventFlow-EtwInput-* 6 | [string[]]$EtwSessions = Get-EtwTraceSession | Where-Object {$_.Name -like "EventFlow-EtwInput-*"} | Select-Object -ExpandProperty Name 7 | if ($EtwSessions -ne $null) 8 | { 9 | Remove-EtwTraceSession -Name $EtwSessions 10 | } 11 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/DeleteEtwSessions.ps1: -------------------------------------------------------------------------------- 1 | [string[]]$EtwSessions = Get-EtwTraceSession | Where-Object {$_.Name -like "EventFlow-EtwInput-*"} | Select-Object -ExpandProperty Name 2 | if ($EtwSessions -ne $null) 3 | { 4 | Remove-EtwTraceSession -Name $EtwSessions 5 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/PackageRoot/Config/Settings.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 9 |
10 | 11 |
12 |
13 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/PackageRoot/Config/eventFlowConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "type": "ETW", 5 | "providers": [ 6 | { 7 | "providerName": "Microsoft-ServiceFabric-Services", 8 | "level": "servicefabric:/DiagnosticPipelineParametersConfig/TraceLevel" 9 | }, 10 | { 11 | "providerName": "Microsoft-ServiceFabric-Actors", 12 | "level": "servicefabric:/DiagnosticPipelineParametersConfig/TraceLevel" 13 | }, 14 | { 15 | "providerName": "LongRunningActors-Framework-Service", 16 | "level": "servicefabric:/DiagnosticPipelineParametersConfig/TraceLevel" 17 | }, 18 | { 19 | "providerName": "LongRunningActors-Framework-Actor", 20 | "level": "servicefabric:/DiagnosticPipelineParametersConfig/TraceLevel" 21 | } 22 | ] 23 | } 24 | ], 25 | "filters": [ 26 | { 27 | "type": "drop", 28 | "include": "Level == Verbose" 29 | }, 30 | { 31 | "type": "drop", 32 | "include": "ProviderName == System.Threading.Tasks.TplEventSource" 33 | }, 34 | { 35 | "type": "drop", 36 | "include": "ProviderName == Microsoft-ServiceFabric-Services && EventName == ManifestData" 37 | }, 38 | { 39 | "type": "drop", 40 | "include": "ProviderName == Microsoft-ServiceFabric-Actors && EventName == ManifestData" 41 | }, 42 | { 43 | "type": "drop", 44 | "include": "ProviderName == LongRunningActors-Framework-Service && EventName == ManifestData" 45 | }, 46 | { 47 | "type": "drop", 48 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ManifestData" 49 | } 50 | ], 51 | "outputs": [ 52 | { 53 | "type": "EventHub", 54 | "eventHubName": "diagnosticseventfloweventhub", 55 | "connectionString": "", 56 | "filters": [ 57 | { 58 | "type": "drop", 59 | "include": "ProviderName == Microsoft-ServiceFabric-Services || ProviderName == Microsoft-ServiceFabric-Actors" 60 | } 61 | ] 62 | }, 63 | { 64 | "type": "ElasticSearch", 65 | "indexNamePrefix": "LongRunningActors-", 66 | "serviceUri": "http://localhost:9200", 67 | "filters": [ 68 | { 69 | "type": "metadata", 70 | "metadata": "request", 71 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == RequestComplete", 72 | "requestNameProperty": "requestName", 73 | "isSuccessProperty": "isSuccess", 74 | "durationProperty": "duration", 75 | "durationUnit": "milliseconds", 76 | "responseCodeProperty": "response" 77 | }, 78 | { 79 | "type": "metadata", 80 | "metadata": "request", 81 | "include": "ProviderName == LongRunningActors-Framework-Service && EventName == RequestComplete", 82 | "requestNameProperty": "requestName", 83 | "isSuccessProperty": "isSuccess", 84 | "durationProperty": "duration", 85 | "durationUnit": "milliseconds", 86 | "responseCodeProperty": "response" 87 | }, 88 | { 89 | "type": "metadata", 90 | "metadata": "metric", 91 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ReceivedMessage", 92 | "metricName": "ReceivedMessages", 93 | "metricValue": "1.0" 94 | }, 95 | { 96 | "type": "metadata", 97 | "metadata": "metric", 98 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == StoppedMessage", 99 | "metricName": "StoppedMessages", 100 | "metricValue": "1.0" 101 | }, 102 | { 103 | "type": "metadata", 104 | "metadata": "metric", 105 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ProcessedMessage", 106 | "metricName": "ProcessedMessages", 107 | "metricValue": "1.0" 108 | } 109 | ] 110 | }, 111 | { 112 | "type": "ApplicationInsights", 113 | "instrumentationKey": "", 114 | "filters": [ 115 | { 116 | "type": "metadata", 117 | "metadata": "request", 118 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == RequestComplete", 119 | "requestNameProperty": "requestName", 120 | "isSuccessProperty": "isSuccess", 121 | "durationProperty": "duration", 122 | "durationUnit": "milliseconds", 123 | "responseCodeProperty": "response" 124 | }, 125 | { 126 | "type": "metadata", 127 | "metadata": "request", 128 | "include": "ProviderName == LongRunningActors-Framework-Service && EventName == RequestComplete", 129 | "requestNameProperty": "requestName", 130 | "isSuccessProperty": "isSuccess", 131 | "durationProperty": "duration", 132 | "durationUnit": "milliseconds", 133 | "responseCodeProperty": "response" 134 | }, 135 | { 136 | "type": "metadata", 137 | "metadata": "metric", 138 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ReceivedMessage", 139 | "metricName": "ReceivedMessages", 140 | "metricValue": "1.0" 141 | }, 142 | { 143 | "type": "metadata", 144 | "metadata": "metric", 145 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == StoppedMessage", 146 | "metricName": "StoppedMessages", 147 | "metricValue": "1.0" 148 | }, 149 | { 150 | "type": "metadata", 151 | "metadata": "metric", 152 | "include": "ProviderName == LongRunningActors-Framework-Actor && EventName == ProcessedMessage", 153 | "metricName": "ProcessedMessages", 154 | "metricValue": "1.0" 155 | } 156 | ] 157 | } 158 | ], 159 | "schemaVersion": "2016-08-11", 160 | "settings": { 161 | "pipelineBufferSize": "10000", 162 | "maxEventBatchSize": "1000", 163 | "maxBatchDelayMsec": "500", 164 | "maxConcurrency": "10", 165 | "pipelineCompletionTimeoutMsec": "30000" 166 | }, 167 | "extensions": [] 168 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/PackageRoot/ServiceManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Setup.bat 18 | CodePackage 19 | 20 | 21 | 22 | 23 | EventCollectorService.exe 24 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/Program.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | using System; 22 | using System.Diagnostics; 23 | using System.Threading; 24 | using Microsoft.ServiceFabric.Services.Runtime; 25 | using Microsoft.AzureCat.Samples.Framework; 26 | 27 | #endregion 28 | namespace Microsoft.AzureCat.Samples.EventCollectorService 29 | { 30 | internal static class Program 31 | { 32 | /// 33 | /// This is the entry point of the service host process. 34 | /// 35 | private static void Main() 36 | { 37 | try 38 | { 39 | // The ServiceManifest.XML file defines one or more service type names. 40 | // Registering a service maps a service type name to a .NET type. 41 | // When Service Fabric creates an instance of this service type, 42 | // an instance of the class is created in this host process. 43 | 44 | ServiceRuntime.RegisterServiceAsync("EventCollectorServiceType", 45 | context => new EventCollectorService(context)).GetAwaiter().GetResult(); 46 | 47 | ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(EventCollectorService).Name); 48 | 49 | // Prevents this host process from terminating so services keep running. 50 | Thread.Sleep(Timeout.Infinite); 51 | } 52 | catch (Exception e) 53 | { 54 | ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString()); 55 | throw; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EventCollectorService")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("EventCollectorService")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("79684a1f-bc90-4dcf-88c6-bb08a198c462")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/Setup.bat: -------------------------------------------------------------------------------- 1 | powershell.exe -ExecutionPolicy Bypass -Command ".\DeleteEtwSessions.ps1" -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/eventFlowConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | // { 4 | // "type": "EventSource", 5 | // "sources": [ 6 | // { "providerName": "Microsoft-Windows-ASPNET" } 7 | // ] 8 | // }, 9 | { 10 | "type": "Trace", 11 | "traceLevel": "Warning" 12 | } 13 | ], 14 | "filters": [ 15 | { 16 | "type": "drop", 17 | "include": "Level == Verbose" 18 | } 19 | ], 20 | "outputs": [ 21 | // Please update the instrumentationKey. 22 | { 23 | "type": "ApplicationInsights", 24 | "instrumentationKey": "00000000-0000-0000-0000-000000000000" 25 | } 26 | ], 27 | "schemaVersion": "2016-08-11", 28 | // "healthReporter": { 29 | // "type": "CsvHealthReporter", 30 | // "logFileFolder": ".", 31 | // "logFilePrefix": "HealthReport", 32 | // "minReportLevel": "Warning", 33 | // "throttlingPeriodMsec": "1000" 34 | // }, 35 | // "settings": { 36 | // "pipelineBufferSize": "1000", 37 | // "maxEventBatchSize": "100", 38 | // "maxBatchDelayMsec": "500", 39 | // "maxConcurrency": "8", 40 | // "pipelineCompletionTimeoutMsec": "30000" 41 | // }, 42 | "extensions": [] 43 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/EventCollectorService/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/App_Start/BrowserJsonFormatter.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | #region Using Directives 7 | 8 | #endregion 9 | 10 | using System; 11 | using System.Net.Http.Formatting; 12 | using System.Net.Http.Headers; 13 | using Newtonsoft.Json; 14 | 15 | namespace Microsoft.AzureCat.Samples.GatewayService 16 | { 17 | public class BrowserJsonFormatter : JsonMediaTypeFormatter 18 | { 19 | public BrowserJsonFormatter() 20 | { 21 | SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); 22 | SerializerSettings.Formatting = Formatting.Indented; 23 | } 24 | 25 | public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, 26 | MediaTypeHeaderValue mediaType) 27 | { 28 | base.SetDefaultContentHeaders(type, headers, mediaType); 29 | headers.ContentType = new MediaTypeHeaderValue("application/json"); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/EventSourceFilter.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | 21 | #region Using Directives 22 | 23 | using System; 24 | using System.Diagnostics; 25 | using System.Linq; 26 | using System.Text; 27 | using System.Web.Http.Controllers; 28 | using System.Web.Http.Filters; 29 | using Microsoft.AzureCat.Samples.Framework; 30 | 31 | #endregion 32 | 33 | namespace Microsoft.AzureCat.Samples.GatewayService 34 | { 35 | public class EventSourceFilter : ActionFilterAttribute 36 | { 37 | #region Private Constants 38 | 39 | private const string StopwatchKey = "StopwatchFilter.Value"; 40 | private const string Prefix = "Gateway"; 41 | 42 | #endregion 43 | 44 | #region ActionFilterAttribute Overridden Methods 45 | 46 | public override void OnActionExecuting(HttpActionContext actionContext) 47 | { 48 | base.OnActionExecuting(actionContext); 49 | actionContext.Request.Properties[StopwatchKey] = Stopwatch.StartNew(); 50 | } 51 | 52 | public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) 53 | { 54 | base.OnActionExecuted(actionExecutedContext); 55 | var stopwatch = (Stopwatch) actionExecutedContext.Request.Properties[StopwatchKey]; 56 | stopwatch.Stop(); 57 | ServiceEventSource.Current.RequestComplete(GetRequestName(actionExecutedContext.Request.RequestUri), 58 | actionExecutedContext.Response.IsSuccessStatusCode, 59 | stopwatch.ElapsedMilliseconds, 60 | actionExecutedContext.Response.Content.ReadAsStringAsync().Result); 61 | } 62 | 63 | #endregion 64 | 65 | #region Private Static Methods 66 | 67 | private static string GetRequestName(Uri uri) 68 | { 69 | if (string.IsNullOrEmpty(uri?.AbsolutePath)) 70 | { 71 | return "UNKNOWN"; 72 | } 73 | var segmentList = 74 | uri.Segments.Select(s => s.Replace("/", "")).Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); 75 | var index = 76 | segmentList.FindIndex(s => string.Compare(s, "api", StringComparison.InvariantCultureIgnoreCase) == 0); 77 | var stringBuilder = new StringBuilder(Prefix); 78 | for (var i = index + 1; i < segmentList.Count; i++) 79 | { 80 | stringBuilder.Append(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(segmentList[i])); 81 | } 82 | return stringBuilder.ToString(); 83 | } 84 | 85 | #endregion 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/IOwinAppBuilder.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | #region Using Directives 7 | 8 | #endregion 9 | 10 | using Owin; 11 | 12 | namespace Microsoft.AzureCat.Samples.GatewayService 13 | { 14 | public interface IOwinAppBuilder 15 | { 16 | void Configuration(IAppBuilder appBuilder); 17 | } 18 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/OwinCommunicationListener.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | #region Using Directives 7 | 8 | #endregion 9 | 10 | using System; 11 | using System.Fabric; 12 | using System.Globalization; 13 | using System.Linq; 14 | using System.Threading; 15 | using System.Threading.Tasks; 16 | using Microsoft.AzureCat.Samples.Framework; 17 | using Microsoft.Owin.Hosting; 18 | using Microsoft.ServiceFabric.Services.Communication.Runtime; 19 | 20 | namespace Microsoft.AzureCat.Samples.GatewayService 21 | { 22 | public class OwinCommunicationListener : ICommunicationListener 23 | { 24 | #region Public Constructor 25 | 26 | public OwinCommunicationListener(string appRoot, IOwinAppBuilder startup, StatelessServiceContext context) 27 | { 28 | this.startup = startup; 29 | this.appRoot = appRoot; 30 | this.context = context; 31 | } 32 | 33 | #endregion 34 | 35 | #region Public Static Properties 36 | 37 | public static string WorkerActorServiceUri { get; private set; } 38 | 39 | #endregion 40 | 41 | #region Private Methods 42 | 43 | private void StopWebServer() 44 | { 45 | if (serverHandle == null) 46 | return; 47 | try 48 | { 49 | serverHandle.Dispose(); 50 | } 51 | catch (ObjectDisposedException) 52 | { 53 | // no-op 54 | } 55 | } 56 | 57 | #endregion 58 | 59 | #region Private Constants 60 | 61 | //************************************ 62 | // Parameters 63 | //************************************ 64 | private const string ConfigurationPackage = "Config"; 65 | private const string ConfigurationSection = "GatewayServiceConfig"; 66 | private const string DeviceActorServiceUriParameter = "WorkerActorServiceUri"; 67 | 68 | #endregion 69 | 70 | #region Private Fields 71 | 72 | private readonly IOwinAppBuilder startup; 73 | private readonly string appRoot; 74 | private readonly StatelessServiceContext context; 75 | private IDisposable serverHandle; 76 | private string listeningAddress; 77 | 78 | #endregion 79 | 80 | #region ICommunicationListener Methods 81 | 82 | public Task OpenAsync(CancellationToken cancellationToken) 83 | { 84 | try 85 | { 86 | // Read settings from the DeviceActorServiceConfig section in the Settings.xml file 87 | var activationContext = context.CodePackageActivationContext; 88 | var config = activationContext.GetConfigurationPackageObject(ConfigurationPackage); 89 | var section = config.Settings.Sections[ConfigurationSection]; 90 | 91 | // Check if a parameter called WorkerActorServiceUri exists in the DeviceActorServiceConfig config section 92 | if (section.Parameters.Any( 93 | p => string.Compare( 94 | p.Name, 95 | DeviceActorServiceUriParameter, 96 | StringComparison.InvariantCultureIgnoreCase) == 0)) 97 | { 98 | var parameter = section.Parameters[DeviceActorServiceUriParameter]; 99 | WorkerActorServiceUri = !string.IsNullOrWhiteSpace(parameter?.Value) 100 | ? parameter.Value 101 | : 102 | // By default, the current service assumes that if no URI is explicitly defined for the actor service 103 | // in the Setting.xml file, the latter is hosted in the same Service Fabric application. 104 | $"fabric:/{context.ServiceName.Segments[1]}WorkerActorService"; 105 | } 106 | else 107 | { 108 | // By default, the current service assumes that if no URI is explicitly defined for the actor service 109 | // in the Setting.xml file, the latter is hosted in the same Service Fabric application. 110 | WorkerActorServiceUri = $"fabric:/{context.ServiceName.Segments[1]}WorkerActorService"; 111 | } 112 | 113 | var serviceEndpoint = context.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); 114 | var port = serviceEndpoint.Port; 115 | 116 | listeningAddress = string.Format( 117 | CultureInfo.InvariantCulture, 118 | "http://+:{0}/{1}", 119 | port, 120 | string.IsNullOrWhiteSpace(appRoot) 121 | ? string.Empty 122 | : appRoot.TrimEnd('/') + '/'); 123 | serverHandle = WebApp.Start(listeningAddress, appBuilder => startup.Configuration(appBuilder)); 124 | var publishAddress = listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); 125 | 126 | ServiceEventSource.Current.Message($"Listening on [{publishAddress}]"); 127 | 128 | return Task.FromResult(publishAddress); 129 | } 130 | catch (Exception ex) 131 | { 132 | ServiceEventSource.Current.Message(ex.Message); 133 | throw; 134 | } 135 | } 136 | 137 | public Task CloseAsync(CancellationToken cancellationToken) 138 | { 139 | ServiceEventSource.Current.Message("Close"); 140 | 141 | StopWebServer(); 142 | 143 | return Task.FromResult(true); 144 | } 145 | 146 | public void Abort() 147 | { 148 | ServiceEventSource.Current.Message("Abort"); 149 | 150 | StopWebServer(); 151 | } 152 | 153 | #endregion 154 | } 155 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/PackageRoot/Config/Settings.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | 6 |
7 | 8 | 9 | 10 | 11 |
12 |
-------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/PackageRoot/ServiceManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | GatewayService.exe 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/Program.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | #region Using Directives 7 | 8 | #endregion 9 | 10 | using System; 11 | using System.Diagnostics; 12 | using System.Threading; 13 | using Microsoft.AzureCat.Samples.Framework; 14 | using Microsoft.ServiceFabric.Services.Runtime; 15 | 16 | namespace Microsoft.AzureCat.Samples.GatewayService 17 | { 18 | internal static class Program 19 | { 20 | /// 21 | /// This is the entry point of the service host process. 22 | /// 23 | private static void Main() 24 | { 25 | try 26 | { 27 | // The ServiceManifest.XML file defines one or more service type names. 28 | // Registering a service maps a service type name to a .NET type. 29 | // When Service Fabric creates an instance of this service type, 30 | // an instance of the class is created in this host process. 31 | 32 | ServiceRuntime.RegisterServiceAsync( 33 | "GatewayServiceType", 34 | context => new GatewayService(context)).GetAwaiter().GetResult(); 35 | 36 | ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, 37 | typeof(GatewayService).Name); 38 | 39 | // Prevents this host process from terminating so services keep running. 40 | Thread.Sleep(Timeout.Infinite); 41 | } 42 | catch (Exception e) 43 | { 44 | ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString()); 45 | throw; 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | 13 | [assembly: AssemblyTitle("GatewayService")] 14 | [assembly: AssemblyDescription("")] 15 | [assembly: AssemblyConfiguration("")] 16 | [assembly: AssemblyCompany("")] 17 | [assembly: AssemblyProduct("GatewayService")] 18 | [assembly: AssemblyCopyright("Copyright © 2016")] 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | 30 | [assembly: Guid("5f7b01c9-c373-45b0-b7c8-42eeda51c890")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | 43 | [assembly: AssemblyVersion("1.0.0.0")] 44 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/Startup.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2015 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System.Web.Http; 23 | using Owin; 24 | 25 | #endregion 26 | 27 | namespace Microsoft.AzureCat.Samples.GatewayService 28 | { 29 | public class Startup : IOwinAppBuilder 30 | { 31 | public void Configuration(IAppBuilder app) 32 | { 33 | var httpConfiguration = new HttpConfiguration(); 34 | httpConfiguration.MapHttpAttributeRoutes(); 35 | httpConfiguration.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", 36 | new {id = RouteParameter.Optional}); 37 | httpConfiguration.Filters.Add(new EventSourceFilter()); 38 | httpConfiguration.Formatters.Add(new BrowserJsonFormatter()); 39 | app.UseWebApi(httpConfiguration); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/GatewayService/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/WorkerActorService/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/WorkerActorService/PackageRoot/Config/Settings.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 |
4 | 5 | 6 |
7 |
8 | 9 |
10 |
11 | 12 | 13 |
14 |
15 | 16 |
17 |
18 | 19 | 20 |
21 |
22 | 23 |
24 |
25 | 26 |
27 |
-------------------------------------------------------------------------------- /ServiceFabricServicesBackup/WorkerActorService/PackageRoot/ServiceManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | WorkerActorService.exe 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/WorkerActorService/Program.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System; 23 | using System.Threading; 24 | using Microsoft.AzureCat.Samples.Framework; 25 | using Microsoft.ServiceFabric.Actors.Runtime; 26 | 27 | #endregion 28 | 29 | namespace Microsoft.AzureCat.Samples.WorkerActorService 30 | { 31 | internal static class Program 32 | { 33 | /// 34 | /// This is the entry point of the service host process. 35 | /// 36 | private static void Main() 37 | { 38 | try 39 | { 40 | // Create default garbage collection settings for all the actor types 41 | var settings = new ActorGarbageCollectionSettings(300, 60); 42 | 43 | // These lines register three Actor Services to host your actor classes with the Service Fabric runtime. 44 | // The contents of your ServiceManifest.xml and ApplicationManifest.xml files 45 | // are automatically populated when you build this project. 46 | // For more information, see http://aka.ms/servicefabricactorsplatform 47 | 48 | ActorRuntime.RegisterActorAsync( 49 | (context, actorType) => new WorkerActorService(context, 50 | actorType, 51 | (s, i) => new WorkerActor(s, i), 52 | null, 53 | null, 54 | new ActorServiceSettings 55 | { 56 | ActorGarbageCollectionSettings = settings 57 | })).GetAwaiter().GetResult(); 58 | 59 | ActorRuntime.RegisterActorAsync( 60 | (context, actorType) => new ActorService(context, 61 | actorType, 62 | (s, i) => new QueueActor(s, i), 63 | null, 64 | null, 65 | new ActorServiceSettings 66 | { 67 | ActorGarbageCollectionSettings = settings 68 | })).GetAwaiter().GetResult(); 69 | 70 | ActorRuntime.RegisterActorAsync( 71 | (context, actorType) => new ActorService(context, 72 | actorType, 73 | (s, i) => new ProcessorActor(s, i), 74 | null, 75 | null, 76 | new ActorServiceSettings 77 | { 78 | ActorGarbageCollectionSettings = settings 79 | })).GetAwaiter().GetResult(); 80 | 81 | Thread.Sleep(Timeout.Infinite); 82 | } 83 | catch (Exception e) 84 | { 85 | ActorEventSource.Current.ActorHostInitializationFailed(e); 86 | throw; 87 | } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/WorkerActorService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | 13 | [assembly: AssemblyTitle("WorkerActorService")] 14 | [assembly: AssemblyDescription("")] 15 | [assembly: AssemblyConfiguration("")] 16 | [assembly: AssemblyCompany("")] 17 | [assembly: AssemblyProduct("WorkerActorService")] 18 | [assembly: AssemblyCopyright("Copyright © 2016")] 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | 30 | [assembly: Guid("e74a9019-a1ae-4c26-8119-8d6187c0a220")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | 43 | [assembly: AssemblyVersion("1.0.0.0")] 44 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/WorkerActorService/QueueActor.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using Microsoft.AzureCat.Samples.Framework; 23 | using Microsoft.AzureCat.Samples.WorkerActorService.Interfaces; 24 | using Microsoft.ServiceFabric.Actors; 25 | using Microsoft.ServiceFabric.Actors.Runtime; 26 | 27 | #endregion 28 | 29 | namespace Microsoft.AzureCat.Samples.WorkerActorService 30 | { 31 | /// 32 | /// This actor can be used to start, stop and monitor long running processes. 33 | /// 34 | [ActorService(Name = "QueueActorService")] 35 | [StatePersistence(StatePersistence.Persisted)] 36 | internal class QueueActor : CircularQueueActor, IQueueActor 37 | { 38 | #region Public Constructor 39 | 40 | /// 41 | /// Initializes a new instance of QueueActor 42 | /// 43 | /// The Microsoft.ServiceFabric.Actors.Runtime.ActorService that will host this actor instance. 44 | /// The Microsoft.ServiceFabric.Actors.ActorId for this actor instance. 45 | public QueueActor(ActorService actorService, ActorId actorId) 46 | : base(actorService, actorId) 47 | { 48 | } 49 | 50 | #endregion 51 | } 52 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/WorkerActorService/WorkerActorService.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at https://github.com/paolosalvatori. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System; 23 | using System.Fabric; 24 | using System.Linq; 25 | using Microsoft.AzureCat.Samples.Framework; 26 | using Microsoft.ServiceFabric.Actors; 27 | using Microsoft.ServiceFabric.Actors.Runtime; 28 | 29 | #endregion 30 | 31 | namespace Microsoft.AzureCat.Samples.WorkerActorService 32 | { 33 | public class WorkerActorService : ActorService 34 | { 35 | #region Private Constants 36 | 37 | //************************************ 38 | // Parameters 39 | //************************************ 40 | private const string ConfigurationPackage = "Config"; 41 | private const string ConfigurationSection = "WorkerActorCustomConfig"; 42 | private const string QueueLengthParameter = "QueueLength"; 43 | 44 | //************************************ 45 | // Constants 46 | //************************************ 47 | private const int DefaultQueueLength = 100; 48 | 49 | #endregion 50 | 51 | #region Public Constructor 52 | 53 | public WorkerActorService(StatefulServiceContext context, 54 | ActorTypeInformation typeInfo, 55 | Func actorFactory, 56 | Func stateManagerFactory, 57 | IActorStateProvider stateProvider = null, 58 | ActorServiceSettings settings = null) 59 | : base(context, typeInfo, actorFactory, stateManagerFactory, stateProvider, settings) 60 | { 61 | // Read Settings 62 | ReadSettings(context.CodePackageActivationContext.GetConfigurationPackageObject(ConfigurationPackage)); 63 | 64 | // Creates event handlers for configuration changes 65 | context.CodePackageActivationContext.ConfigurationPackageAddedEvent += 66 | CodePackageActivationContext_ConfigurationPackageAddedEvent; 67 | context.CodePackageActivationContext.ConfigurationPackageModifiedEvent += 68 | CodePackageActivationContext_ConfigurationPackageModifiedEvent; 69 | context.CodePackageActivationContext.ConfigurationPackageRemovedEvent += 70 | CodePackageActivationContext_ConfigurationPackageRemovedEvent; 71 | } 72 | 73 | #endregion 74 | 75 | #region Public Properties 76 | 77 | /// 78 | /// Gets or sets the queue length 79 | /// 80 | public int QueueLength { get; set; } 81 | 82 | #endregion 83 | 84 | #region Private Methods 85 | 86 | private void CodePackageActivationContext_ConfigurationPackageAddedEvent(object sender, 87 | PackageAddedEventArgs e) 88 | { 89 | if (e == null) 90 | { 91 | throw new ArgumentNullException(nameof(e)); 92 | } 93 | 94 | ReadSettings(e.Package); 95 | } 96 | 97 | private void CodePackageActivationContext_ConfigurationPackageModifiedEvent(object sender, 98 | PackageModifiedEventArgs e) 99 | { 100 | if (e == null) 101 | { 102 | throw new ArgumentNullException(nameof(e)); 103 | } 104 | 105 | ReadSettings(e.NewPackage); 106 | } 107 | 108 | private void CodePackageActivationContext_ConfigurationPackageRemovedEvent(object sender, 109 | PackageRemovedEventArgs e) 110 | { 111 | if (e == null) 112 | { 113 | throw new ArgumentNullException(nameof(e)); 114 | } 115 | 116 | ReadSettings(e.Package); 117 | } 118 | 119 | private void ReadSettings(ConfigurationPackage configurationPackage) 120 | { 121 | try 122 | { 123 | if (configurationPackage == null) 124 | { 125 | throw new ArgumentException( 126 | $"The ConfigurationPackage of the [{Context.ServiceName}-{Context.ReplicaId}] service replica is null."); 127 | } 128 | 129 | if (configurationPackage.Settings == null || 130 | !configurationPackage.Settings.Sections.Contains(ConfigurationSection)) 131 | { 132 | throw new ArgumentException( 133 | $"The ConfigurationPackage of the [{Context.ServiceName}-{Context.ReplicaId}] service replica does not contain any configuration section called [{ConfigurationSection}]."); 134 | } 135 | 136 | var section = configurationPackage.Settings.Sections[ConfigurationSection]; 137 | 138 | // Check if a parameter called QueueLength exists in the ActorConfig config section 139 | if (section.Parameters.Any( 140 | p => string.Compare( 141 | p.Name, 142 | QueueLengthParameter, 143 | StringComparison.InvariantCultureIgnoreCase) == 0)) 144 | { 145 | int queueLength; 146 | var parameter = section.Parameters[QueueLengthParameter]; 147 | if (!string.IsNullOrWhiteSpace(parameter.Value) && 148 | int.TryParse(parameter.Value, out queueLength)) 149 | { 150 | QueueLength = queueLength; 151 | } 152 | else 153 | { 154 | QueueLength = DefaultQueueLength; 155 | } 156 | } 157 | 158 | // Logs event 159 | ServiceEventSource.Current.Message($"[{QueueLengthParameter}] = [{QueueLength}]"); 160 | } 161 | catch (Exception ex) 162 | { 163 | ServiceEventSource.Current.Message(ex.Message); 164 | throw; 165 | } 166 | } 167 | #endregion 168 | } 169 | } -------------------------------------------------------------------------------- /ServiceFabricServicesBackup/WorkerActorService/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /TestClient/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /TestClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | 13 | [assembly: AssemblyTitle("TestClient")] 14 | [assembly: AssemblyDescription("")] 15 | [assembly: AssemblyConfiguration("")] 16 | [assembly: AssemblyCompany("")] 17 | [assembly: AssemblyProduct("TestClient")] 18 | [assembly: AssemblyCopyright("Copyright © 2016")] 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | 30 | [assembly: Guid("b34490f9-c4df-4c0a-b6b1-bc48bceb61e8")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | 43 | [assembly: AssemblyVersion("1.0.0.0")] 44 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /TestClient/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Visio/LongRunningActors.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paolosalvatori/servicefabricasynchronouscomputingactors/3418dc77102468e22e76eb3e210338d27c6b7779/Visio/LongRunningActors.vsdx -------------------------------------------------------------------------------- /WorkerActorService.Interfaces/IProcessorActor.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System.Threading; 23 | using System.Threading.Tasks; 24 | using Microsoft.AzureCat.Samples.Entities; 25 | using Microsoft.ServiceFabric.Actors; 26 | 27 | #endregion 28 | 29 | namespace Microsoft.AzureCat.Samples.WorkerActorService.Interfaces 30 | { 31 | /// 32 | /// This interface represents the actions a client app can perform on an actor. 33 | /// It MUST derive from IActor and all methods MUST return a Task. 34 | /// 35 | public interface IProcessorActor : IActor 36 | { 37 | /// 38 | /// Starts processing messages from the work queue in a sequential order. 39 | /// 40 | /// This CancellationToken is used to stop message processing. 41 | /// 42 | Task ProcessSequentialMessagesAsync(CancellationToken cancellationToken); 43 | 44 | /// 45 | /// Starts processing messages from the work queue in a parallel order. 46 | /// 47 | /// The actor id as string of thr worker actor that invoked the processor actor 48 | /// The message to process 49 | /// This CancellationToken is used to stop message processing. 50 | /// 51 | Task ProcessParallelMessagesAsync(string workerId, Message message, CancellationToken cancellationToken); 52 | } 53 | } -------------------------------------------------------------------------------- /WorkerActorService.Interfaces/IQueueActor.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using Microsoft.AzureCat.Samples.Framework.Interfaces; 23 | 24 | #endregion 25 | 26 | namespace Microsoft.AzureCat.Samples.WorkerActorService.Interfaces 27 | { 28 | /// 29 | /// This interface represents the actions a client app can perform on an actor. 30 | /// It MUST derive from IActor and all methods MUST return a Task. 31 | /// 32 | public interface IQueueActor : ICircularQueueActor 33 | { 34 | } 35 | } -------------------------------------------------------------------------------- /WorkerActorService.Interfaces/IWorkerActor.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System.Threading.Tasks; 23 | using Microsoft.AzureCat.Samples.Entities; 24 | using Microsoft.ServiceFabric.Actors; 25 | 26 | #endregion 27 | 28 | namespace Microsoft.AzureCat.Samples.WorkerActorService.Interfaces 29 | { 30 | /// 31 | /// This interface represents the actions a client app can perform on an actor. 32 | /// It MUST derive from IActor and all methods MUST return a Task. 33 | /// 34 | public interface IWorkerActor : IActor, IActorEventPublisher 35 | { 36 | /// 37 | /// Starts processing a message in sequential order. If the message parameter is null, 38 | /// the method simply starts the sequential processing loop. 39 | /// 40 | /// The message to process. 41 | /// True if the operation completes successfully, false otherwise. 42 | Task StartSequentialProcessingAsync(Message message); 43 | 44 | /// 45 | /// Starts processing a message on a separate task. 46 | /// 47 | /// The message to process. 48 | /// True if the operation completes successfully, false otherwise. 49 | Task StartParallelProcessingAsync(Message message); 50 | 51 | /// 52 | /// Stops the sequential processing task. 53 | /// 54 | /// True if the operation completes successfully, false otherwise. 55 | Task StopSequentialProcessingAsync(); 56 | 57 | /// 58 | /// Stops the elaboration of a specific message identified by its id. 59 | /// 60 | /// The message id. 61 | /// True if the operation completes successfully, false otherwise. 62 | Task StopParallelProcessingAsync(string messageId); 63 | 64 | /// 65 | /// Used by the sequential processing task to signal the completion 66 | /// of a message processing and return computed results. 67 | /// 68 | /// The message id. 69 | /// The message processing result. 70 | /// True if the operation completes successfully, false otherwise. 71 | Task ReturnSequentialProcessingAsync(string messageId, long returnValue); 72 | 73 | /// 74 | /// Used by the parallel processing task to signal the completion 75 | /// of a message processing and return computed results. 76 | /// 77 | /// The message id. 78 | /// The message processing result. 79 | /// True if the operation completes successfully, false otherwise. 80 | Task ReturnParallelProcessingAsync(string messageId, long returnValue); 81 | 82 | /// 83 | /// Checks if the sequential processing task is running. 84 | /// 85 | /// True if sequential processing task is still running, false otherwise. 86 | Task IsSequentialProcessingRunningAsync(); 87 | 88 | /// 89 | /// Checks if the elaboration of a given message is running. 90 | /// 91 | /// The message id. 92 | /// True if the elaboration of the message is still running, false otherwise. 93 | Task IsParallelProcessingRunningAsync(string messageId); 94 | 95 | /// 96 | /// Sets sequential processing state. 97 | /// 98 | /// True if the sequential processing task is still running, false otherwise. 99 | /// True if the operation completes successfully, false otherwise. 100 | Task CloseSequentialProcessingAsync(bool runningState); 101 | 102 | /// 103 | /// Gets the worker actor statistics from its internal state. 104 | /// 105 | /// The worker actor statistics. 106 | Task GetProcessingStatisticsAsync(); 107 | } 108 | } -------------------------------------------------------------------------------- /WorkerActorService.Interfaces/IWorkerActorEvents.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2017 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using Microsoft.ServiceFabric.Actors; 23 | 24 | #endregion 25 | 26 | namespace Microsoft.AzureCat.Samples.WorkerActorService.Interfaces 27 | { 28 | /// 29 | /// Occurs when a message has been processed. 30 | /// This event is raised when the processor returns a value. 31 | /// 32 | public interface IWorkerActorEvents : IActorEvents 33 | { 34 | void MessageProcessingCompleted(string messageId, long returnValue); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /WorkerActorService.Interfaces/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | 13 | [assembly: AssemblyTitle("WorkerActorService.Interfaces")] 14 | [assembly: AssemblyDescription("")] 15 | [assembly: AssemblyConfiguration("")] 16 | [assembly: AssemblyCompany("")] 17 | [assembly: AssemblyProduct("WorkerActorService.Interfaces")] 18 | [assembly: AssemblyCopyright("Copyright © 2016")] 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | 30 | [assembly: Guid("cebd3ae2-3d51-45d1-b11b-12fc3cf446f7")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | 43 | [assembly: AssemblyVersion("1.0.0.0")] 44 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /WorkerActorService.Interfaces/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /WorkerActorService.Interfaces/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /WorkerActorService/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /WorkerActorService/PackageRoot/Config/Settings.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 |
4 | 5 | 6 |
7 |
8 | 9 |
10 |
11 | 12 | 13 |
14 |
15 | 16 |
17 |
18 | 19 | 20 |
21 |
22 | 23 |
24 |
25 | 26 |
27 |
-------------------------------------------------------------------------------- /WorkerActorService/PackageRoot/ServiceManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | WorkerActorService.exe 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /WorkerActorService/Program.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System; 23 | using System.Threading; 24 | using Microsoft.AzureCat.Samples.Framework; 25 | using Microsoft.ServiceFabric.Actors.Runtime; 26 | 27 | #endregion 28 | 29 | namespace Microsoft.AzureCat.Samples.WorkerActorService 30 | { 31 | internal static class Program 32 | { 33 | /// 34 | /// This is the entry point of the service host process. 35 | /// 36 | private static void Main() 37 | { 38 | try 39 | { 40 | // Create default garbage collection settings for all the actor types 41 | var settings = new ActorGarbageCollectionSettings(300, 60); 42 | 43 | // These lines register three Actor Services to host your actor classes with the Service Fabric runtime. 44 | // The contents of your ServiceManifest.xml and ApplicationManifest.xml files 45 | // are automatically populated when you build this project. 46 | // For more information, see http://aka.ms/servicefabricactorsplatform 47 | 48 | ActorRuntime.RegisterActorAsync( 49 | (context, actorType) => new WorkerActorService(context, 50 | actorType, 51 | (s, i) => new WorkerActor(s, i), 52 | null, 53 | null, 54 | new ActorServiceSettings 55 | { 56 | ActorGarbageCollectionSettings = settings 57 | })).GetAwaiter().GetResult(); 58 | 59 | ActorRuntime.RegisterActorAsync( 60 | (context, actorType) => new ActorService(context, 61 | actorType, 62 | (s, i) => new QueueActor(s, i), 63 | null, 64 | null, 65 | new ActorServiceSettings 66 | { 67 | ActorGarbageCollectionSettings = settings 68 | })).GetAwaiter().GetResult(); 69 | 70 | ActorRuntime.RegisterActorAsync( 71 | (context, actorType) => new ActorService(context, 72 | actorType, 73 | (s, i) => new ProcessorActor(s, i), 74 | null, 75 | null, 76 | new ActorServiceSettings 77 | { 78 | ActorGarbageCollectionSettings = settings 79 | })).GetAwaiter().GetResult(); 80 | 81 | Thread.Sleep(Timeout.Infinite); 82 | } 83 | catch (Exception e) 84 | { 85 | ActorEventSource.Current.ActorHostInitializationFailed(e); 86 | throw; 87 | } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /WorkerActorService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------ 2 | // Copyright (c) Microsoft Corporation. All rights reserved. 3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. 4 | // ------------------------------------------------------------ 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | 13 | [assembly: AssemblyTitle("WorkerActorService")] 14 | [assembly: AssemblyDescription("")] 15 | [assembly: AssemblyConfiguration("")] 16 | [assembly: AssemblyCompany("")] 17 | [assembly: AssemblyProduct("WorkerActorService")] 18 | [assembly: AssemblyCopyright("Copyright © 2016")] 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | 26 | [assembly: ComVisible(false)] 27 | 28 | // The following GUID is for the ID of the typelib if this project is exposed to COM 29 | 30 | [assembly: Guid("e74a9019-a1ae-4c26-8119-8d6187c0a220")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | 43 | [assembly: AssemblyVersion("1.0.0.0")] 44 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /WorkerActorService/QueueActor.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at http://blogs.msdn.com/b/paolos/. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using Microsoft.AzureCat.Samples.Framework; 23 | using Microsoft.AzureCat.Samples.WorkerActorService.Interfaces; 24 | using Microsoft.ServiceFabric.Actors; 25 | using Microsoft.ServiceFabric.Actors.Runtime; 26 | 27 | #endregion 28 | 29 | namespace Microsoft.AzureCat.Samples.WorkerActorService 30 | { 31 | /// 32 | /// This actor can be used to start, stop and monitor long running processes. 33 | /// 34 | [ActorService(Name = "QueueActorService")] 35 | [StatePersistence(StatePersistence.Persisted)] 36 | internal class QueueActor : CircularQueueActor, IQueueActor 37 | { 38 | #region Public Constructor 39 | 40 | /// 41 | /// Initializes a new instance of QueueActor 42 | /// 43 | /// The Microsoft.ServiceFabric.Actors.Runtime.ActorService that will host this actor instance. 44 | /// The Microsoft.ServiceFabric.Actors.ActorId for this actor instance. 45 | public QueueActor(ActorService actorService, ActorId actorId) 46 | : base(actorService, actorId) 47 | { 48 | } 49 | 50 | #endregion 51 | } 52 | } -------------------------------------------------------------------------------- /WorkerActorService/WorkerActorService.cs: -------------------------------------------------------------------------------- 1 | #region Copyright 2 | 3 | //======================================================================================= 4 | // Microsoft Azure Customer Advisory Team 5 | // 6 | // This sample is supplemental to the technical guidance published on the community 7 | // blog at https://github.com/paolosalvatori. 8 | // 9 | // Author: Paolo Salvatori 10 | //======================================================================================= 11 | // Copyright © 2016 Microsoft Corporation. All rights reserved. 12 | // 13 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 14 | // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 15 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. YOU BEAR THE RISK OF USING IT. 16 | //======================================================================================= 17 | 18 | #endregion 19 | 20 | #region Using Directives 21 | 22 | using System; 23 | using System.Fabric; 24 | using System.Linq; 25 | using Microsoft.AzureCat.Samples.Framework; 26 | using Microsoft.ServiceFabric.Actors; 27 | using Microsoft.ServiceFabric.Actors.Runtime; 28 | 29 | #endregion 30 | 31 | namespace Microsoft.AzureCat.Samples.WorkerActorService 32 | { 33 | public class WorkerActorService : ActorService 34 | { 35 | #region Private Constants 36 | 37 | //************************************ 38 | // Parameters 39 | //************************************ 40 | private const string ConfigurationPackage = "Config"; 41 | private const string ConfigurationSection = "WorkerActorCustomConfig"; 42 | private const string QueueLengthParameter = "QueueLength"; 43 | 44 | //************************************ 45 | // Constants 46 | //************************************ 47 | private const int DefaultQueueLength = 100; 48 | 49 | #endregion 50 | 51 | #region Public Constructor 52 | 53 | public WorkerActorService(StatefulServiceContext context, 54 | ActorTypeInformation typeInfo, 55 | Func actorFactory, 56 | Func stateManagerFactory, 57 | IActorStateProvider stateProvider = null, 58 | ActorServiceSettings settings = null) 59 | : base(context, typeInfo, actorFactory, stateManagerFactory, stateProvider, settings) 60 | { 61 | // Read Settings 62 | ReadSettings(context.CodePackageActivationContext.GetConfigurationPackageObject(ConfigurationPackage)); 63 | 64 | // Creates event handlers for configuration changes 65 | context.CodePackageActivationContext.ConfigurationPackageAddedEvent += 66 | CodePackageActivationContext_ConfigurationPackageAddedEvent; 67 | context.CodePackageActivationContext.ConfigurationPackageModifiedEvent += 68 | CodePackageActivationContext_ConfigurationPackageModifiedEvent; 69 | context.CodePackageActivationContext.ConfigurationPackageRemovedEvent += 70 | CodePackageActivationContext_ConfigurationPackageRemovedEvent; 71 | } 72 | 73 | #endregion 74 | 75 | #region Public Properties 76 | 77 | /// 78 | /// Gets or sets the queue length 79 | /// 80 | public int QueueLength { get; set; } 81 | 82 | #endregion 83 | 84 | #region Private Methods 85 | 86 | private void CodePackageActivationContext_ConfigurationPackageAddedEvent(object sender, 87 | PackageAddedEventArgs e) 88 | { 89 | if (e == null) 90 | { 91 | throw new ArgumentNullException(nameof(e)); 92 | } 93 | 94 | ReadSettings(e.Package); 95 | } 96 | 97 | private void CodePackageActivationContext_ConfigurationPackageModifiedEvent(object sender, 98 | PackageModifiedEventArgs e) 99 | { 100 | if (e == null) 101 | { 102 | throw new ArgumentNullException(nameof(e)); 103 | } 104 | 105 | ReadSettings(e.NewPackage); 106 | } 107 | 108 | private void CodePackageActivationContext_ConfigurationPackageRemovedEvent(object sender, 109 | PackageRemovedEventArgs e) 110 | { 111 | if (e == null) 112 | { 113 | throw new ArgumentNullException(nameof(e)); 114 | } 115 | 116 | ReadSettings(e.Package); 117 | } 118 | 119 | private void ReadSettings(ConfigurationPackage configurationPackage) 120 | { 121 | try 122 | { 123 | if (configurationPackage == null) 124 | { 125 | throw new ArgumentException( 126 | $"The ConfigurationPackage of the [{Context.ServiceName}-{Context.ReplicaId}] service replica is null."); 127 | } 128 | 129 | if (configurationPackage.Settings == null || 130 | !configurationPackage.Settings.Sections.Contains(ConfigurationSection)) 131 | { 132 | throw new ArgumentException( 133 | $"The ConfigurationPackage of the [{Context.ServiceName}-{Context.ReplicaId}] service replica does not contain any configuration section called [{ConfigurationSection}]."); 134 | } 135 | 136 | var section = configurationPackage.Settings.Sections[ConfigurationSection]; 137 | 138 | // Check if a parameter called QueueLength exists in the ActorConfig config section 139 | if (section.Parameters.Any( 140 | p => string.Compare( 141 | p.Name, 142 | QueueLengthParameter, 143 | StringComparison.InvariantCultureIgnoreCase) == 0)) 144 | { 145 | int queueLength; 146 | var parameter = section.Parameters[QueueLengthParameter]; 147 | if (!string.IsNullOrWhiteSpace(parameter.Value) && 148 | int.TryParse(parameter.Value, out queueLength)) 149 | { 150 | QueueLength = queueLength; 151 | } 152 | else 153 | { 154 | QueueLength = DefaultQueueLength; 155 | } 156 | } 157 | 158 | // Logs event 159 | ServiceEventSource.Current.Message($"[{QueueLengthParameter}] = [{QueueLength}]"); 160 | } 161 | catch (Exception ex) 162 | { 163 | ServiceEventSource.Current.Message(ex.Message); 164 | throw; 165 | } 166 | } 167 | #endregion 168 | } 169 | } -------------------------------------------------------------------------------- /WorkerActorService/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | --------------------------------------------------------------------------------