简体   繁体   English

当您尝试取消已排队的计划Azure服务总线消息时会发生什么?

[英]What happens when you try to cancel a scheduled Azure service bus message that has already been enqueued?

I'm trying to come up with the best way to schedule a message for an Azure service bus queue or topic while leaving the option open for immediately sending a message instead of the scheduled message. 我正在尝试为安排Azure服务总线队列或主题的消息的最佳方法,同时保持打开选项以立即发送消息而不是计划的消息。 I want to make sure I can protect myself against creating a duplicate message if I try to send the replacement message right at or after the scheduled time of the first message. 如果我尝试在第一封邮件的预定时间或之后立即发送替换邮件,我想确保自己可以防止创建重复邮件。

What will happen if I try to cancel a scheduled message with CancelScheduledMessageAsync (for both QueueClient and TopicClient classes) after the message has already been enqueued? 如果消息已入队,如果我尝试使用CancelScheduledMessageAsync(对于QueueClient和TopicClient类)取消计划的消息,将会发生什么情况? Will it throw an exception? 会抛出异常吗?

According to your description, I found a blog ( Canceling Scheduled Messages ) talking about the similar issue. 根据您的描述,我发现了一个博客(正在取消预定的消息 ),谈论着类似的问题。

Before version 3.3.1, a scheduled message needs to be canceled prior to becoming visible, it was not possible . 在版本3.3.1之前, 需要取消计划的消息才能使其可见,这是不可能的 And any attempt to access its value would result in InvalidOperationException . 任何访问其值的尝试都将导致InvalidOperationException Therefore, any messages scheduled in the future and no longer needed would be "stuck" on the broker until the later time. 因此,将来计划的任何不再需要的消息都将“滞留”在代理上,直到以后。

With Microsoft Azure Service Bus >= 3.3.1 QueueClient or TopicClient can be used to schedule a message and cancel it later. 使用Microsoft Azure Service Bus > = 3.3.1 QueueClient ,可以使用QueueClientTopicClient安排消息并稍后将其取消。

Also, I have tested it on my side via the following code: 此外,我还通过以下代码对它进行了测试:

BrokeredMessage brokerMsg= new BrokeredMessage("Hello World!!!");
long sequenceNumber = await queueClient.ScheduleMessageAsync(brokerMsg, DateTimeOffset.UtcNow.AddSeconds(30));

await Task.Delay(TimeSpan.FromMinutes(1));
// Cancel scheduled message
await queueClient.CancelScheduledMessageAsync(sequenceNumber);

I logged into azure portal and checked ACTIVE MESSAGE COUNT and SCHEDULED MESSAGE COUNT . 我登录到Azure门户并检查了“活动消息数”和“ 计划消息数” I could cancel the scheduled message before it becomes active, but if I cancel the scheduled message via the sequenceNumber after the scheduled message becomes active, then I would retrieve the exception as follows: 我可以在预定消息变为活动状态之前取消预定消息,但是如果我在预定消息变为活动状态之后通过sequenceNumber取消预定消息,那么我将按以下方式检索异常:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM