Path: redb-route/demo/SerialNumbersDemo/SerialNumbers.Core/Routes/Processing/IntakeRouteBuilder.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.Core/Routes/Processing/IntakeRouteBuilder.cs
----
using Microsoft.Extensions.Logging;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.File;
using redb.Route.RedbCore.Extensions;
using SerialNumbers.Core.Infrastructure;
using SerialNumbers.Core.Integration.Xml;
using SerialNumbers.Core.Services;
namespace SerialNumbers.Core.Routes.Processing;
///
/// The common intake for every transport: archive the raw file first, then route it by what it is.
///
public sealed class IntakeRouteBuilder : RouteBuilder
{
protected override void Configure()
{
var settings = ModuleSettings.FromContext(Context!);
From(RouteUris.Intake)
.RouteId("intake")
.MessageHistory()
.ConvertBody()
// The raw copy goes to the archive before anything can fail on its content.
.SetHeader(SerialHeaders.ArchivePath, e => ArchivePaths.For(
e.In.GetHeader(SerialHeaders.Partner)!,
e.In.GetHeader(SerialHeaders.FileName)!,
DateTimeOffset.UtcNow))
.To(FileDsl.Write(settings.ArchiveDirectory).FileName("${header.serials.archivePath}"))
.Log("${header.serials.partner}: ${header.serials.fileName} archived as ${header.serials.archivePath}")
.SetHeader(SerialHeaders.MessageType, e => XmlMessageInspector.RootElementName(e.In.Body as string))
.Choice()
.When(e => e.In.GetHeader(SerialHeaders.MessageType) is null)
.ProcessWithRedb(IntakeRecorder.RecordInvalidAsync)
.Log("${header.serials.partner}: ${header.serials.fileName} is not well-formed XML, recorded as Invalid", LogLevel.Warning)
.When(XPath("/SerialNumberRequest"))
.Log("${header.serials.partner}: ${header.serials.fileName} is a serial number request")
.To(RouteUris.SerialNumberRequest)
.Otherwise()
// Handled context-wide by ExceptionRouteBuilder: archived, recorded, parked.
.ThrowException("The message type has no route in this module.")
.EndChoice();
}
}