How do I extend class derived from StatelessService in Service Fabric ASP.NET 5 - based service?

坚强是说给别人听的谎言 提交于 2019-12-11 13:56:02

问题


Is there a way to subscribe to an actor event from ASP.NET 5 - based service? I saw similar feature in service-fabric-dotnet-data-streaming-websockets sample, but the sample uses OWIN-based web service and it has PublicGateway class derived from StatelessService where one can hook to the service Task RunAsync override. I haven't found any StatelessService-derived type in the ASP.NET 5 - based project code. Seems like it's auto-generated, if to look into the project ServiceManifest.XML?

The goal I'm trying to achieve is the same with the sample - I want to subscribe to events from actor service to publish them through SignalR hub.


回答1:


The difference you're seeing is that the OWIN (Katana, to be precise) sample is a Service Fabric Reliable Service - a service written on the Service Fabric API - that uses Katana to open an HTTP listener. The ASP.NET 5 (now called ASP.NET Core 1) project you're seeing is what we call a "Guest Host" which is a separate EXE hosted by Service Fabric but doesn't implement any of the Service Fabric APIs. The reason it's done this way currently is because the current ASP.NET Core 1 hosting model makes it difficult to open a web server programmatically like we do with Katana.

However, this is changing. The upcoming RC2 of ASP.NET Core 1 will let you easily start a web server programmatically, similar to the way we do it with Katana, so you can write a service on the Service Fabric API and open an ASP.NET Core 1 server from the service. Here is an example using the RC2 build: https://github.com/weidazhao/Hosting

That said, you don't necessarily need to be inside a Reliable Service to hook into actor events. Any code running in the cluster can do it by pulling in the Reliable Actors NuGet package (Microsoft.ServiceFabric.Actors) and using the ActorProxy API. You can do this in a Guest Host service, you just won't have RunAsync as an entry point to do it in.



来源:https://stackoverflow.com/questions/35476040/how-do-i-extend-class-derived-from-statelessservice-in-service-fabric-asp-net-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!