public async Task <IFizzBuzzService> Connect() { if (string.IsNullOrWhiteSpace(_clusterId)) { throw new ArgumentNullException(nameof(_clusterId)); } if (string.IsNullOrWhiteSpace(_serviceId)) { throw new ArgumentNullException(nameof(_serviceId)); } var builder = new ClientBuilder() .UseLocalhostClustering() .Configure <ClusterOptions>(options => { options.ClusterId = _clusterId; options.ServiceId = _serviceId; }); if (_addConsole) { builder.ConfigureLogging(logging => logging.AddConsole()); } _clusterClient = builder.Build(); await _clusterClient.Connect(); return(this); }
public static IClusterClient Get(OrleansClientConnectionOptions options) { var serviceName = new Uri(options.FabricUrl); var builder = new ClientBuilder(); builder.Configure <ClusterOptions>(opt => { opt.ServiceId = serviceName.ToString(); opt.ClusterId = options.ClusterId; }); builder.UseAzureStorageClustering(opt => opt.ConnectionString = options.TableStorageConnectionString); builder.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IMyFirstGrain).Assembly)); builder.ConfigureLogging(logging => logging.AddDebug()); var client = builder.Build(); return(client); }
public static IClusterClient Get(string fabricUrl, string azureStorageConnectionString) { var serviceName = new Uri(fabricUrl); var builder = new ClientBuilder(); builder.Configure <ClusterOptions>(options => { options.ServiceId = serviceName.ToString(); options.ClusterId = "development"; }); builder.UseAzureStorageClustering(options => options.ConnectionString = azureStorageConnectionString); builder.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IMyFirstGrain).Assembly)); builder.ConfigureLogging(logging => logging.AddDebug()); var client = builder.Build(); return(client); }
private static async Task Run(string[] args) { var serviceName = new Uri("fabric:/StatelessCalculatorApp/StatelessCalculatorService"); var builder = new ClientBuilder(); builder.Configure <ClusterOptions>(options => { options.ServiceId = Guid.Empty; options.ClusterId = "dev"; }); // Use Service Fabric for managing cluster membership. builder.UseServiceFabricClustering(serviceName); // Add the application assemblies. builder.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ICalculatorGrain).Assembly)); // Optional: configure logging. builder.ConfigureLogging(logging => logging.AddDebug()); builder.ConfigureServices( services => { // Some deployments require a custom FabricClient, eg so that cluster endpoints and certificates can be configured. // A pre-configured FabricClient can be injected. var fabricClient = new FabricClient(); services.AddSingleton(fabricClient); }); // Create the client and connect to the cluster. var client = builder.Build(); await client.Connect(); double result; if (args.Length < 1) { Console.WriteLine( $"Usage: {Assembly.GetExecutingAssembly()} <operation> [operand]\n\tOperations: get, set, add, subtract, multiple, divide"); return; } var value = args.Length > 1 ? double.Parse(args[1]) : 0; var calculator = client.GetGrain <ICalculatorGrain>(Guid.Empty); var observer = new CalculatorObserver(); var observerReference = await client.CreateObjectReference <ICalculatorObserver>(observer); var cancellationTokenSource = new CancellationTokenSource(); var subscriptionTask = StaySubscribed(calculator, observerReference, cancellationTokenSource.Token); switch (args[0].ToLower()) { case "stress": result = await StressTest(client); break; case "add": case "+": result = await calculator.Add(value); break; case "subtract": case "-": result = await calculator.Subtract(value); break; case "multiply": case "*": result = await calculator.Multiply(value); break; case "divide": case "/": result = await calculator.Divide(value); break; case "set": result = await calculator.Set(value); break; case "get": default: result = await calculator.Get(); break; } Console.WriteLine(result); Console.WriteLine("Listening for updates to calculations. Press any key to exit."); Console.ReadKey(); cancellationTokenSource.Cancel(); await subscriptionTask; }
private static async Task Run(string[] args) { var serviceName = new Uri("fabric:/StatelessCalculatorApp/StatelessCalculatorService"); var builder = new ClientBuilder(); builder.Configure <ClusterOptions>(options => { options.ServiceId = serviceName.ToString(); options.ClusterId = "development"; }); // TODO: Pick a clustering provider and configure it here. builder.UseAzureStorageClustering(options => options.ConnectionString = "UseDevelopmentStorage=true"); // Add the application assemblies. builder.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ICalculatorGrain).Assembly)); // Optional: configure logging. builder.ConfigureLogging(logging => logging.AddDebug()); // Create the client and connect to the cluster. var client = builder.Build(); await client.Connect(); double result; if (args.Length < 1) { Console.WriteLine( $"Usage: {Assembly.GetExecutingAssembly()} <operation> [operand]\n\tOperations: get, set, add, subtract, multiple, divide"); return; } var value = args.Length > 1 ? double.Parse(args[1]) : 0; var calculator = client.GetGrain <ICalculatorGrain>(Guid.Empty); var observer = new CalculatorObserver(); var observerReference = await client.CreateObjectReference <ICalculatorObserver>(observer); var cancellationTokenSource = new CancellationTokenSource(); var subscriptionTask = StaySubscribed(calculator, observerReference, cancellationTokenSource.Token); switch (args[0].ToLower()) { case "stress": result = await StressTest(client); break; case "add": case "+": result = await calculator.Add(value); break; case "subtract": case "-": result = await calculator.Subtract(value); break; case "multiply": case "*": result = await calculator.Multiply(value); break; case "divide": case "/": result = await calculator.Divide(value); break; case "set": result = await calculator.Set(value); break; case "get": default: result = await calculator.Get(); break; } Console.WriteLine(result); Console.WriteLine("Listening for updates to calculations. Press any key to exit."); Console.ReadKey(); cancellationTokenSource.Cancel(); await subscriptionTask; }