使用 Windows 服务和 SQL Server 在 OneWay WCF 消息中排队 [英] Queuing in OneWay WCF Messages using Windows Service and SQL Server

查看:30
本文介绍了使用 Windows 服务和 SQL Server 在 OneWay WCF 消息中排队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为 WCF 服务请求实现排队机制.该服务将由客户端以单向方式调用.这些请求消息应存储在 SQL Server 数据库中,并且 Windows 服务将消息排入队列.处理请求的时间将是可配置的.如果消息处理发生错误,则需要重试最多100次,如果仍然失败则需要终止.

I need to implement a queuing mechanism for WCF service requests. The service will be called by clients in a one-way manner. These request messages should be stored in a SQL Server database and a Windows Service queues the messages. The time at which the requests are processed will be configurable. If there happens error in processing the message, it need to be retried up to 100 times and if still fails it need to be terminated.

还应该有一种机制来监控一天的交易次数和失败次数.

Also there should be a mechanism to monitor the number of transaction made on a day and number of failures.

问题

  1. 如果我使用 MSMQ,客户端可能会在不知道服务端点的情况下将消息转发到队列.但我使用 SQL Server 来存储请求消息.客户端如何将请求发送到 SQL Server?

  1. If I were using MSMQ, clients could have forwarded the message to queue without knowing the service endpoint. But I am using SQL Server to store the request messages. How the clients can put the requests to SQL Server?

解决方案可行吗?我们是否有任何文章/书籍解释如何实施上述内容?

Is the solution feasible? Do we have any article/book that explains how to implement the above?

在这种情况下,防止服务和客户端进入故障状态的步骤是什么?

What are the steps to prevent service and client reaching faulted state in this scenario?

将传入消息存储到数据库的最佳方法是什么?

What is the best method to store incoming message to database?

实现重试机制的最佳方法是什么?任何已经存在的东西,这样我就不必重新发明轮子了?

What is the best method to implement retry mechanism? Anything already exist so that I don't have to reinvent the wheel?

有没有解释这个实现的书/文章?

Is there any book/article that explains this implementation?

<小时>

注意事项


NOTES

  1. 消息的内容将是复杂的 XML.例如,员工的差旅费用项目或员工列表.

<小时>

阅读

  1. 将 WCF 请求记录到数据库

保证在 WCF 服务中处理数据

MSMQ 与 SQL Server 服务代理

是否可以持久化 WCF 消息然后将其转发到目标服务?

WCF 4 路由服务 - 协议桥接问题

https://softwareengineering.stackexchange.com/问题/134605/designing-a-scalable-and-robust-retry-mechanism

集成 SQL Service Broker 和 NServiceBus

订阅者是否也可以发布/发送消息在 NServiceBus 中?

推荐答案

我是一名 DBA,所以我的回答很有趣,但我会这样做:

I'm a DBA, so that flavors my my response, but here's what I'd do:

  1. 如果您使用的是 SQL 2005+,请使用 Service Broker 来存储消息在数据库中而不是将它们存储在表中.你得到一个队列机制与此,所以你可以摆脱MSMQ.您还将拥有一个表,但它只会存储会话句柄(本质上是指向消息的指针)以及尝试此消息的次数.最后,您需要某种死信箱",将达到重试阈值的邮件发送到其中.
  2. 在您的消息处理代码中,执行以下操作:
    • 开始交易
    • 从队列中接收消息
    • 如果重试次数大于阈值,则将其移至死信箱并提交
    • 为这条消息增加桌面上的计数器
    • 处理消息
    • 如果处理成功,提交事务
    • 如果处理失败,则在队列中放入一条内容相同的新消息,然后提交事务

请注意,没有任何计划回滚.Service Broker 中的回滚可能很糟糕;如果在没有成功接收的情况下回滚 5 次,则队列将被禁用入队和出队.但是您仍然希望在消息处理器在处理过程中死亡(即服务器崩溃)的情况下进行事务处理.

Notice that there aren't any planned rollbacks. Rollbacks in Service Broker can be bad; if you rollback 5 times without a successful receive, the queue will become disabled for both enqueuing and dequeuing. But you still want to have transactions for the case when your message processor dies in the middle of processing (i.e. the server crashes).

这篇关于使用 Windows 服务和 SQL Server 在 OneWay WCF 消息中排队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