public async Task DemoRun()
        {
            var builder = OrleansClientBuilder
                          .CreateLocalhostClientBuilder(clusterId: "dev", serviceId: "HelloWorldApp");

            builder
            .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IHello).Assembly).WithCodeGeneration())
            .ConfigureLogging(logBuilder => {
                logBuilder.AddSerilog();
            });

            using (var client = builder.Build())
            {
                await client.ConnectWithRetryAsync();

                _logger.LogInformation("Client successfully connect to silo host");

                var grain = client.GetGrain <IHello>(0);
                _logger.LogInformation("Get hello world grain, start calling RPC methods...");

                var returnValue = await grain.SayHello("Hello Orleans");

                _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n");

                await client.Close();

                _logger.LogInformation("Client successfully close connection to silo host");
            }
        }
Пример #2
0
        public async Task <IActionResult> CallGrainDemo(string input)
        {
            using (var client =
                       OrleansClientBuilder.CreateClient(_logger, _clusterInfo, _providerOption, new[] { typeof(IHello), typeof(INumberGenerator) }))
            {
                await client.ConnectWithRetryAsync();

                _logger.LogInformation("Client successfully connect to silo host");

                var grain = client.GetGrain <IHello>(0);
                _logger.LogInformation("Get greeting grain, start calling RPC method...");

                var returnValue = await grain.SayHello(input);

                _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n\r\n");

                var randomNumberGrain = client.GetGrain <INumberGenerator>(input);
                var luckyNumber       = await randomNumberGrain.NextInt();

                await client.Close();

                _logger.LogInformation("Client successfully close connection to silo host");

                TempData[DataKey] = JsonConvert.SerializeObject(new ResultViewModel {
                    Result = $"{returnValue}<br/>LuckyNumber is <b>{luckyNumber}</b>"
                });

                return(RedirectToAction(nameof(Index)));
            }
        }
