【原创】RabbitMQ 之 Dynamic Shovel(翻译)

Configuring Dynamic Shovels 

Information about dynamic shovels is stored in the RabbitMQ database, along with users, permissions, queues, etc. Every shovel is defined by a corresponding named parameter. 
dynamic shovel 的配置信息会被保存到 Mnesia 中,信息中会包含 user, permission, queue 等内容; 
每一个 shovel 都由一个相应的命名 parameter 定义; 

Parameters can be defined using rabbitmqctl, through the management HTTP API, or (with the rabbitmq_shovel_management plugin installed) through the management plugin's web UI. 
可以通过 rabbitmqctl 脚本,或者通过管理插件的 HTTP API,或者通过管理插件的 Web UI(需要使能 rabbitmq_shovel_management 插件)进行 parameter 内容的定义; 

A simple example 
简单示例 

Here we will consume messages from the queue my-queue on the local broker, and push them out to the queue another-queue on a remote broker. 
下面展示的是从本地 broker 中名为 my-queue 的 queue 上消费消息后,再转发到远端 broker 上的名为 another-queue 的 queue 的用法。 

rabbitmqctl rabbitmqctl set_parameter shovel my-shovel \
'{"src-uri": "amqp://", "src-queue": "my-queue", \
"dest-uri": "amqp://remote-server", "dest-queue": "another-queue"}'
rabbitmqctl (Windows) rabbitmqctl set_parameter shovel my-shovel ^
"{""src-uri"":""amqp://"", ""src-queue"": ""my-queue"", ^
""dest-uri"": ""amqp://remote-server"", ""dest-queue"": ""another-queue""}"
HTTP API PUT /api/parameters/shovel/%2f/my-shovel
{"value":{"src-uri":  "amqp://",              "src-queue":  "my-queue",
          "dest-uri": "amqp://remote-server", "dest-queue": "another-queue"}}
Web UI Navigate to Admin > Shovel Management > Add a new shovel. Enter "my-shovel" next to Name, "amqp://" and "my-queue" next to Source, and "amqp://remote-server" and "another-queue" next Destination Expiry. Click Add shovel.

Configuration reference 
配置参考 

Source

src-uri
The AMQP URI(s) for the source. Mandatory. See the AMQP URI reference for information on how RabbitMQ treats AMQP URIs in general, and the query parameter reference for the Erlang client's extensions (including those for SSL and SASL) which are available to the shovel. 
用于指定 source 的 AMQP URI 值,强制要求; 
需要针对特殊 URI 查看手册; 
需要针对 Erlang 客户端扩展查看手册;

Note that this field can either be a string, or a list of strings. If more than one string is provided, the shovel will randomly pick one URI from the list. This can be used to connect to a cluster and ensure the link will eventually find another node in the event that one fails. It's probably not a great idea to use multiple URIs that do not point to the same cluster.
该参数的值可以为 string 或者 string 列表; 
如果指定的是 string 的列表,则 shovel 将会随机选取一个 URI 使用;该方式用于集群场景,解决某一个节点失效后自动找寻其他节点的情况; 
使用不指向同一个 cluster 节点的多个 URI 可能会导致问题; 

src-queue 
The queue from which to consume. Either this or src-exchange (but not both) must be set. 
If the source queue does not exist on the source broker, it will be declared as a durable queue with no arguments. 
用于指定消费行为所需的 queue ;src-queue 或 src-exchange 必须设置一个(但不要求都设置); 
如果在 source broker 上目标 queue 不存在,则基于该参数会创建一个没有 argument 的、具有 durable 属性的 queue ; 

src-exchange 
The exchange from which to consume. Either this or src-queue (but not both) must be set. 
The shovel will declare an exclusive queue and bind it to the named exchange with src-exchange-key before consuming from the queue. 
If the source exchange does not exist on the source broker, it will be not declared; the shovel will fail to start. 
用于指定消费行为所需的 exchange ;src-queue 或 src-exchange 必须设置一个(但不要求都设置); 
shovel 会在从消息消费行为开始前,先声明一个具有 exclusive 属性的 queue ,并使用 src-exchange-key 将其绑定到由该参数指定名字的 exchange 上; 
如果 source exchange 在 source broker 上并不存在,则不会自动进行声明,此时 shovel 在启动时失败; 

src-exchange-key 
Routing key when using src-exchange 
当使用 src-exchange 时所需的路由 key 值; 

