简体   繁体   English

MSMQ + WCF-延迟不断增加重试

[英]MSMQ + WCF - Retry with Growing Delay

I am using MSMQ 4 with WCF. 我在WCF中使用MSMQ 4。 We have a Microsoft Dynamics plugin putting a message on an queue. 我们有一个Microsoft Dynamics插件将消息放入队列中。 A service picks up the message and makes an HTTP request to another web server. 服务接收消息并向另一个Web服务器发出HTTP请求。 The web server responds by putting another message on a different queue. Web服务器通过将另一条消息放在不同的队列中进行响应。 A second service picks up the messages and sends the response back to Dynamics... 第二个服务接收消息并将响应发送回Dynamics ...

We have our retry queue set up to retry 3 times and then wait for 5 minutes before retrying again. 我们将重试队列设置为重试3次,然后等待5分钟,然后重试。 The Dynamics system some times takes so long (due to other plugins) that we can round-trip before the database transaction commits. Dynamics系统有时会花费很长时间(由于使用其他插件),因此我们可以在提交数据库事务之前往返。 The user's aren't seeing the update come through for another 5 minutes. 用户再过5分钟都看不到更新。

I am curious if there is a way to configure the retry mechanism to retry incrementally. 我很好奇是否有一种方法可以配置重试机制以递增方式重试。 So, the first time it fails, it only waits a few seconds. 因此,它第一次失败时,仅等待几秒钟。 If it fails a second time, it waits twice that. 如果第二次失败,它将等待两次。 And the time between retries just keeps growing. 重试之间的时间一直在增长。

The problem with just reducing the time between retries is that a bad message could easily fill up a log file. 仅减少重试之间的时间的问题在于,一条错误消息很容易填满日志文件。

It turns out there is no built-in way of doing this. 事实证明,没有内置的方法可以做到这一点。 One slightly involved option is to create multiple queues, each with its own retry/poison sub-queues, each with a growing retry delay. 一个稍微涉及的选项是创建多个队列,每个队列都有自己的重试/中毒子队列,每个队列的重试延迟都在增加。 You can reuse the same handler for each queue - the only thing that changes is the configuration. 您可以为每个队列重用相同的处理程序-唯一改变的是配置。 You also need a handler that can read the poison sub-queues ( service ) and move the message to the next queue in the chain ( client ). 您还需要一个处理程序,该处理程序可以读取有毒子队列( service )并将消息移至链中的下一个队列( client )。

So, you set receiveErrorHandling to Move . 因此,您将receiveErrorHandling设置为Move The maxRetryCycles and receiveRetryCount are just 1 . maxRetryCyclesreceiveRetryCount仅为1 Each queue will use a growing retryCycleDelay . 每个队列将使用不断增长的retryCycleDelay Each queue you create will have a poison sub-queue created for it automatically. 您创建的每个队列都会自动为其创建一个poison子队列。 You simply read from each poison sub-queue and use a client to move it to the next queue. 您只需从每个poison子队列中读取内容,并使用客户端将其移至下一个队列即可。

I am sure someone could write some code that would automatically create N queues with a growing retryCycleDelay and hook it up all programmatically. 我确信有人可以编写一些代码,该代码会随着retryCycleDelay的增加而自动创建N个队列,并以编程方式将其连接起来。 Since it is the same handler/client for every queue, it wouldn't be a big deal. 由于每个队列都使用相同的处理程序/客户端,所以这没什么大不了的。

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

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