static async Task Main(string[] args) { var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory()) .ConfigureServices(services => { services.AddTransient(provider => HelloComponent.Create(provider.GetRequiredService <IGrainActivationContext>())); }) .UseLocalhostClustering() .Build(); await client.Connect(); Console.WriteLine("Client is connected"); for (var i = 0; i < 3; i++) { Console.WriteLine(i); var grain = client.GetGrain <IHelloLifecycleGrain>(i); var message = await grain.SayAsync("powerumc"); Console.WriteLine($"Grain identity: {grain.GetGrainIdentity()}"); Console.WriteLine($"Grain primary key: {grain.GetPrimaryKey()}"); Console.WriteLine($"Message received: {message}"); Console.WriteLine(); } }
static void Main(string[] args) { // First, configure and start a local silo var siloConfig = ClusterConfiguration.LocalhostPrimarySilo(); var silo = new SiloHost("TestSilo", siloConfig); silo.InitializeOrleansSilo(); silo.StartOrleansSilo(); Console.WriteLine("Silo started."); // Then configure and connect a client. var clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder().UseConfiguration(clientConfig).Build(); client.Connect().Wait(); Console.WriteLine("Client connected."); // // This is the place for your test code. // Console.WriteLine("\nPress Enter to terminate..."); Console.ReadLine(); // Shut down client.Close(); silo.ShutdownOrleansSilo(); }
private IClusterClient CreateClusterClient(IServiceProvider serviceProvider) { var log = serviceProvider.GetService <ILogger <Startup> >(); // TODO replace with your connection string const string connectionString = "ENTER_CONNECTION_STRING"; var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IValueGrain).Assembly)) .Configure <ClusterOptions>(options => { options.ClusterId = "orleans-service-fabric-mesh"; options.ServiceId = "AspNetSampleApp"; }) .UseAzureStorageClustering(options => options.ConnectionString = connectionString) .Build(); client.Connect(RetryFilter).GetAwaiter().GetResult(); return(client); async Task <bool> RetryFilter(Exception exception) { log?.LogWarning("Exception while attempting to connect to Orleans cluster: {Exception}", exception); await Task.Delay(TimeSpan.FromSeconds(2)); return(true); } }
private static async Task <IClusterClient> StartClientWithRetries() { attempt = 0; IClusterClient client; client = new ClientBuilder() .UseAdoNetClustering(options => { options.Invariant = "System.Data.SqlClient"; options.ConnectionString = "Server=DESKTOP-RS8V952\\SQLSERVER;Database=Orleans;Trusted_Connection=True;"; }) .Configure <ClusterOptions>(options => { options.ClusterId = "poc"; options.ServiceId = "Orleans"; }) .ConfigureLogging(logging => logging .AddConsole() .AddFilter("Orleans", LogLevel.Warning) .AddFilter("Runtime", LogLevel.Warning) .AddFilter("Microsoft", LogLevel.Warning)) .Build(); await client.Connect(RetryFilter); Console.WriteLine("Client successfully connect to silo host"); return(client); }
/// <summary> /// 获取Orleans服务集群客户端 /// </summary> /// <param name="clusterId">Orleans集群的唯一ID</param> /// <param name="serviceId">Orleans服务的唯一ID</param> /// <param name="connectionString">Orleans数据库连接串</param> /// <returns>Orleans服务集群客户端</returns> public static IClusterClient Fetch(string clusterId, string serviceId, string connectionString) { return(_cache.GetValue(String.Format("{0}*{1}", clusterId, serviceId), () => { IClusterClient value = new ClientBuilder() .ConfigureLogging(logging => logging.AddConsole()) .Configure <ConnectionOptions>(options => { options.ProtocolVersion = NetworkProtocolVersion.Version2; }) .Configure <ClusterOptions>(options => { options.ClusterId = clusterId; options.ServiceId = serviceId; }) .UseAdoNetClustering(options => { options.ConnectionString = connectionString; #if PgSQL options.Invariant = "Npgsql"; #endif #if MySQL options.Invariant = "MySql.Data.MySqlClient"; #endif #if ORA options.Invariant = "Oracle.DataAccess.Client"; #endif }) .ConfigureApplicationParts(parts => { parts.AddPluginPart(); }) .AddSimpleMessageStreamProvider(StreamProvider.Name) .Build(); value.Connect().Wait(); return value; })); }
static IClusterClient StartClient() { return(Policy <IClusterClient> .Handle <SiloUnavailableException>() .Or <OrleansMessageRejectionException>() .Or <ConnectionFailedException>(exception => { Console.WriteLine(exception.Source + exception.Message); return true; }) .WaitAndRetry(new[] { TimeSpan.FromSeconds(5) }) .Execute(() => { var client = new ClientBuilder() .UseLocalhostClustering() .Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "HelloApp"; }) .Build(); client.Connect().GetAwaiter().GetResult(); Console.WriteLine("Client connected"); return client; } )); }
public static async Task <IClusterClient> createClient() { string strConnection = "Server=10.0.75.1;Initial Catalog=Orleans;Persist Security Info=False;User ID=sa;Password=P@ssword0;MultipleActiveResultSets=False;Connection Timeout=30;"; attempt = 0; IClusterClient client; client = new ClientBuilder() .UseLocalhostClustering() //.ConfigureHostConfiguration(config => //{ //}) //.UseAdoNetClustering(options => //{ // options.ConnectionString = strConnection; // options.Invariant = "System.Data.SqlClient"; //}) .Configure <ClusterOptions>(options => { options.ClusterId = "test"; options.ServiceId = "MudGame"; }) .AddSimpleMessageStreamProvider(Constants.NotifyStreamProvider) .ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Critical)) .Build(); await client.Connect(RetryFilter); Console.WriteLine("Client successfully connect to silo host"); return(client); }
private static async Task <IClientActorSystem> StartClientWithRetries() { // Client config IClusterClient client; client = new ClientBuilder() .UseLocalhostClustering() .Configure <ClusterOptions>(options => { options.ClusterId = "nejcSC"; options.ServiceId = "SmartCache"; }) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomain).Assembly).WithReferences()) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomainProjection).Assembly).WithReferences()) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomainReader).Assembly).WithReferences()) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomainsInfoProjection).Assembly).WithReferences()) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IDomainsInfoReader).Assembly).WithReferences()) .AddSimpleMessageStreamProvider("SMSProvider") .UseOrleankka() .Build(); var log = new LoggerConfiguration() .WriteTo.Seq("http://localhost:5341") .WriteTo.Console() .CreateLogger(); await client.Connect(RetryFilter); return(client.ActorSystem()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); var clusterClient = new ClientBuilder() .UseLocalhostClustering() .UseSignalR() .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IChatGrain).Assembly).WithReferences()) .Build(); var retries = 0; clusterClient.Connect(async ex => { if (retries >= 5) { return(false); } await Task.Delay(1000); retries++; return(true); }).Wait(); services.AddSingleton(clusterClient); services.AddSignalR() .AddOrleans <ChatHub>() .AddOrleans <AnotherHub>(); }
static async Task Main(string[] args) { var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory().WithCodeGeneration()) .UseLocalhostClustering() .AddSimpleMessageStreamProvider(StreamNames.PubSubProviderName) .Build(); await client.Connect(); Console.WriteLine("Connected."); Console.WriteLine("Send a message."); AssemblyLoadContext.Default.Unloading += async context => await client.Close(); Console.CancelKeyPress += async(sender, eventArgs) => await client.Close(); var grain = client.GetGrain <IHelloGrain>(0); var streamId = await grain.JoinAsync(); var streamProvider = client.GetStreamProvider(StreamNames.PubSubProviderName); var stream = streamProvider.GetStream <string>(streamId, StreamNames.HelloGrainNamespace); await stream.SubscribeAsync(new HelloGrainStreamObserver()); while (true) { var message = Console.ReadLine(); await grain.SayStreamAsync(message); } }
private IClusterClient CreateOrleansClient() { var orleansConfig = Configuration.GetSection("OrleansConfig"); var client = new ClientBuilder() .UseLocalhostClustering(gatewayPort: orleansConfig.GetValue <int>("gatewayPort")) .Configure <ClusterOptions>(options => { options.ClusterId = orleansConfig["clusterId"]; options.ServiceId = orleansConfig["serviceId"]; }) .ConfigureLogging(logging => logging.AddConsole()) .Build(); client .Connect(async ex => { Console.WriteLine(ex); Console.WriteLine("Retrying..."); await Task.Delay(3000); return(true); }) .Wait(); return(client); }
private static IClusterClient StartClient() { return(Policy <IClusterClient> .Handle <SiloUnavailableException>() .Or <OrleansMessageRejectionException>() .WaitAndRetry( new List <TimeSpan> { TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4) }).Execute(() => { var client = new ClientBuilder() //clustering inforation .Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "HelloApp"; }) //Clustering provider .UseLocalhostClustering().Build(); client.Connect().GetAwaiter().GetResult(); Console.WriteLine("client connected"); return client; })); }
public static IServiceProvider ConfigureServices(IServiceCollection services) { services.AddLogging(builder => { builder.AddSerilog(new LoggerConfiguration().WriteTo.File("log.txt").CreateLogger()); }); services.AddTransient <CeChatApp>(); services.AddTransient <IClusterClient>(sp => { var looger = sp.GetRequiredService <ILogger <ClientBuilder> >(); var client = new ClientBuilder() .ConfigureApplicationParts(manager => manager.AddApplicationPart(typeof(ICeChatRoomGrain).Assembly).WithReferences()) .UseLocalhostClustering() .AddSimpleMessageStreamProvider("SMS") .Build(); client.Connect(async error => { looger.LogError(error, error.Message); await Task.Delay(TimeSpan.FromSeconds(1)); return(true); }); return(client); }); return(services.BuildServiceProvider()); }
private IClusterClient CreateClusterClient(IServiceProvider serviceProvider) { var log = serviceProvider.GetService <ILogger <Startup> >(); var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IManageContentGrain).Assembly).WithCodeGeneration()) //.Configure<ClusterOptions>(options => //{ // options.ClusterId = "orleans-docker"; // options.ServiceId = "AspNetSampleApp"; //}) .UseLocalhostClustering() .Build(); client.Connect(RetryFilter).GetAwaiter().GetResult(); return(client); async Task <bool> RetryFilter(Exception exception) { log?.LogWarning("Exception while attempting to connect to Orleans cluster: {Exception}", exception); await Task.Delay(TimeSpan.FromSeconds(2)); return(true); } }
static async Task Main(string[] args) { var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory()) .UseLocalhostClustering() .Build(); await client.Connect(); var manualResetEvent = new ManualResetEvent(false); var cancellationTokenSource = new CancellationTokenSource(); Console.CancelKeyPress += async(sender, eventArgs) => { await Shutdown(client, cancellationTokenSource); }; AssemblyLoadContext.Default.Unloading += async context => { await Shutdown(client, cancellationTokenSource); }; Console.WriteLine("Connected"); cancellationTokenSource.Token.Register(() => { manualResetEvent.Set(); }); var task = Task.Run(() => GetRandomAsync(client, cancellationTokenSource.Token), cancellationTokenSource.Token); manualResetEvent.WaitOne(); await task; }
private IClusterClient CreateClusterClient(IServiceProvider serviceProvider) { //TODO: move magic strings? var client = new ClientBuilder() .Configure <ClusterOptions>(options => { options.ClusterId = "orleans-wdm4-cluster-aks"; options.ServiceId = "orleans-wdm4-service-aks"; }) .UseAzureStorageClustering(opt => opt.ConnectionString = AzureConnectionString) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IOrderGrain).Assembly).WithReferences()) .ConfigureLogging(logging => logging.AddConsole()) .Build(); Console.WriteLine("API CLUSTERCLIENT CONNECTION ATTEMPT STARTED"); client.Connect(RetryFilter).GetAwaiter().GetResult(); return(client); //https://github.com/dotnet/orleans/issues/5158 async Task <bool> RetryFilter(Exception exception) { Console.WriteLine("Exception while attempting to connect to Orleans cluster: {0}", exception); await Task.Delay(TimeSpan.FromSeconds(2)); return(true); } }
public async Task ConnectIsRetryableTest() { var gwEndpoint = this.HostedCluster.Client.Configuration().Gateways.First(); // Create a client with no gateway endpoint and then add a gateway endpoint when the client fails to connect. var gatewayProvider = new MockGatewayListProvider(); var client = new ClientBuilder() .Configure <ClusterOptions>(options => { var existingClientOptions = this.HostedCluster.ServiceProvider.GetRequiredService <IOptions <ClusterOptions> >().Value; options.ClusterId = existingClientOptions.ClusterId; options.ServiceId = existingClientOptions.ServiceId; }) .ConfigureServices(services => services.AddSingleton <IGatewayListProvider>(gatewayProvider)) .Build(); var exceptions = new List <Exception>(); Task <bool> RetryFunc(Exception exception) { Assert.IsType <OrleansException>(exception); exceptions.Add(exception); gatewayProvider.Gateways = new List <Uri> { gwEndpoint.ToGatewayUri() }.AsReadOnly(); return(Task.FromResult(true)); } await client.Connect(RetryFunc); Assert.Single(exceptions); }
public OrleansFixture() { var siloPort = 11111; int gatewayPort = 30000; var siloAddress = IPAddress.Loopback; //siloConfig.Globals.FallbackSerializationProvider = typeof(ILBasedSerializer).GetTypeInfo(); ClusterConfiguration clusterConfig = ClusterConfiguration.LocalhostPrimarySilo(); var builder = new SiloHostBuilder(); var silo = PreBuild(builder) .Configure(options => options.ClusterId = "TESTCLUSTER") .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort)) .ConfigureEndpoints(siloAddress, siloPort, gatewayPort) //.UseConfiguration(clusterConfig) .ConfigureApplicationParts(pm => pm.AddApplicationPart(typeof(PersistenceTests).Assembly)) .Build(); silo.StartAsync().Wait(); this.Silo = silo; //clientConfig.FallbackSerializationProvider = typeof(ILBasedSerializer).GetTypeInfo(); ClientConfiguration clientConfig = ClientConfiguration.LocalhostSilo(); var client = new ClientBuilder() //.UseConfiguration(clientConfig) .ConfigureCluster(c => c.ClusterId = "TESTCLUSTER") .UseStaticClustering(options => options.Gateways = new[] { new IPEndPoint(siloAddress, gatewayPort).ToGatewayUri() }) .ConfigureApplicationParts(pm => pm.AddApplicationPart(typeof(PersistenceTests).Assembly)) .Build(); client.Connect().Wait(); this.Client = client; }
public static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.File("log.txt") .WriteTo.Console() .CreateLogger(); var client = new ClientBuilder() .UseLocalhostClustering() .Configure <ClusterOptions>(x => { x.ClusterId = "dev"; x.ServiceId = "helloworld"; }) .ConfigureLogging(l => { l.AddSerilog(dispose: true); }) .Build(); await client.Connect(async ex => { await Task.Delay(TimeSpan.FromSeconds(3)); return(true); }); CreateWebHostBuilder(args, client).Build().Run(); }
#pragma warning restore IDE0022 // Use expression body for methods private static void UseOrleansLocally() { Program.userName = Program.GetUserName(); var config = ClientConfiguration.LocalhostSilo(30000); while (true) { try { var client = new ClientBuilder().UseConfiguration(config).Build(); client.Connect().GetAwaiter().GetResult(); break; } // TODO: Get Rocky to stop laughing at me. catch { Task.Delay(TimeSpan.FromSeconds(1)); } } GrainClient.Initialize(config); Console.Out.WriteLine("Begin..."); using (var keyLogger = new BufferedEventedNativeKeyWatcher(Program.BufferSize)) { keyLogger.KeysLogged += Program.OnKeysLogged; Application.Run(); } }
private IClusterClient CreateClusterClient(IServiceProvider serviceProvider) { var log = serviceProvider.GetService <ILogger <Startup> >(); // TODO replace with your connection string var client = new ClientBuilder() .Configure <ClusterOptions>(options => { options.ClusterId = "orleans-docker"; options.ServiceId = "AspNetSampleApp"; }) .UseDashboard() .UseMongoDBClustering(options => { options.ConnectionString = "mongodb://192.168.124.88:27017"; options.DatabaseName = "k8s-clustering"; }) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IValueGrain).Assembly)) .ConfigureLogging(builder => builder.SetMinimumLevel(LogLevel.Information).AddConsole()) .Build(); client.Connect(RetryFilter).GetAwaiter().GetResult(); log.LogInformation($"Orleans client connected!"); return(client); async Task <bool> RetryFilter(Exception exception) { log?.LogWarning("Exception while attempting to connect to Orleans cluster: {Exception}", exception); await Task.Delay(TimeSpan.FromSeconds(2)); return(true); } }
public static async Task <IClusterClient> StartClientWithRetries(int initializeAttemptsBeforeFailing = 5) { int attempt = 0; IClusterClient client; while (true) { try { var config = ClientConfiguration.LocalhostSilo(); client = new ClientBuilder() .UseConfiguration(config) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IHello).Assembly).WithReferences()) .ConfigureLogging(logging => logging.AddConsole()) .Build(); await client.Connect(); Console.WriteLine("Client successfully connect to silo host"); break; } catch (SiloUnavailableException) { attempt++; Console.WriteLine($"Attempt {attempt} of {initializeAttemptsBeforeFailing} failed to initialize the Orleans client."); if (attempt > initializeAttemptsBeforeFailing) { throw; } await Task.Delay(TimeSpan.FromSeconds(4)); } } return(client); }
public static void Main(string[] args) { ClientConfiguration config = ClientConfiguration.LoadFromFile("ClientConfiguration.xml"); config.DeploymentId = "R5Ent-v1.0"; config.DataConnectionString = @"Server=NCI-R5ESQL01.dev-r5ead.net\mssqlsvr02;Database=Orleans;User ID=orleans;password=orleans;"; var oclient = new ClientBuilder() .UseConfiguration(config) .ConfigureServices(services => { }) .Build(); oclient.Connect().Wait(); //we need to actual hit the silos to ensure that the silo is up. var managementGrain = oclient.GetGrain <IManagementGrain>(0); Task.Run(async() => { var hosts = await managementGrain.GetHosts(); }); CreateWebHostBuilder(args).Build().Run(); }
public OrleansFixture() { var siloPort = 11111; int gatewayPort = 30000; var siloAddress = IPAddress.Loopback; var silo = new SiloHostBuilder() .Configure(options => options.ClusterId = "test-cluster") .UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort)) .ConfigureEndpoints(siloAddress, siloPort, gatewayPort) .UseSignalR() .Build(); silo.StartAsync().Wait(); this.Silo = silo; var client = new ClientBuilder() .ConfigureCluster(options => options.ClusterId = "test-cluster") .UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(siloAddress, gatewayPort).ToGatewayUri())) .UseSignalR() .Build(); client.Connect().Wait(); this.Client = client; }
private static async Task <IClusterClient> StartClientWithRetries() { attempt = 0; IClusterClient client; client = new ClientBuilder() .ConfigureClustering( ServiceProvider.GetService <IOptions <OrleansConfig> >(), Startup.HostingEnvironment.EnvironmentName ) .Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "HelloWorldApp"; }) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IGrainInterfaceMarker).Assembly).WithReferences()) // I don't want the chatter of logging from the client for now. //.ConfigureLogging(logging => logging.AddConsole()) .Build(); await client.Connect(RetryFilter); Console.WriteLine("Client successfully connect to silo host"); return(client); }
static async Task cfdf() { try { Console.WriteLine("상태없음"); Console.ReadLine(); var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory()) .UseLocalhostClustering() .Build(); await client.Connect(); Console.WriteLine(await client.GetGrain <IHelloStatefulGrain>(0).SayAsync("Stateful powerumc")); Console.WriteLine(await client.GetGrain <IHelloStatelessGrain>(0).SayAsync("Stateless powerumc")); Console.WriteLine(await client.GetGrain <IHelloStatelessLimitGrain>(0).SayAsync("StatelessLimit powerumc")); Console.ReadLine(); } catch (Exception exc) { Console.WriteLine(exc.Message); Console.ReadLine(); } }
private IClusterClient CreateClusterClient(IServiceProvider serviceProvider) { var log = serviceProvider.GetService <ILogger <Startup> >(); // Due to bug: https://github.com/Azure/service-fabric-mesh-preview/issues/264 var connectionString = Uri.UnescapeDataString(Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING")); var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IValueGrain).Assembly)) .Configure <ClusterOptions>(options => { options.ClusterId = "orleans-docker"; options.ServiceId = "AspNetSampleApp"; }) .UseAzureStorageClustering(options => options.ConnectionString = connectionString) .Build(); client.Connect(RetryFilter).GetAwaiter().GetResult(); return(client); async Task <bool> RetryFilter(Exception exception) { log?.LogWarning("Exception while attempting to connect to Orleans cluster: {Exception}", exception); await Task.Delay(TimeSpan.FromSeconds(2)); return(true); } }
private IClusterClient CreateClusterClient(IServiceProvider serviceProvider) { var log = serviceProvider.GetService <ILogger <Startup> >(); // TODO replace with your connection string string connectionString = Configuration.GetConnectionString("default"); var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IValueGrain).Assembly)) .Configure <ClusterOptions>(options => { options.ClusterId = "orleans-docker"; options.ServiceId = "AspNetSampleApp"; }) .UseAdoNetClustering(options => { options.ConnectionString = connectionString; options.Invariant = "System.Data.SqlClient"; }) .Build(); client.Connect(RetryFilter).GetAwaiter().GetResult(); return(client); async Task <bool> RetryFilter(Exception exception) { log?.LogWarning("Exception while attempting to connect to Orleans cluster: {Exception}", exception); await Task.Delay(TimeSpan.FromSeconds(2)); return(true); } }
static async Task Main(string[] args) { var client = new ClientBuilder() .ConfigureApplicationParts(parts => parts.AddFromApplicationBaseDirectory()) .UseLocalhostClustering() .Build(); await client.Connect(); AssemblyLoadContext.Default.Unloading += async context => await client.Close(); Console.WriteLine("Connected."); var grain = client.GetGrain <IHelloNotifyGrain>(0); var observerRef = await client.CreateObjectReference <IHelloNotifyGrainObserver>(new HelloNotifyGrainObserver()); await grain.SubscribeAsync(observerRef); while (true) { Console.WriteLine("Type a message."); var message = Console.ReadLine(); if (string.IsNullOrWhiteSpace(message)) { continue; } await grain.SendMessageAsync(message); } }
static IClusterClient StartClient() { return(Policy <IClusterClient> .Handle <Exception>() .Or <OrleansMessageRejectionException>() .WaitAndRetry(2, retryAttempt => { Console.WriteLine($"Attempt {retryAttempt}. Waiting 10 seconds"); return TimeSpan.FromSeconds(10); // Wait 10 seconds }) .Execute(() => { var client = new ClientBuilder() // Clustering information .Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "HelloApp"; }) // Clustering provider .UseAdoNetClustering(options => { options.Invariant = "MySql.Data.MySqlClient"; options.ConnectionString = "Server=localhost;Uid=root;Pwd=123456;Persist Security Info= true;Database=orleanshelloworld;SslMode=none;"; }) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IHello).Assembly)) //.ConfigureLogging(logging => logging.AddConsole()) .Build(); client.Connect().GetAwaiter().GetResult(); Console.WriteLine("Client connected"); return client; })); }