Path: redb-route/redb.Route.Amqp/AmqpMessageHelper.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/redb.Route.Amqp/AmqpMessageHelper.cs ---- using System.Text; using Amqp; using Amqp.Framing; using redb.Route.Abstractions; using AmqpMessage = global::Amqp.Message; namespace redb.Route.Amqp; /// /// Helpers for AMQP message body extraction and property mapping. /// internal static class AmqpMessageHelper { /// /// Extracts the body from an AMQP message as raw bytes or string. /// Handles: string, byte[], Data section, AmqpValue section. /// public static object ExtractBody(AmqpMessage message) { return message.Body switch { byte[] bytes => bytes, Data data => data.Binary, string s => Encoding.UTF8.GetBytes(s), AmqpValue value => Encoding.UTF8.GetBytes(value.Value?.ToString() ?? string.Empty), null => Array.Empty(), _ => Encoding.UTF8.GetBytes(message.Body.ToString() ?? string.Empty) }; } /// /// Copies the AMQP application-properties that lets in into a redb.Route message's /// headers; is the one they come into (for a request-reply's reply, the request's). /// public static void CopyApplicationProperties(AmqpMessage amqpMessage, redb.Route.Core.Message routeMessage, IHeaderFilterStrategy headerFilter, IExchange exchange) { if (amqpMessage.ApplicationProperties?.Map == null) return; foreach (var kvp in amqpMessage.ApplicationProperties.Map) { var key = kvp.Key?.ToString(); if (string.IsNullOrEmpty(key)) continue; object? value = kvp.Value switch { byte[] bytes => Encoding.UTF8.GetString(bytes), string str => str, _ => kvp.Value }; if (value is null) continue; if (headerFilter.FilterIncoming(key, value, exchange)) continue; routeMessage.Headers[key] = value; } } }