Path: redb-route/demo/SerialNumbersDemo/SerialNumbers.Worker/ProductConsole.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/demo/SerialNumbersDemo/SerialNumbers.Worker/ProductConsole.cs ---- using redb.Route.Core; using SerialNumbers.Core; using SerialNumbers.Core.Catalog; namespace SerialNumbers.Worker; /// /// Product status changes typed into the console, for example status 04607005550001 Active. /// /// A command goes through a to direct:set-product-status, the /// endpoint the REST API calls: code running in the same process as the routes uses them exactly as a /// web page does over HTTP, and gets the same answer back. /// /// public static class ProductConsole { public static Task RunAsync(RouteContext hub, CancellationToken stopping) => Task.Run(async () => { using var producer = new ProducerTemplate(hub); producer.Start(); while (!stopping.IsCancellationRequested) { var line = Console.ReadLine(); if (line is null) return; // no console input, for example when started without a terminal var words = line.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (words.Length == 0) continue; if (words is not ["status", var gtin, var status]) { Console.WriteLine("Usage: status "); continue; } var message = new Message(new ProductStatusChange(status, ChangedBy: "console")); message.Headers[SerialHeaders.Gtin] = gtin; try { // ProductStatusResult, or ApiError for an unknown product or status. Console.WriteLine(await producer.RequestBody(RouteUris.SetProductStatus, message, stopping)); } catch (Exception ex) when (ex is not OperationCanceledException) { // The route logged the failure; the console shows it and keeps reading commands. Console.WriteLine($"The status change failed: {ex.Message}"); } } }, stopping); }