C# 在不同的Azure服务总线队列中使用相同的消息id导致错误

C# 在不同的Azure服务总线队列中使用相同的消息id导致错误,c#,azure,async-await,azureservicebus,azure-servicebus-queues,C#,Azure,Async Await,Azureservicebus,Azure Servicebus Queues,我在下面的函数中遇到问题,该函数将计划消息添加到Azure服务总线队列。当调用该方法时,创建方法将弹出 var sendCodeSequence = await queueClient.ScheduleMessageAsync(message, new DateTimeOffset(endTime)); 即使消息被添加到队列中,我的控制器中的堆栈中也不会抛出异常 我的问

我在下面的函数中遇到问题,该函数将计划消息添加到Azure服务总线队列。当调用该方法时,创建方法将弹出

var sendCodeSequence = await queueClient.ScheduleMessageAsync(message, 
                                                              new DateTimeOffset(endTime));
即使消息被添加到队列中,我的控制器中的堆栈中也不会抛出异常

我的问题

  • 如果我在同一服务总线上的不同队列中多次使用相同的消息id,那么在创建和删除每个队列中的消息id时会遇到问题吗,即使它们都有不同的序列id

  • 我在代理消息构造函数和消息id属性中使用了一个消息id,这可以吗?还是会导致添加更多消息并将其从队列中删除的问题

  • 例如,我在同一服务总线命名空间上有5个不同的队列。可能会添加5条不同的消息,每个队列一条,所有消息都具有相同的代理消息id。所以,不知道这是否会导致任何问题

    下面是一个方法,我使用我的事件id作为消息id将计划消息添加到队列中

    public async Task <long> CreateHostPointCodeMessage(int eventId, YogaSpaceDuration duration, DateTime utcEventDateTime) {
      string serviceBusConnectionString = System.Configuration.ConfigurationManager.AppSettings["ServiceBusConnectionString"];
      string queueName = System.Configuration.ConfigurationManager.AppSettings["PreEventPointsCodeQueueName"];
    
      var queueClient = QueueClient.CreateFromConnectionString(serviceBusConnectionString, queueName);
      int length = Convert.ToInt16(EnumHelper.GetDisplayName(duration).Split(' ')[0]);
      var endTime = DateTime.SpecifyKind(utcEventDateTime.AddMinutes(length).AddMinutes(-5), DateTimeKind.Utc);
    
      BrokeredMessage message = new BrokeredMessage(eventId.ToString());
      message.MessageId = eventId.ToString();
      message.ScheduledEnqueueTimeUtc = endTime;
    
      var sendCodeSequence = await queueClient.ScheduleMessageAsync(message, new DateTimeOffset(endTime));
      await queueClient.CloseAsync();
    
      return sendCodeSequence;
    }
    
    公共异步任务CreateHostPointCodeMessage(int-eventId、YogaSpaceDuration duration、DateTime-utcEventDateTime){
    字符串serviceBusConnectionString=System.Configuration.ConfigurationManager.AppSettings[“serviceBusConnectionString”];
    字符串queueName=System.Configuration.ConfigurationManager.AppSettings[“PreEventPointsCodeQueueName”];
    var queueClient=queueClient.CreateFromConnectionString(serviceBusConnectionString,queueName);
    int length=Convert.ToInt16(EnumHelper.GetDisplayName(duration).Split(“”)[0]);
    var endTime=DateTime.SpecifyKind(utcEventDateTime.AddMinutes(length).AddMinutes(-5),DateTimeKind.Utc);
    BrokeredMessage=新的BrokeredMessage(eventId.ToString());
    message.MessageId=eventId.ToString();
    message.ScheduledEnqueueTimeUtc=endTime;
    var sendCodeSequence=wait queueClient.ScheduleMessageAsync(message,new DateTimeOffset(endTime));
    等待queueClient.CloseAsync();
    返回sendCodeSequence;
    }
    

    仅供参考-我正在使用“Microsoft.ServiceBus.Messaging”将消息发送到队列,但根据这一点,我应该使用“Microsoft.Azure.ServiceBus”我不知道这是否有任何区别?

    将具有相同id的消息发送到命名空间下的不同队列没有任何错误

    即使您可以向同一队列发送任意数量的具有相同id的消息,除非队列的属性设置为“True”


    仅对于启用了“RequiresDuplicateDetection”属性的队列,具有重复Id的消息将丢失。

    较新的命名空间Microsoft.Azure.ServiceBus是完全开源的,所有异步的,并且它针对新的.Net标准。所以你应该继续使用这个。