rebus-org / Rebus.RabbitMq

:bus: RabbitMQ transport for Rebus
https://mookid.dk/category/rebus
Other
63 stars 44 forks source link

Preserve the UserId Header in the TransportMessage #44

Closed michalsteyn closed 5 years ago

michalsteyn commented 5 years ago

I need to verify that a message was sent by a specific user. In order to achieve this, the UserId Property can be used in RabbitMq. Currently, this works by sending a message in Rebus and including the RabbitMqHeaders.UserId header.

However, when receiving a message, the UserId Property is not preserved in the TransportMessage as it a Property of IBasicProperties and not one of the headers. Thus the UserId is lost to the receiver.

Am I missing something?

It seems to be a very simple fix by simply adding the following to CreateTransportMessage in RabbitMqTransport:

if (basicProperties.IsUserIdPresent())
                headers[RabbitMqHeaders.UserId] = basicProperties.UserId;

There is a whole range of useful RabbitMq Properties in the IBasicProperties instance, so other properties might be useful to add as well.