Пример #3
0
        public async Task DemoRun()
        {
            using var client = OrleansClientBuilder
                               .CreateLocalhostClient(_logger,
                                                      clusterId: "dev", serviceId: "HelloWorldApp",
                                                      configureLogging: builder => {
                builder.AddSerilog();
            });

            await client.ConnectWithRetryAsync();

            _logger.LogInformation("Client successfully connect to silo host");

            var grain = client.GetGrain <IHello>(0);

            _logger.LogInformation("Get hello world grain, start calling RPC methods...");

            var returnValue = await grain.SayHello("Hello Orleans");

            _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n");

            await client.Close();

            _logger.LogInformation("Client successfully close connection to silo host");
        }
        public async Task DemoRun()
        {
            var clusterInfoOption = new ClusterInfoOption {
                ClusterId = "dev", ServiceId = "HelloWorldApp"
            };
            var staticGatewayOption = new StaticGatewayListProviderOptions
            {
                Gateways = new List <Uri> {
                    new Uri("gwy.tcp://127.0.0.1:30000/0")
                }
            };

            using var client =
                      OrleansClientBuilder.CreateStaticRouteClient(_logger,
                                                                   clusterInfoOption, staticGatewayOption,
                                                                   configureLogging: builder => { builder.AddSerilog(); });

            await client.ConnectWithRetryAsync();

            _logger.LogInformation("Client successfully connect to silo host");

            var grain = client.GetGrain <IHello>(0);

            _logger.LogInformation("Get hello world grain, start calling RPC methods...");

            var returnValue = await grain.SayHello("Hello Orleans");

            _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n");

            await client.Close();

            _logger.LogInformation("Client successfully close connection to silo host");
        }
        public async Task CallHello()
        {
            var(clusterInfo, providerOption) = GetConfigSettings();
            using (var client = OrleansClientBuilder.CreateClient(_logger, clusterInfo, providerOption))
            {
                await client.ConnectWithRetryAsync();

                _logger.LogInformation("Client successfully connect to silo host");

                var grain = client.GetGrain <IHello>(0);
                _logger.LogInformation("Get greeting grain, start calling RPC method...");

                var returnValue = await grain.SayHello("Hello Orleans");

                _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n\r\n");

                var return2Value = await grain.SayHello("Hello again");

                _logger.LogInformation($"RPC method return value is \r\n\r\n{{{return2Value}}}\r\n\r\n");

                var return3Value = await grain.SayHello("Hello Orleans");

                _logger.LogInformation($"RPC method return value is \r\n\r\n{{{return3Value}}}\r\n\r\n");

                await client.Close();

                _logger.LogInformation("Client successfully close connection to silo host");
            }
        }
        public static IClientBuilder CreateOrleansClientBuilder(
            int gatewayPort  = 30000,
            string clusterId = "dev",
            string serviceId = "dev",
            IEnumerable <Type> applicationPartTypes = null)
        {
            var builder = OrleansClientBuilder
                          .CreateLocalhostClientBuilder(gatewayPort, clusterId, serviceId, applicationPartTypes)
                          .ConfigureApplicationParts(_ => _.AddApplicationPart(typeof(IHello).Assembly).WithCodeGeneration());

            return(builder);
        }
        public async Task RunCounter()
        {
            var(clusterInfo, providerOption) = ConfigUtil.GetConfigSettings();

            try
            {
                using (var client =
                           OrleansClientBuilder.CreateClient(_logger,
                                                             clusterInfo,
                                                             providerOption,
                                                             new[] { typeof(IHello), typeof(ICounter) }))
                {
                    await client.ConnectWithRetryAsync();

                    _logger.LogInformation("Client successfully connect to silo host");

                    var helloGrain = client.GetGrain <IHello>(0);
                    _logger.LogInformation("Get greeting grain, start calling RPC method...");

                    var returnValue = await helloGrain.SayHello("Hello Orleans");

                    _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n\r\n");

                    var counterGrain = client.GetGrain <ICounter>(0);

                    _logger.LogInformation("Get counter grain, start calling RPC methods...");

                    await counterGrain.Add(1);

                    await Task.Delay(new TimeSpan(0, 0, 1));

                    await counterGrain.Add(2);

                    await Task.Delay(new TimeSpan(0, 0, 1));

                    await counterGrain.Add(3);

                    var current = await counterGrain.CurrentValue();

                    _logger.LogInformation("Current counter value is '{0}'", current);

                    await client.Close();

                    _logger.LogInformation("Client successfully close connection to silo host");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "call RunCounter() error");
                throw;
            }
        }
        public async Task DemoRun()
        {
            var clusterInfoOption = new ClusterInfoOption {
                ClusterId = "dev", ServiceId = "HelloWorldApp"
            };

            var sqlDbProviderOption =
                new OrleansProviderOption
            {
                DefaultProvider = @"SQLDB",
                SQLDB           = new AdoNetProviderSettings
                {
                    Cluster = new AdoNetProviderClusterSettings
                    {
                        DbConn =
                            @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Orleans_Cluster;
                                Integrated Security=True;Pooling=False;Max Pool Size=200;
                                MultipleActiveResultSets=True"
                    }
                }
            };

            using var client =
                      OrleansClientBuilder.CreateClient(_logger,
                                                        clusterInfoOption, sqlDbProviderOption,
                                                        configureLogging: builder => { builder.AddSerilog(); });

            await client.ConnectWithRetryAsync();

            _logger.LogInformation("Client successfully connect to silo host");

            var grain = client.GetGrain <IHello>(0);

            _logger.LogInformation("Get hello world grain, start calling RPC methods...");

            var returnValue = await grain.SayHello("Hello Orleans");

            _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n");

            await client.Close();

            _logger.LogInformation("Client successfully close connection to silo host");
        }
        private async Task DetectLongRunningTaskStatus(ChannelWriter <string> writer, Ulid grainId, int delay, CancellationToken cancellationToken)
        {
            try
            {
                using (var client = OrleansClientBuilder.CreateClient(_logger, _clusterInfo, _providerOption,
                                                                      new[] { typeof(IMyReminder) }))
                {
                    await client.ConnectWithRetryAsync();

                    var grain = client.GetGrain <IMyReminder>(grainId.ToGuid());

                    string status;
                    do
                    {
                        // Check the cancellation token regularly so that the server will stop
                        // producing items if the client disconnects.
                        cancellationToken.ThrowIfCancellationRequested();

                        status = await grain.GetCurrentStatus();

                        await writer.WriteAsync(status, cancellationToken);

                        if (status == "stopped")
                        {
                            break;
                        }

                        await Task.Delay(TimeSpan.FromSeconds(delay), cancellationToken);
                    } while (status == "running");

                    await client.Close();
                }
            }
            catch (Exception ex)
            {
                _logger.Error(400, "Runtime error", ex);
                writer.TryComplete(ex);
                return;
            }

            writer.TryComplete();
        }
        public async Task DemoRun()
        {
            var clusterInfoOption = new ClusterInfoOption {
                ClusterId = "dev", ServiceId = "HelloWorldApp"
            };

            var sqlDbProviderOption =
                new OrleansProviderOption
            {
                DefaultProvider = @"MYSQL",
                SQLDB           = new AdoNetProviderSettings
                {
                    Cluster = new AdoNetProviderClusterSettings
                    {
                        DbConn =
                            @"Server=localhost;uid=root;pwd=Pass1234;Database=orleans_demo"
                    }
                }
            };

            using var client =
                      OrleansClientBuilder
                      .CreateClient(_logger, clusterInfoOption, sqlDbProviderOption,
                                    new[] { typeof(IHello) }, configureLogging: builder => {
                builder.AddSerilog();
            });
            await client.ConnectWithRetryAsync();

            _logger.LogInformation("Client successfully connect to silo host");

            var grain = client.GetGrain <IHello>(0);

            _logger.LogInformation("Get hello world grain, start calling RPC methods...");

            var returnValue = await grain.SayHello("Hello Orleans");

            _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n");

            await client.Close();

            _logger.LogInformation("Client successfully close connection to silo host");
        }
