Home > database >  masstransit publish with context
masstransit publish with context

Time:10-25

How to pass custom value to MessageId when publish message ?

My topic endpoint configuration

cfg.Message<OrderSubmitted>(configTopology =>
{
     configTopology.SetEntityName("my-topic");

});

Somewhere in service I publish message like this

await azureServiceBus.Publish<OrderSubmitted>(contract);

How I can provide custom MessageId while publishing ? (I need this because I want to use ASB duplicate message detection)

I looked into source code of MassTransit and it seems like there is an overload method where I can pass IPipe<PublishContext<T>> publishPipe as 2nd parameter but I don't understand but question is how to create this object properly ?

CodePudding user response:

You can set any of the envelope properties and message headers by specifying a callback with Send or Publish.

await bus.Publish<OrderSubmitted>(message, x =>
{
    x.MessageId = someGuid;
});
  • Related