简体   繁体   English

如何在WCF端点上延迟从MSMQ挑选消息

[英]How to delay picking of messages from MSMQ on a WCF endpoint

Can anyone suggest me a solution for a scenario where I want the msmq message from the queue to be picked up after some delay as there are workflows which need to trigger in the database before I pickup the msmq message for processing and I am seeing some delay there in the workflow processing. 任何人都可以为我提供一些解决方案,该方案是我希望延迟一段时间后从队列中提取msmq消息,因为在拾取msmq消息进行处理之前,数据库中需要触发一些工作流,并且看到一些延迟在工作流处理中。 Is there some setting or built in features as Sleep and all that is not the solution I am looking for or delaying at the client end as there is a transaction running on the client end which needs to execute all at once and cannot delay process just the call to the Queue. 是否有某些设置或内置功能(例如“睡眠”),而这不是我正在寻找的解决方案,还是不是在客户端延迟的原因,因为在客户端运行的事务需要立即执行所有事务,而不能仅延迟进程调用队列。

Thanks, Bala 谢谢,巴拉

I solved this by creating another queue as Pending queue. 我通过创建另一个队列作为Pending队列解决了这个问题。 Once I received the message at the endpoint, I queued appropriate message which do not require immediate processing to another queue using below queue. 一旦在端点接收到消息,就将适当的消息放入队列中,这些消息不需要立即使用下面的队列处理到另一个队列。

PendingQueue.Send(queuedMessage);

The message was removed in Active queue automatically. 该邮件已自动删除在活动队列中。

There is another Timer service which parses this Pending queue and re-queues the message to active as and when required. 还有另一个计时器服务,可以解析此挂起队列并在需要时重新排队使消息处于活动状态。

However remember to add custom xmlformatter to the pending queue when initializing queue in timer, as in below queue, as the queue will not know how to de-serialize the contract object otherwise. 但是,请记住在计时器中初始化队列时(如在下面的队列中),将定制的xmlformatter添加到挂起的队列中,因为队列将不知道如何反序列化协定对象。

//Create a Formatter that can deserialize the Messages.
XmlMessageFormatter xmlMessageFormatter = new XmlMessageFormatter
    {
        TargetTypes = new[]
            {typeof (DataContract)}
    };
_pendingQueue.Formatter = xmlMessageFormatter;

Then I used the following code to retrieve object at appropriate time. 然后,我使用以下代码在适当的时间检索对象。

List<Message> messages = PendingQueue.GetAllMessages().ToList();
foreach (Message x in messages)
{
    DataContract y = x.Body as DataContract;
    if (!<some condition>) 
        continue;    
    //Remove the object from pending queue.
    PendingQueue.ReceiveById(x.Id);
    _mproxy.QueueMessage(y)
}

Above did the trick for me. 以上为我做了把戏。 Also do remember that the active queue should not be transactional, otherwise, if the message execution fails when re queued, the original caller can not be notified. 还要记住,活动队列不应是事务性的,否则,如果重新排队时消息执行失败,则无法通知原始调用者。 Please feel free to improve the solution. 请随时改进解决方案。

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

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