diff --git a/src/Transports/Kafka/Wolverine.Kafka/IKafkaEnvelopeMapper.cs b/src/Transports/Kafka/Wolverine.Kafka/IKafkaEnvelopeMapper.cs index 441bb1b1a..43c856ce8 100644 --- a/src/Transports/Kafka/Wolverine.Kafka/IKafkaEnvelopeMapper.cs +++ b/src/Transports/Kafka/Wolverine.Kafka/IKafkaEnvelopeMapper.cs @@ -26,7 +26,20 @@ public JsonOnlyMapper(KafkaTopic topic, JsonSerializerOptions options) public void MapEnvelopeToOutgoing(Envelope envelope, Message outgoing) { outgoing.Key = envelope.GroupId; - outgoing.Value = JsonSerializer.Serialize(envelope.Message, _options); + + if (envelope.Data != null && envelope.Data.Any()) + { + outgoing.Value = Encoding.Default.GetString(envelope.Data); + } + else if (envelope.Message != null) + { + outgoing.Value = JsonSerializer.Serialize(envelope.Message, _options); + } + else + { + throw new InvalidOperationException( + $"Envelope {envelope.Id} has neither {nameof(envelope.Data)} nor {nameof(Envelope.Message)}"); + } } public void MapIncomingToEnvelope(Envelope envelope, Message incoming)