简体   繁体   English

Azure 服务总线 - 已取消的计划消息重新排队

[英]Azure Service Bus - cancelled scheduled messages getting re-queued

I'm using the latest Java bindings (v3.1.3) for Azure Service Bus: https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/servicebus我正在为 Azure 服务总线使用最新的 Java 绑定 (v3.1.3): https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/servicebus

When I create a new queue client, schedule a message, and cancel it...当我创建一个新的队列客户端时,安排一条消息,然后取消它......

QueueClient sendClient = new QueueClient(new ConnectionStringBuilder(connectionString, queueName), ReceiveMode.PEEKLOCK);
long sequenceNumber = sendClient.scheduleMessage(message, instant);
...
sendClient.cancelScheduledMessage(sequenceNumber)

...the code appears to work as intended: The active message count goes to 0. But as soon as the scheduled message gets to the time it was supposed to be scheduled (I tested with 10 seconds and 100 seconds in the future), the message sometimes gets re-queued with a new sequence number. ...代码似乎按预期工作:活动消息计数变为 0。但是一旦预定的消息到达预定的时间(我在未来测试了 10 秒和 100 秒),消息有时会使用新的序列号重新排队。 I'm not getting any errors when scheduling or cancelling the messages.在安排或取消消息时我没有收到任何错误。 Is there something I can do to make sure cancelled messages don't get re-queued?我可以做些什么来确保取消的消息不会重新排队吗?

From my own testing, I found that cancelling a service bus message in a short time frame after the scheduled message was sent to the service bus queue does not always process the cancellation as expected.从我自己的测试中,我发现在预定消息发送到服务总线队列后的短时间内取消服务总线消息并不总是按预期处理取消。 In general we're talking only a few seconds but the behaviour is not entirely consistant.一般来说,我们只谈了几秒钟,但行为并不完全一致。

My conslusion is that there will be some latency between the scheduled message being queued to when a cancellation of that same message is registered which means that canclelling a scheduled message almost straight away after sending it to the queue will not always stop it being processed.我的结论是,预定消息排队到注册取消同一消息时会有一些延迟,这意味着在将预定消息发送到队列后几乎立即取消预定消息并不总是会停止处理。

Therefore in my environment, I had to provide my own fallback feature to check additional custom properties in the service bus message, so when it arrives back at my subscriber app, i use an IF Statement to check the status of the custom property so I can chose whether to ignore it and not process anything more.因此,在我的环境中,我必须提供自己的后备功能来检查服务总线消息中的其他自定义属性,因此当它返回我的订阅者应用程序时,我使用 IF 语句检查自定义属性的状态,以便我可以选择是否忽略它并且不再处理任何东西。

This really caught me out for a little while as my environement was rather complex and I assumed there was some issue in my code somwhere along the line which in the end, once I factored in the above annomlly and started to see how the service bus was responding to the schedule message cancellation, I was able to overcome this issue.这真的让我困惑了一会儿,因为我的环境相当复杂,我认为我的代码中某处存在一些问题,最后,一旦我考虑了上述因素并开始查看服务总线是如何运行的响应计划消息取消,我能够克服这个问题。

You can schedule messages either by setting the ScheduledEnqueueTimeUtc property when sending a message through the regular send path, or explicitly with the ScheduleMessageAsync API.您可以通过在通过常规发送路径发送消息时设置ScheduledEnqueueTimeUtc属性来安排消息,也可以使用ScheduleMessageAsync API 显式ScheduleMessageAsync The latter immediately returns the scheduled message's SequenceNumber , which you can later use to cancel the scheduled message if needed.后者立即返回预定消息的SequenceNumber ,您可以稍后使用它来取消预定消息(如果需要)。

Cancels the enqueuing of an already sent scheduled message, if it was not already enqueued.取消已发送的预定消息的入队(如果尚未入队)。 This is an asynchronous method returning a CompletableFuture which completes when the message is cancelled.这是一个异步方法,返回一个CompletableFuture ,它在消息被取消时完成。

So, I suggest that you could use cancelScheduledMessageAsync to cancel scheduled message.所以,我建议你可以使用cancelScheduledMessageAsync来取消预定的消息。

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

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