Destination 

dest-uri 
The AMQP URI(s) for the destination. Mandatory. See src-uri above. 
用于指定 destination 的 AMQP URI 值,强制要求; 

dest-queue 
The queue to which messages should be published. Either this or dest-exchange (but not both) may be set. If neither is set then messages are republished with their original exchange and routing key. 
If the destination queue does not exist on the source broker, it will be declared as a durable queue with no arguments. 
消息要被发送到的目标 queue ;dest-queue 或 dest-exchange 可以设置一个(但不要求都设置);若两个参数都没设置,则消息会基于其原始 exchange 和 routing key 重新投递; 
如果在 source broker 上由 dest-queue 指定的 queue 不存在,则基于该参数会创建一个没有 argument 的、具有 durable 属性的 queue ; 

dest-exchange 
The exchange to which messages should be published. Either this or dest-queue (but not both) may be set. 
If the destination exchange does not exist on the source broker, it will be not declared; the shovel will fail to start. 
消息要被发送到的目标 exchange ;dest-queue 或 dest-exchange 可以设置一个(但不要求都设置); 
如果在 source broker 上由 dest-exchange 指定的 exchange 不存在,则不会进行创建,此时 shovel 将会启动失败; 

dest-exchange-key 
Routing key when using dest-exchange. If this is not set, the original message's routing key will be used. 
当使用 dest-exchange 时的路由 key ; 
如果没有设置该参数,将会使用原始消息中的 routing key 值; 

Shovel 

prefetch-count 
The maximum number of unacknowledged messages copied over a shovel at any one time. Default is 1000. 
在任意一次操作中,经由 shovel 拷贝出的、尚未进行确认的最大消息数量;默认为 1000 条; 

reconnect-delay 
The duration (in seconds) to wait before reconnecting to the brokers after being disconnected at either end. Default is 1. 
被任意一端断开后,重连 broker 前的等待时间(以秒为单位);默认为 1 秒; 

publish-properties 
Properties to overwrite when shovelling messages. Setting headers this way is not currently supported. Default is {}. 
用于改写被 shovel 的消息的属性的设置;针对 header 的设置目前尚不支持;默认为 {} ; 

add-forward-headers 
Whether to add x-shovelled headers to the shovelled messages indicating where they have been shovelled from and to. Default is false. 
是否添加 x-shovelled 头到被 shovel 的消息中,以表明该消息被从哪里 shovel 到了哪里;默认为 false ; 

ack-mode 
Determines how the shovel should acknowledge messages. If set to on-confirm (the default), messages are acknowledged to the source broker after they have been confirmed by the destination. This handles network errors and broker failures without losing messages, and is the slowest option. 
决定 shovel 如何针对消息进行确认; 
如果设置了 on-confirm (默认值),那么只有当消息被 destination broker 确认后,才会向 source broker 进行确认; 
通过该设置可以解决网络错误或者 broker 失效导致的消息丢失问题;该方式下的消息处理速度当然最慢; 

If set to on-publish, messages are acknowledged to the source broker after they have been published at the destination. This handles network errors without losing messages, but may lose messages in the event of broker failures. 
如果设置了 on-publish ,那么当消息被发送到了 destination broker 后,就会向 source broker 进行确认; 
该方式能够处理由于网络错误导致的消息丢失,但遇到 broker 失效的情况则有可能会丢失消息; 

If set to no-ack, message acknowledgements are not used. This is the fastest option, but may lose messages in the event of network or broker failures. 
如果设置了 no-ack ,则不使用任何消息确认机制;这种设置在消息处理速度上最快,但是在发生网络错误或者 broker 失效问题是,丢消息的可能性大大增加; 

delete-after
Determines when (if ever) the shovel should delete itself. This can be useful if the shovel is being treated as more of a move operation - i.e. being used to move messages from one queue to another on an ad hoc basis. 
该参数用于确定(若设置了的话)何时 shovel 应该删除自身; 
该功能在将 shovel 作为用于搬运的操作时非常有用,即用于在 ad-hoc 场景下将消息从一个 queue 中搬移到另一个 queue 中; 

The default is never, meaning the shovel should never delete itself. 
该参数默认值为 never ,意味着 shovel 永远不要删除自身; 

