/// <summary> /// 创建一个客户端 /// </summary> /// <returns></returns> private async Task <IClusterClient> ConnectClient() { var orleansConfig = OrleansConfig.ReadConfig(); IClusterClient client; client = new ClientBuilder() //.UseLocalhostClustering(30001) .UseStaticClustering(orleansConfig.GetIPEndPoint()) .Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "OrleansBasics"; }) .ConfigureLogging(logging => logging.AddConsole()) .Build(); await client.Connect(); return(client); }
/// <summary> /// 启动Silo /// </summary> /// <param name="assemblys"></param> /// <returns></returns> private static async Task <ISiloHost> StartSilo(params Assembly[] assemblys) { var orleansConfig = OrleansConfig.ReadConfig(); // define the cluster configuration var builder = new SiloHostBuilder() .UseLocalhostClustering() .Configure <ClusterOptions>(options => { //群集标识 options.ClusterId = "dev"; options.ServiceId = "OrleansBasics"; }) .Configure <EndpointOptions>(options => { //网关设置 //options.AdvertisedIPAddress = IPAddress.Parse("127.0.0.1");//监听外网地址 options.AdvertisedIPAddress = IPAddress.Parse(orleansConfig.GatewayAddress); options.SiloPort = orleansConfig.SiloPort; options.GatewayPort = orleansConfig.GatewayPort; }) .ConfigureApplicationParts( parts => { foreach (var assembly in assemblys) { //注入程序集 parts.AddApplicationPart(assembly).WithReferences(); } } ) .ConfigureLogging(logging => logging.AddConsole()); if (orleansConfig.UseDashboard) {//使用监控 builder.UseDashboard(); } var host = builder.Build(); await host.StartAsync(); return(host); }