Пример #1
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)));
            }
        }
        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 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");
        }
Пример #7
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;
            }
        }
Пример #8
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 }));
            }
        }
Пример #9
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");
        }