public async Task BuildAndStartDataflowAsync() { var workflowName = _config.GetValue <string>("HouseofCat:ConsumerDataflowOptions:DataflowName"); var consumerName = _config.GetValue <string>("HouseofCat:ConsumerDataflowOptions:ConsumerName"); var consumerCount = _config.GetValue <int>("HouseofCat:ConsumerDataflowOptions:ConsumerCount"); var maxDoP = _config.GetValue <int>("HouseofCat:ConsumerDataflowOptions:MaxDoP"); var ensureOrdered = _config.GetValue <bool>("HouseofCat:ConsumerDataflowOptions:EnsureOrdered"); var capacity = _config.GetValue <int>("HouseofCat:ConsumerDataflowOptions:Capacity"); _simulateIODelay = _config.GetValue <bool>("HouseofCat:ConsumerDataflowOptions:SimulateIODelay"); _minIODelay = _config.GetValue <int>("HouseofCat:ConsumerDataflowOptions:MinIODelay"); _maxIODelay = _config.GetValue <int>("HouseofCat:ConsumerDataflowOptions:MaxIODelay"); _logStepOutcomes = _config.GetValue <bool>("HouseofCat:ConsumerDataflowOptions:LogStepOutcomes"); _workflow = new ConsumerDataflow <WorkState>( rabbitService: _rabbitService, workflowName: workflowName, consumerName: consumerName, consumerCount: consumerCount) .SetSerializationProvider(_serializationProvider) .SetEncryptionProvider(_encryptionProvider) .SetCompressionProvider(_compressionProvider) .SetMetricsProvider(_metricsProvider) .WithBuildState <Message>("Message", maxDoP, ensureOrdered) .WithDecryptionStep(maxDoP, ensureOrdered) .WithDecompressionStep(maxDoP, ensureOrdered) .AddStep(RetrieveObjectFromState, $"{workflowName}_RetrieveObjectFromState", true, null, maxDoP, ensureOrdered) .AddStep(ProcessStepAsync, $"{workflowName}_ProcessStep", !_simulateIODelay, null, maxDoP, ensureOrdered) .AddStep(AckMessage, $"{workflowName}_AckMessage", true, null, maxDoP, ensureOrdered) .WithErrorHandling(ErrorHandlingAsync, capacity, maxDoP, ensureOrdered) .WithFinalization(Finalization, maxDoP, ensureOrdered); Completion = _workflow.Completion; await _workflow .StartAsync() .ConfigureAwait(false); }
public static async Task Main() { await Console.Out.WriteLineAsync("Run a ConsumerWorkflow demo... press any key to continue!").ConfigureAwait(false); Console.ReadKey(); // memory snapshot baseline // Create RabbitService await SetupAsync().ConfigureAwait(false); await Console.Out.WriteLineAsync("Setting up Workflow...").ConfigureAwait(false); var workflowName = "MyConsumerWorkflow"; _workflow = new ConsumerDataflow <WorkState>( rabbitService: _rabbitService, workflowName: workflowName, consumerName: "ConsumerFromConfig", consumerCount: ConsumerCount) .SetSerializationProvider(_serializationProvider) .SetEncryptionProvider(_encryptionProvider) .SetCompressionProvider(_compressionProvider) .SetMetricsProvider(_metricsProvider) .WithBuildState <Message>("Message", MaxDoP, false, 200) .WithDecryptionStep(MaxDoP, false, 200) .WithDecompressionStep(MaxDoP, false, 200) .AddStep(RetrieveObjectFromState, $"{workflowName}_RetrieveObjectFromState", true, null, MaxDoP, EnsureOrdered, 200) .AddStep(ProcessStepAsync, $"{workflowName}_ProcessStep", !SimulateIODelay, null, MaxDoP, EnsureOrdered, 200) .AddStep(AckMessage, $"{workflowName}_AckMessage", true, null, MaxDoP, EnsureOrdered, 200) .WithErrorHandling(ErrorHandlingAsync, 200, MaxDoP, false) .WithFinalization(FinalizationAsync, MaxDoP, false); await Console.Out.WriteLineAsync("Starting Workflow...").ConfigureAwait(false); await _workflow .StartAsync() .ConfigureAwait(false); Stopwatch = Stopwatch.StartNew(); await Console.Out.WriteLineAsync("Waiting for workflow to be signaled complete...").ConfigureAwait(false); await _workflow.Completion.ConfigureAwait(false); await Console.Out.WriteLineAsync("\r\nStatistics!").ConfigureAwait(false); await Console.Out.WriteLineAsync($"MaxDoP: {MaxDoP}, Ensure Ordered: {EnsureOrdered}").ConfigureAwait(false); await Console.Out.WriteLineAsync($"SimulateIODelay: {SimulateIODelay}, MinIODelay: {MinIODelay}ms, MaxIODelay: {MaxIODelay}ms").ConfigureAwait(false); await Console.Out.WriteLineAsync($"AwaitShutdown: {AwaitShutdown}, LogOutcome: {LogOutcome}").ConfigureAwait(false); await Console.Out.WriteLineAsync($"UseStreamPipeline: {UseStreamPipeline}").ConfigureAwait(false); await Console.Out.WriteLineAsync($"Finished processing {GlobalCount} messages (Steps: {GlobalCount * ActionCount}) in {Stopwatch.ElapsedMilliseconds} milliseconds.").ConfigureAwait(false); var rate = GlobalCount / (Stopwatch.ElapsedMilliseconds / 1.0) * 1000.0; await Console.Out.WriteLineAsync($"Rate: {rate} msg/s.").ConfigureAwait(false); await Console.Out.WriteLineAsync($"Rate: {rate * ActionCount} actions/s.").ConfigureAwait(false); await Console.Out.WriteLineAsync("\r\nClient Finished! Press any key to start the shutdown!").ConfigureAwait(false); Console.ReadKey(); // checking for memory leak (snapshots) await Console.Out.WriteLineAsync("\r\nAll finished cleanup! Press any key to exit...").ConfigureAwait(false); Console.ReadKey(); // checking for memory leak (snapshots) }