Is there a way to get the message headers from RabbitMQ (different than the headers set through MassTransit)?
My use case is, I’m trying to read the timestamp added by RabbitMQ, timestamp_in_ms
(previously generated by RabbitMQ plugin, now native via configuration).
I’ve checked the docs and debugged, but couldn’t find any RabbitMQ header key in what I receive.
I’m aware MassTransit adds its own “SentTime” on the message envelope, but I believe this is different than the timestamp
as filled in by RabbitMQ itself (with server local time of the broker).
You can access any transport headers (including RabbitMQ) from within a consumer’s Consume
method using:
if (context.ReceiveContext.TransportHeaders.TryGetHeader("timestamp_in_ms", out object timestampHeader))
{
if(timestampHeader is AmqpTimestamp ts)
{
var dateTime = DateTimeConstants.Epoch + TimeSpan.FromMilliseconds(ts.UnixTime);
}
}