Пример #11
0
        public async Task TestRpc()
        {
            var(clusterInfo, providerOption) = ConfigUtil.GetConfigSettings();

            try
            {
                using (var client =
                           OrleansClientBuilder.CreateClient(_logger,
                                                             clusterInfo,
                                                             providerOption,
                                                             new[] { typeof(IUtilityGrain) }))
                {
                    await client.ConnectWithRetryAsync();

                    _logger.LogInformation("Client successfully connect to silo host");

                    var grain = client.GetGrain <IUtilityGrain>("test");

                    var testInput = new InputDTO {
                        Name = "Alice", Email = "*****@*****.**"
                    };

                    var jsonStr = await grain.OutputJsonStr(testInput);

                    _logger.LogInformation($"Client side get OutputJsonStr() result= {jsonStr}");

                    var bsonDoc = await grain.ToBson(testInput);

                    _logger.LogInformation($"Client side get ToBson() result= {bsonDoc}");

                    await client.Close();

                    _logger.LogInformation("Client successfully close connection to silo host");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "call TestRpc() error");
                throw;
            }
        }
Пример #12
0
        public async Task <IActionResult> CallGrainAlarm()
        {
            using (var client =
                       OrleansClientBuilder.CreateClient(_logger, _clusterInfo, _providerOption))
            {
                await client.ConnectWithRetryAsync();

                var runSessionId = NUlid.Ulid.NewUlid();
                var grainGuid    = runSessionId.ToGuid();

                var demoGrain  = client.GetGrain <IMyReminder>(grainGuid);
                var callResult = await demoGrain.Alarm();

                await client.Close();

                TempData[tempDataKey] = JsonConvert.SerializeObject(new LongTaskViewModel {
                    Result = callResult, RunSessionId = runSessionId
                });

                return(RedirectToAction(nameof(Index), new { runSessionId }));
            }
        }
Пример #13
0
        public async Task DemoRun()
        {
            var clusterInfoOption = new ClusterInfoOption {
                ClusterId = "dev", ServiceId = "HelloWorldApp"
            };

            var mongoDbProviderOption = new OrleansProviderOption
            {
                DefaultProvider = "mongodb",
                MongoDB         = new MongoDbProviderSettings
                {
                    Cluster = new MongoDbProviderClusterSettings
                    {
                        DbConn = "mongodb://localhost:27017",
                        DbName = "demo-silo-Clustering"
                    }
                }
            };

            using var client = OrleansClientBuilder
                               .CreateClient(_logger, clusterInfoOption, mongoDbProviderOption, new[] { typeof(IHello) },
                                             builder => { builder.AddSerilog(); });

            await client.ConnectWithRetryAsync();

            _logger.LogInformation("Client successfully connect to silo host");

            var grain = client.GetGrain <IHello>(0);

            _logger.LogInformation("Get hello world grain, start calling RPC methods...");

            var returnValue = await grain.SayHello("Hello Orleans");

            _logger.LogInformation($"RPC method return value is \r\n\r\n{{{returnValue}}}\r\n");

            await client.Close();

            _logger.LogInformation("Client successfully close connection to silo host");
        }