简体   繁体   English

消息队列方案-队列和远程Web服务

[英]Message Queueing Scenario - Queueing and remote web service

(Please see Slide Links below) I am trying to create and audit-able request and response service that interacts with a remote web service. (请参阅下面的幻灯片链接)我正在尝试创建与远程Web服务交互的,可审核的请求和响应服务。 I am having some trouble deciding on the correct implementation for my approach. 我在为我的方法选择正确的实现时遇到一些麻烦。 Basically, how I need the implementation to work is as follows. 基本上,我需要执行该工作的方式如下。

  • A Requester application (A) will generate a request XML and add it to a request 'queue'. 请求者应用程序(A)将生成请求XML,并将其添加到请求“队列”中。 A request processor will then get an unprocessed record from the 'queue' and POST it to a remote web service (X) with a unique ID, if the request is not successful the request is kept/(requestComplete flag = 0) in the request 'queue' to be retried at a later time. 然后,请求处理器将从“队列”中获取未处理的记录,并将其发布到具有唯一ID的远程Web服务(X),如果请求成功,则请求将被保留/(requestComplete标志= 0) “队列”将在以后的时间重试。

  • If the request is successful it is kept/(requestComplete flag = 1) and is not retried 如果请求成功它被保持/(requestComplete标志= 1),并且不重试

  • At A later date a Receiver web service (B) receives a response from the 'X' service that was called in the request. 稍后,接收者Web服务(B)从请求中调用的“ X”服务接收响应。

  • 'B' then searches through the request records to find the original request and correlates the 'A' request and the 'X' response (matching using the unique ID). 然后,“ B”搜索请求记录以查找原始请求,并将“ A”请求和“ X”响应相关联(使用唯一ID进行匹配)。

  • Some additional processing is done with the response and the record from the 'queue' is updated as completed. 响应会执行一些其他处理,并且来自“队列”的记录将更新为已完成。

In this way there is a complete audit trail from request to response. 这样,从请求到响应都有完整的审核跟踪。 I can see when the original request was made, if there is an error with the request by looking at the 'queue' record. 通过查看“队列”记录,可以看到原始请求是何时发出的,如果请求有错误。 Likewise with the response I can see when it was received if at all. 同样,通过响应,我可以看到何时收到响应。

There are two ways I have thought to implement this. 我曾考虑过两种实现此方法的方法。

  1. Scenario 1 With a database table that acts as the request queue, the response queue as well as the audit trail in one. 方案1使用一个数据库表作为一个请求队列,响应队列以及审核跟踪。 One row in a table with a GUID that can be referenced throughout any stage of the process (request->processing->receipt) and updated along the way. 带有GUID的表中的一行,可以在过程的任何阶段(请求->处理->接收)进行引用,并在此过程中进行更新。 The trouble is that this implementation from what I gather does not act like a true queue like MSMQ (push/pop), transactable and not as scalable. 问题是我收集的这种实现方式不能像MSMQ(推送/弹出)之类的真正队列那样操作,可交易且不可扩展。
  2. Scenario 2 For actual queue implementation I did some research and thought to use MSMQ that will perhaps have multiple queues; 方案2对于实际的队列实现,我进行了一些研究,并认为将使用可能具有多个队列的MSMQ。 a processor queue to deal with the processing and sending off of the request, then push that completed request to a Receiver Queue to wait for the response from 'X'. 处理器队列来处理请求的处理和发送,然后将完成的请求推送到接收器队列,以等待来自“ X”的响应。 The only trouble with this method there is no clear audit trail, ie the request is removed from the queue once it is received, likewise with the response. 这种方法的唯一麻烦是没有清晰的审计线索,即,一旦收到请求,就将其从队列中删除,同样是响应。 Unless I use a database table to store the request and response queues for auditing purposes. 除非我使用数据库表存储请求和响应队列以进行审核。 I have read that there is journal type transactions with MSMQ which does keep what records were queued but I am looking for a more complete solution or indeed advice on the matter. 我已经读过,MSMQ存在日记类型的事务,它确实将什么记录排入队列,但是我正在寻找更完整的解决方案或关于此事的建议。

Just a few notes: 只是一些注意事项:

  • The request 'A' sends to 'X' with a unique Id, 'X' sends a response to 'B' referencing that unique Id. 请求“ A”发送给具有唯一ID的“ X”,“ X”发送对引用该唯一ID的“ B”的响应。 This allows 'B' to track down request record 'A'. 这允许“ B”跟踪请求记录“ A”。
  • I need to be able to retry failed attempts to 'X' (any error 400 or 404's need to be retried) 我需要能够重试失败的“ X”尝试(需要重试任何错误400或404)
  • I need to be able to keep an audit trail for the requests/responses. 我需要能够对请求/响应进行审核跟踪。
  • I am using C#, WCF, MSMQ, SQL Server 2008 R2, VS 2012. 我正在使用C#,WCF,MSMQ,SQL Server 2008 R2,VS 2012。

If anyone has any suggestions or guidance on which avenue to pursue, any comments or any knowledge on best practices in dealing with scenarios above, it would be greatly beneficial. 如果有人对采用哪种方法有任何建议或指导,对上述方案的最佳做法有任何意见或知识,那将是非常有益的。

I would suggest looking at a service bus with sagas (my preference is Rhino Service Bus , but NServiceBus also has a lot of traction, and there's also Mass Transit ) 我建议您查看带有sagas的服务总线(我的首选是Rhino Service Bus ,但NServiceBus也有很多吸引力,并且还有Mass Transit

Basically a service bus will handle the plumbing of enqueuing (aka sending) messages, and dequeueing (aka receiving & processing them). 基本上,服务总线将处理排队(又称为发送)和出队(又称为接收和处理)的消息。 A saga will then assist with maintaining state for a conversation (where a conversation consists of multiple messages). 然后,传奇将帮助维护对话的状态(对话包含多个消息)。

The issues of retrying later can be handled quite elegantly with delayed messages in Rhino Service Bus, and timeouts in NServiceBus (I have no experience of Mass Transit). Rhino Service Bus中的延迟消息和NServiceBus中的超时(我没有使用Mass Transit的经验)可以很好地处理稍后重试的问题。

I would store the result logs in a database to make it easier to query & report on. 我会将结果日志存储在数据库中,以使其更易于查询和报告。 I would also rather use a servicebus with MSMQ (or any other queue) than use a database table as a "queue" - the former is designed precisely for your scenario, whereas the latter is a much more generic product to handle many different scenarios and thus it won't be as efficient as a queue implementation (eg MSMQ) (although it can do it - but scaling becomes harder). 我还宁愿将服务总线与MSMQ(或任何其他队列)一起使用,而不是将数据库表用作“队列”-前者是专门为您的情况设计的,而后者是一种更通用的产品,可以处理许多不同的情况,并且因此,它不会像队列实现(例如MSMQ)那样高效(尽管它可以做到-但扩展变得更加困难)。

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

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