将 MSMQ 消息从一个队列路由到另一个队列

发布于 2024-12-25 16:32:33 字数 285 浏览 0 评论 0 原文

是否有某种标准配置设置、服务或工具可以接受来自一个队列的消息并将其移至另一个队列?自动处理死消息问题,并提供一些重试能力?我认为这就是“MSMQ 消息路由”的作用,但似乎找不到有关它的文档(Windows Mobile 6 除外,我不知道这是否相关)。

上下文:

据我了解,在使用 MSMQ 时,您应该始终写入本地队列,以便不太可能出现故障,然后 X 应该将该消息移动到远程队列。我的理解有错吗?这就是像 Biztalk 这样的消息传递基础设施的用武之地吗?是否有必要先写入本地队列才能绝对确保成功?我应该自己构建 X 吗?

Is there some standard configuration setting, service, or tool that accepts messages from one queue and moves them on to another one? Automatically handling the dead message problem, and providing some of retry capability? I was thinking this is what "MSMQ Message Routing" does but can't seem to find documentation on it (except for on Windows Mobile 6, and I don't know if that's relevant).

Context:

I understand that when using MSMQ you should always write to a local queue so that failure is unlikely, and then X should move that message to a remote queue. Is my understanding wrong? Is this where messaging infrastructure like Biztalk comes in? Is it unnecessary to write to a local queue first to absolutely ensure success? Am I supposed to build X myself?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄与心 2025-01-01 16:32:33

正如 Hugh 指出的那样,您只需要一个 MSMQ 队列即可从源到目的地单向发送消息。源和目标可以位于同一服务器、同一网络或跨 Internet,但是源和目标都必须运行 MSMQ 服务。

如果您需要进行“消息”路由(例如,处理来自多个源或目标队列的消息的交换机,或者根据消息类型将消息路由到一个或多个订阅者等),您将需要的不仅仅是 MSMQ 队列。
虽然您当然可以使用 BizTalk 进行消息路由,但如果您不需要使用 BizTalk 的其他功能,这将是昂贵的/过度杀伤力。建议您查看开源软件,或者自己构建一些自定义的东西。

但是,通过“路由”,您可能指的是使用 HTTP 作为传输(例如通过互联网)时的队列重定向功能(例如 此处此处)。

回复:失败的传递和重试

我认为您已经掌握了大部分概念 - 一般来说,消息 DELIVERY 重试功能应该隐含在 MSMQ 中。如果 MSMQ 无法在定义的到期之前传递消息,那么它将在死信队列中返回,然后源可以处理来自 DLQ 的消息,然后对它们进行“补偿”(例如,反转“发送”的操作,向用户指示失败等)。

然而,目标中的“处理”类型重试需要由目标应用程序/侦听器执行(例如,如果目标系统出现故障、死锁等)

执行此操作的常见方法包括:

  • 使用 2 阶段提交 - 在分布式工作单元下,将消息从 MSMQ 中拉出并对其进行处理(例如,将数据插入数据库、更改某些记录的状态等),如果遇到任何失败,则将消息放回队列中并进行处理数据库更改将被回滚。
  • 应用程序级别重试 - 即在目标系统上,如果出现“可重试”类型错误(由于负载、死锁等而超时),则休眠几秒钟,然后重试同一事务。

然而,在大多数情况下,无限期的处理重试是不可取的,您最终需要承认失败并实现一种机制来记录消息和错误并将其从队列中删除。

但我不会“重试”业务失败(例如业务规则、验证等),并且行为应该在您如何处理这些的要求中定义(例如帐户透支、消息格式不正确或无效等) ),例如通过向源返回“NACK”类型消息。

华泰

As Hugh points out, you need only one MSMQ Queue to Send messages in one direction from a source to a destination. Source and destination can be on the same server, same network or across the internet, however, both source and destination must have the MSMQ service running.

If you need to do 'message' routing (e.g. a switch which processes messages from several source or destination queues, or routing a message to one or more subscribers based on the type of message etc) you would need more than just MSMQ queue.
Although you certainly can use BizTalk to do message routing, this would be expensive / overkill if you didn't need to use other features of BizTalk. Would recommend you look at open source, or building something custom yourself.

But by "Routing" you might be referring to the queue redirection capability when using HTTP as the transport e.g. over the internet (e.g. here and here).

Re : Failed delivery and retry

I think you have most of the concepts - generally the message DELIVERY retry functionality should be implicit in MSMQ. If MSMQ cannot deliver the message before the defined expiry, then it will be returned on the Dead Letter Queue, and the source can then process messages from the DLQ and then 'compensate' for them (e.g. reverse the actions of the 'send', indicate failure to the user, etc).

However 'processing' type Retries in the destination will need to be performed by the destination application / listener (e.g. if the destination system is down, deadlocks, etc)

Common ways to do this include:

  • Using 2 Phase commit - under a distributed unit of work, pull the message off MSMQ and process it (e.g. insert data into a database, change the status of some records etc), and if any failure is encountered, then leave the message back onto the queue and the DB changes will be rolled back.
  • Application level retries - i.e. on the destination system, in the event of 'retryable' type errors (timeout due to load, deadlocks etc) then to sleep for a few seconds and then retry the same transaction.

However, in most cases, indefinite processing retries are not desirable and you would ultimately need to admit defeat and implement a mechanism to log the message and the error and remove it from the queue.

But I wouldn't 'retry' business failures (e.g. Business Rules, Validation etc) and the behaviour should be defined in your requirements of how to handle these (e.g. account is overdrawn, message is not in a correct format or not valid, etc), e.g. by returning a "NACK" type message back to the source.

HTH

稳稳的幸福 2025-01-01 16:32:33

MSMQ 将消息从一个队列发送到另一个队列。

假设您在远程计算机上有一个队列。您想向该队列发送消息。

所以你创建了一个发件人。发送方是可以使用 MSMQ 传输来发送消息的应用程序。这可以是 .Net 队列客户端 (System.Messaging)、WCF 服务使用者(通过 netMsmqBinding 或 msmqIntegrationBinding、使用 MSMQ 适配器的 BizTalk 等)。

您发送消息时,实际发生的情况是:

  1. 当 发送方计算机将消息写入临时本地队列,
  2. 发送方计算机上的 MSMQ 队列管理器连接到接收方计算机上的 MSMQ 管理器并传输消息
  3. 。接收方计算机上的 MSMQ 队列管理器将消息放入目标队列。

在某些情况下,MSMQ 会遇到由于某种原因而无法在目标队列上接收的消息。在这些情况下,如果您已指示消息将使用死信队列,那么MSMQ将确保消息被转发到死信队列。

MSMQ sends messages from one queue to another queue.

Let's say you have a queue on a remote machine. You want to send a message to that queue.

So you create a sender. A sender is an application that can use the MSMQ transport to send a message. This can be a .Net queue client (System.Messaging), a WCF service consumer (either over netMsmqBinding or msmqIntegrationBinding, BizTalk using the MSMQ adapter, etc etc.

When you send the message, what actually happens is:

  1. The MSMQ queue manager on the sender machine writes the message to a temporary local queue.
  2. The MSMQ queue manager on the sender machine connects to the MSMQ manager on the receiving machine and transmits the message.
  3. The MSMQ queue manager on the receivers machine puts the message onto the destination queue.

In certain situations MSMQ will encounter messages which for some reason or another cannot be received on the destination queue. In these situations, if you have indicated that a message will use the dead-letter queue then MSMQ will make sure that the message is forwarded to the dead-letter queue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文