• <tfoot id='l6cby'></tfoot>
    <i id='l6cby'><tr id='l6cby'><dt id='l6cby'><q id='l6cby'><span id='l6cby'><b id='l6cby'><form id='l6cby'><ins id='l6cby'></ins><ul id='l6cby'></ul><sub id='l6cby'></sub></form><legend id='l6cby'></legend><bdo id='l6cby'><pre id='l6cby'><center id='l6cby'></center></pre></bdo></b><th id='l6cby'></th></span></q></dt></tr></i><div id='l6cby'><tfoot id='l6cby'></tfoot><dl id='l6cby'><fieldset id='l6cby'></fieldset></dl></div>

    <small id='l6cby'></small><noframes id='l6cby'>

      • <bdo id='l6cby'></bdo><ul id='l6cby'></ul>

      1. <legend id='l6cby'><style id='l6cby'><dir id='l6cby'><q id='l6cby'></q></dir></style></legend>

        在 RabbitMQ 中混合发布/订阅与工作队列

        时间:2023-08-24

          <i id='PY6Pj'><tr id='PY6Pj'><dt id='PY6Pj'><q id='PY6Pj'><span id='PY6Pj'><b id='PY6Pj'><form id='PY6Pj'><ins id='PY6Pj'></ins><ul id='PY6Pj'></ul><sub id='PY6Pj'></sub></form><legend id='PY6Pj'></legend><bdo id='PY6Pj'><pre id='PY6Pj'><center id='PY6Pj'></center></pre></bdo></b><th id='PY6Pj'></th></span></q></dt></tr></i><div id='PY6Pj'><tfoot id='PY6Pj'></tfoot><dl id='PY6Pj'><fieldset id='PY6Pj'></fieldset></dl></div>
          • <small id='PY6Pj'></small><noframes id='PY6Pj'>

              <tbody id='PY6Pj'></tbody>

            1. <legend id='PY6Pj'><style id='PY6Pj'><dir id='PY6Pj'><q id='PY6Pj'></q></dir></style></legend>
                  <bdo id='PY6Pj'></bdo><ul id='PY6Pj'></ul>
                • <tfoot id='PY6Pj'></tfoot>
                  本文介绍了在 RabbitMQ 中混合发布/订阅与工作队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在评估使用 RabbitMQ 作为消息队列/消息总线,并一直在查看示例 教程 在 RabbitMQ 页面上.

                  I am evaluating using RabbitMQ as message queue/message bus and have been looking at the example tutorials on the RabbitMQ page.

                  我正在寻找教程未涵盖的特定场景,我不确定是否以及如何通过 RabbitMQ 进行操作.

                  I am looking for a specific scenario not covered by the tutorials and I am not sure if and how it would be possible to do via RabbitMQ.

                  设置:

                  • 假设我有一项服务,我们称其为采购订单",而我必须提供其他服务,称为物流"和会计".

                  • Let's assume I got a service, let's call it "purchase orders" and I have to other services called "logistics" and "accounting".

                  发送订单时,我想通过 RabbitMQ 将其​​作为消息发送.

                  When an order is sent, I want to send it as a message via RabbitMQ.

                  有 2 个账户"和 3 个物流"服务

                  There 2 "account" and 3 "logistic" services

                  确保帐户"和物流"只处理一次消息的正确方法是什么?如果我理解正确,使用 pub/sub 将导致消息被处理两次(帐户)或三次(物流).

                  What would be the correct way to ensure that "account" and "logistic" will process the message only once? Using pub/sub will cause the messages to be processed twice (account) or trice (logistics) if i understand it correctly.

                  使用工作队列和 prefetch=1 可以确保只有一个可以得到它,但是我有 2 项服务,并且希望每种类型的服务都能得到一个.

                  With work queues and prefetch=1 it would assure that only one gets it, but I have 2 services and want each type of service to get one.

                  有没有一种方法可以将两者结合起来并为每个服务设置一个工作队列,而无需将 2 个单独的事件/消息发送到两个不同的交换器?

                  Is there a way to combine both and have a work queues for each of the service, without sending 2 separate events/messages to two different exchanges?

                  推荐答案

                  如果我理解正确,使用 pub/sub 将导致消息被处理两次(帐户)或三次(物流).

                  Using pub/sub will cause the messages to be processed twice (account) or trice (logistics) if i understand it correctly.

                  根据您的描述,每个工作人员可能有 1 个队列,并且您正在将消息路由到所有工作人员队列.因此,每个工作人员都会获得消息的副本,因为您将消息路由到所有队列.

                  you probably have 1 queue per worker, based on your description, and you are routing the message to all worker queues. therefore, each worker gets a copy of the message, because you routed the message to all of the queues.

                  您想要的是一个帐户"队列和一个后勤"队列.您将从单个帐户队列中读取多个帐户服务;物流服务/队列也一样.

                  what you want is a single "account" queue and a single "logistic" queue. you will have multiple account services reading from the single account queue; same for the logistic service / queue.

                  设置 prefetch=1 也很重要.这可以防止您一次向单个工作人员读取太多消息.

                  setting prefetch=1 is important as well. this prevents you from reading too many messages in to a single worker, at once.

                  有没有一种方法可以将两者结合起来并为每个服务设置一个工作队列,而无需将 2 个单独的事件/消息发送到两个不同的交换器?

                  Is there a way to combine both and have a work queues for each of the service, without sending 2 separate events/messages to two different exchanges?

                  是的 - 不要使用扇出交换.使用主题或直接交换,并使用多个路由键将单个消息路由到帐户和物流队列.

                  yes - don't use a fanout exchange. use a topic or direct exchange, and use multiple routing keys to route a single message to both the account and logistics queues.

                  确保帐户"和物流"只处理一次消息的正确方法是什么?

                  What would be the correct way to ensure that "account" and "logistic" will process the message only once?

                  没有办法保证这一点,100%.在某些时候,即使像我描述的那样进行了正确的设置,您也会遇到网络故障或工作人员崩溃或其他一些问题,并且一条消息将被处理两次.你必须在你的设计中考虑到这一点,在你的消息处理中使用某种形式的 idempotence.

                  there is no way to guarantee this, 100%. at some point, even with a proper setup like I've described, you will have a network failure or a worker crash or some other problem and a message will get processed twice. you have to account for this in you design, using some form of idempotence in your message processing.

                  希望有帮助!

                  这篇关于在 RabbitMQ 中混合发布/订阅与工作队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:rabbitmq 的 REST API 下一篇:RabbitMQ 和 C#

                  相关文章

                  最新文章

                • <small id='mDMmA'></small><noframes id='mDMmA'>

                  <i id='mDMmA'><tr id='mDMmA'><dt id='mDMmA'><q id='mDMmA'><span id='mDMmA'><b id='mDMmA'><form id='mDMmA'><ins id='mDMmA'></ins><ul id='mDMmA'></ul><sub id='mDMmA'></sub></form><legend id='mDMmA'></legend><bdo id='mDMmA'><pre id='mDMmA'><center id='mDMmA'></center></pre></bdo></b><th id='mDMmA'></th></span></q></dt></tr></i><div id='mDMmA'><tfoot id='mDMmA'></tfoot><dl id='mDMmA'><fieldset id='mDMmA'></fieldset></dl></div>

                  1. <legend id='mDMmA'><style id='mDMmA'><dir id='mDMmA'><q id='mDMmA'></q></dir></style></legend>

                    1. <tfoot id='mDMmA'></tfoot>

                        <bdo id='mDMmA'></bdo><ul id='mDMmA'></ul>