• Orleans逐步教程


    参考文档:https://dotnet.github.io/orleans/Tutorials/index.html

    一、通过模板创建Orleans

    ①下载vs插件:https://marketplace.visualstudio.com/items?itemName=sbykov.MicrosoftOrleansToolsforVisualStudio

    ②通过模板添加

    ③引用关系

    Grains引用GrainInterfaces

    Host引用 Grains、GrainInterfaces

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Orleans;
    
    namespace GrainInterfaces
    {
        public interface ITestGrain:IGrainWithGuidKey
        {
            Task Run();
            Task<string> Get();
        }
    }
    GrainInterfaces-ITestGrain
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Orleans;
    using GrainInterfaces;
    
    namespace Grains
    {
        public class TestGrain : Grain, ITestGrain
        {
            public Task<string> Get()
            {
                return Task.FromResult(this.GetType().FullName + ".Get()");
            }
    
            public Task Run()
            {
                Console.WriteLine(this.GetType().FullName + ".Run()");
                return Task.CompletedTask;
            }
        }
    }
    Grains-TestGrain
    using System;
    
    using Orleans;
    using Orleans.Runtime.Configuration;
    using Orleans.Runtime.Host;
    using GrainInterfaces;
    
    namespace Host
    {
        /// <summary>
        /// Orleans test silo host
        /// </summary>
        public class Program
        {
            static void Main(string[] args)
            {
                // 首先,配置并启动一个本地silo
                var siloConfig = ClusterConfiguration.LocalhostPrimarySilo();
                var silo = new SiloHost("TestSilo", siloConfig);
                silo.InitializeOrleansSilo();
                silo.StartOrleansSilo();
    
                Console.WriteLine("Silo started.");
    
                // 然后配置并连接一个客户端。
                var clientConfig = ClientConfiguration.LocalhostSilo();
                var client = new ClientBuilder().UseConfiguration(clientConfig).Build();
                client.Connect().Wait();
    
                Console.WriteLine("Client connected.");
    
                //
                // 这是你测试代码的地方
                //
                var testGrain = client.GetGrain<ITestGrain>(Guid.Empty);
                while (true) {
                    Console.ReadKey();
                    testGrain.Run();
                    Console.WriteLine(testGrain.Get().Result);
    
                    Console.WriteLine("
    Press Enter to terminate...");
                    Console.ReadLine();
                }
    
                // 关掉
                client.Close();
                silo.ShutdownOrleansSilo();
            }
        }
    }
    Host-Program

    下载地址:https://pan.baidu.com/s/1c3OO0zY

  • 相关阅读:
    Hadoop的三大组件 内容
    常用的linux命令
    shell学习心得
    liunx学习心得。
    随机数
    HADOOP框架
    Shell学习心得
    linux学习心得
    jquery解决随机点餐系统重复问题
    在码云上git push时报错,出现error: failed to push some refs to 'https://gitee.com/lipengyangzuishuai/gitstudy.git'的解决办法
  • 原文地址:https://www.cnblogs.com/zd1994/p/8341469.html
Copyright © 2020-2023  润新知