Path: redb-route/demo/SerialNumbersDemo/SerialNumbers.Core/Services/ResponseRenderer.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/Services/ResponseRenderer.cs
----
using redb.Core;
using redb.Route.Abstractions;
using SerialNumbers.Core.Integration.Xml;
using SerialNumbers.Domain.Entities;
namespace SerialNumbers.Core.Services;
/// Turns an outbox row into the XML response the partner receives.
public static class ResponseRenderer
{
public static async Task RenderAsync(IRedbService redb, IExchange exchange, CancellationToken ct)
{
// The sql: consumer copies the columns of the polled row into headers.
var responseId = Convert.ToInt64(exchange.In.Headers["response_object_id"]);
var response = await redb.LoadAsync(responseId, cancellationToken: ct)
?? throw new InvalidOperationException($"Response object {responseId} was not found.");
var props = response.Props;
var xml = new SerialNumberResponseXml
{
RequestId = props.RequestId,
Gtin = props.Gtin,
Status = props.Accepted ? "Accepted" : "Rejected",
Reason = props.RejectionReason,
Quantity = props.Quantity,
};
if (props.AllocationId is long allocationId)
{
var serials = await SerialNumberAllocator.SerialNumbersOfAsync(redb, allocationId, ct);
xml.SerialNumbers = serials.Select(s => s.ToString("D12")).ToList();
}
exchange.In.Body = xml;
exchange.In.Headers[SerialHeaders.FileName] = ArchivePaths.ResponseFileName(props.RequestId, responseId);
}
}