Path: redb-route/tests/redb.Route.Tests.Kafka/KafkaHeaderMappingCharacterizationTests.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/tests/redb.Route.Tests.Kafka/KafkaHeaderMappingCharacterizationTests.cs ---- using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Kafka; namespace redb.Route.Tests.Kafka; /// /// What crosses a Kafka record today, producer to consumer: pinned before the header filter strategy /// takes the rule over, so the transport's default keeps it exactly. /// The producer sends every exchange header but the Camel* and kafka.* ones (Camel's strategy), as text; the consumer takes every record /// header back, as text. A control header of another transport (redbHttp.Method) and a credential cross too. /// [Trait("Category", "Integration")] public sealed class KafkaHeaderMappingCharacterizationTests { private const string Brokers = "localhost:29092"; [Fact] public async Task ProducerToConsumer_TheHeadersThatCrossTheRecord() { var topic = $"hdr-char-{Guid.NewGuid():N}"; var received = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using var ctx = new RouteContext(); ctx.AddComponent(new KafkaComponent()); ctx.AddRoutes(r => r .From($"kafka://{topic}?brokers={Brokers}&groupId=grp-{Guid.NewGuid():N}&autoOffsetReset=Earliest") .Process(e => received.TrySetResult(e))); await ctx.Start(); var exchange = new Exchange(new Message("body")); exchange.In.Headers["X-Corr"] = "c1"; exchange.In.Headers["X-Int"] = 42; exchange.In.Headers["X-Null"] = null; exchange.In.Headers["Authorization"] = "Bearer secret"; exchange.In.Headers["redbHttp.Method"] = "DELETE"; exchange.In.Headers["CamelCustom"] = "camel"; exchange.In.Headers["kafka.custom"] = "kafka"; exchange.In.Headers[KafkaHeaders.PartitionKey] = 0; var producer = ctx.GetEndpoint($"kafka://{topic}?brokers={Brokers}").CreateProducer(); await producer.Start(); await producer.Process(exchange); await producer.Stop(); var headers = (await received.Task.WaitAsync(TimeSpan.FromSeconds(30))).In.Headers; headers["X-Corr"].Should().Be("c1"); headers["X-Int"].Should().Be("42", "a value crosses as its text"); headers["X-Null"].Should().Be("", "a null value crosses as an empty value, it is not skipped"); headers["Authorization"].Should().Be("Bearer secret", "nothing filters a credential"); headers["redbHttp.Method"].Should().Be("DELETE", "a control header of another transport crosses (finding 3.1)"); headers.Should().NotContainKey("CamelCustom", "Camel* headers stay off the record, as Camel's strategy keeps them"); headers.Should().NotContainKey("kafka.custom", "kafka.* headers stay off the record too"); headers.Should().NotContainKey(KafkaHeaders.PartitionKey, "the producer's own CamelKafka* headers never reach the next hop"); headers[KafkaHeaders.Topic].Should().Be(topic, "the consumer adds its own metadata"); } }