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 RunCounter() { var(clusterInfo, _) = ConfigUtil.GetConfigSettings(); try { using (var client = OrleansClientBuilder.CreateLocalhostClient(_logger, gatewayPort: 8310, serviceId: clusterInfo.ServiceId, clusterId: clusterInfo.ClusterId)) { 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 TestRpc() { var(clusterInfo, _) = ConfigUtil.GetConfigSettings(); try { using (var client = OrleansClientBuilder.CreateLocalhostClient(_logger, gatewayPort: 8310, serviceId: clusterInfo.ServiceId, clusterId: clusterInfo.ClusterId)) { await client.ConnectWithRetryAsync(); _logger.LogInformation("Client successfully connect to silo host"); var grain = client.GetGrain <IUtilityGrain>("demo2"); 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; } }