Configure Deduplication on Azure Service Bus Queue with MassTransit

I have found the following question (How to configure the RequiresDuplicateDetection for AzureServiceBus topics) about how to set the RequiresDuplicationDetection property when configuring a publish topic from a producer application in MassTransit. However, I have not been able to find out how to do it for commands that are transmitted to a queue with Send rather than Publish.

Additionally, I have found that when configuring a consumer of one the queues in question I can set the property easily, as shown below. This however is not ideal for my use case, if possible I would much rather the producer set this property when it starts and creates the queue.

cfg.ReceiveEndpoint(queue, e =>{
  e.RequiresDuplicateDetection = true;
  e.ConfigureConsumer<JobEventConsumer>(registrationContext, consumerConfig =>{
    consumerConfig.UseMessageRetry(r =>{
      r.Interval(10, TimeSpan.FromMilliseconds(200));

Update: After a bit more investigation I have also found that setting the property to true at the global config level doesn't seem to work either. Code shown below

class Program {
  static async Task Main(string[] args) {
    EndpointConvention.Map<ExtractionRequest>(new Uri("queue:test-queue"));
    var busControl = Bus.Factory.CreateUsingAzureServiceBus(cfg =>{
      cfg.Host("My connection string");
      cfg.RequiresDuplicateDetection = true;
      cfg.EnablePartitioning = true;

    await busControl.StartAsync();
    try {
      do {
        string value = await Task.Run(() =>{
          Console.WriteLine("Enter message (or quit to exit)");
          Console.Write("> ");
          return Console.ReadLine();

        if ("quit".Equals(value, StringComparison.OrdinalIgnoreCase)) break;

        await busControl.Send<ExtractionRequest>(new {});
      while (true);
    finally {
      await busControl.StopAsync();


public interface ExtractionRequest {}

Any advice on how to turn RequiresDuplicationDetection on for a queue from the producer is welcomed.

Thanks in advance, James.

1 answer

  • answered 2020-09-18 17:50 Chris Patterson

    You can't set queue properties from a message sender, it's the responsibility of the receive endpoint.

    The receive endpoint is the responsible component because it's declaring the queue and related attributes.

    The reason publish is different is because topics can be configured by the producer, since there may be multiple consumer subscriptions on a single topic.