Akka.NET 文档 - Azure 云服务部署场景
下面的示例假设您已经创建了一个新的包含一个空 Worker Role
的 Azure PaaS 云服务。通过安装 Azure .Net SDK 将云服务模版添加到 Visual Studio。
在部署到云之前,可以在本地使用“Azure 服务模拟器”对 Worker Role
的实现进行测试。 参考 MSDN Azure 的文章 使用模拟器在本地调试和运行一个云服务 了解更多细节。
Azure PaaS Worker Role
的实现和 Windows Service 部署场景 的例子很相似。 开始使用 Akka.Net 的最快方式是创建一个简单的 Worker Role
,在它的 RunAsync() 方法里调用 top-level user-actor,如下所示:
WorkerRole.cs
using Akka.Actor;
namespace MyActorWorkerRole { public class WorkerRole : RoleEntryPoint { private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); private readonly ManualResetEvent runCompleteEvent = new ManualResetEvent(false); private ActorSystem _actorSystem; public override bool OnStart() { // Setup the Actor System _actorSystem = ActorSystem.Create("MySystem"); return (base.OnStart()); } public override void OnStop() { this.cancellationTokenSource.Cancel(); this.runCompleteEvent.WaitOne(); // Shutdown the Actor System _actorSystem.Shutdown(); base.OnStop(); } public override void Run() { try { this.RunAsync(this.cancellationTokenSource.Token).Wait(); } finally { this.runCompleteEvent.Set(); } } private async Task RunAsync(CancellationToken cancellationToken) { // Create an instance to the top-level user Actor var workerRoleActor = _actorSystem.ActorOf<WorkerRoleActor>("WorkerRole"); // Send a message to the Actor workerRoleActor.Tell(new WorkerRoleMessage("Hello World!")); while (!cancellationToken.IsCancellationRequested) { await Task.Delay(1000); } } } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

上一篇: 令人惊喜的 Kotlin 特性
下一篇: 设计模式实战
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论