If set to queue-length then the shovel will measure the length of the source queue when starting up, and delete itself after it has transfered that many messages. 
如果设置了 queue-length 参数,则 shovel 会在启动的时候检测 source queue 的长度,并在将这些消息全数转发后删除自身; 

If set to an integer, then the shovel will transfer that number of messages before deleting itself. 
如果设置为整数值,则 shovel 会在删除自身前转发该值数目的消息; 

时间: 2024-08-02 07:52:20

【原创】RabbitMQ 之 Dynamic Shovel(翻译)的相关文章

【原创】RabbitMQ 之 Plugins(翻译)

      为了方便工作中使用,对 RabbitMQ 的[插件]相关文档进行了翻译,鉴于自己水平有限,翻译中难免有纰漏产生,如果疑问,欢迎指出探讨.此文以中英对照方式呈现.官方原文:http://www.rabbitmq.com/plugins.html ========== 我是分割线 =============  Plugins RabbitMQ supports a variety of plugins. This page documents the plugins that ship

【原创】RabbitMQ 之 Configure(翻译)

configure  ========= 我是分割线 =========  Configuration配置方式  RabbitMQ comes with default built-in settings which will most likely be sufficient for running your RabbitMQ server effectively. If it runs fine, then you probably don't need any configuration

【原创】rabbitmq-plugins用户手册(翻译)

      为了方便工作中使用,周末抽空对 rabbitmq-plugins 用户手册进行了翻译,鉴于自己水平有限,翻译中难免有纰漏产生,如果疑问,欢迎指出探讨. 官方原文:http://www.rabbitmq.com/man/rabbitmq-plugins.1.man.html ======== 我是分割线 ========== 通过 http://www.rabbitmq.com/manpages.html  可知 RabbitMQ 有5个 General Command : 1. ra

【原创】rabbitmq-service用户手册(翻译)

      为了方便工作中使用,周末抽空对 rabbitmq-service 用户手册进行了翻译,鉴于自己水平有限,翻译中难免有纰漏产生,如果疑问,欢迎指出探讨. 官方原文:http://www.rabbitmq.com/man/rabbitmq-service.man.html ================ 我是分割线 ================== 通过 http://www.rabbitmq.com/manpages.html 可知 RabbitMQ 有5个 General Co

【原创】rabbitmq-echopid用户手册(翻译)

      为了方便工作中使用,周末抽空对 rabbitmq-echopid 用户手册进行了翻译,鉴于自己水平有限,翻译中难免有纰漏产生,如果疑问,欢迎指出探讨. 官方原文:http://www.rabbitmq.com/man/rabbitmq-echopid.man.html ================= 我是分割线 ================== 通过 http://www.rabbitmq.com/manpages.html 可知 RabbitMQ 有5个 General C

【原创】rabbitmq-server用户手册(翻译)

      为了方便工作中使用,周末抽空对rabbitmq-server用户手册进行了翻译,鉴于自己水平有限,翻译中难免有纰漏产生,如果疑问,欢迎指出探讨. 官方原文:http://www.rabbitmq.com/man/rabbitmq-server.1.man.html ================= 我是分割线 ================== 通过 http://www.rabbitmq.com/manpages.html 可知 RabbitMQ 有5个 General Com

【原创】RabbitMQ 的 shovel 插件使用

      从之前的两篇文章< [原创]RabbitMQ 之 Shovel(翻译) >和< [原创]RabbitMQ 之 Dynamic Shovel(翻译) >中,我们已经知道 shovel 插件的使用存在 static 和 dynamic 两种形式,其主要差异如下  Static Shovels Dynamic Shovels 基于 broker 的配置文件进行定义 基于 broker 的 parameter 参数进行定义 Require a restart of the ho

【原创】RabbitMQ 之 Shovel(翻译)

      为了方便工作中使用,对 RabbitMQ 的[Shovel]文档进行了翻译,鉴于自己水平有限,翻译中难免有纰漏产生,如果疑问,欢迎指出探讨.此文以中英对照方式呈现.      官方原文:http://www.rabbitmq.com/shovel.html ==============================  Shovel pluginShovel 插件 The Shovel plugin allows you to configure a number of shovel

【原创】RabbitMQ 之 Distributed brokers(翻译)

Distributed RabbitMQ brokers  AMQP and the other messaging protocols supported by RabbitMQ via plug-ins (e.g. STOMP), are (of course) inherently distributed - it is quite common for applications from multiple machines to connect to a single broker, e