https://www.rabbitmq.com/parameters.html
A RabbitMQ node can be configured using a number of mechanisms responsible for different areas:
Mechanism | Description |
Configuration File(s) | defines server and plugin settings for and so on. |
Environment Variables | define node name, file and directory locations, runtime flags taken from the shell, or set in the environment configuration file, rabbitmq-env.conf (Linux, MacOS, BSD) and rabbitmq-env-conf.bat (Windows) |
rabbitmqctl | When internal authentication/authorization backend is used, rabbitmqctl is the tool that manages virtual hosts, users and permissions. |
rabbitmq-plugins | rabbitmq-plugins is the tool that manages enabled plugins. |
Parameters and Policies | defines cluster-wide settings which can change at run time as well as settings that are convenient to configure for groups of queues (exchanges, etc) such as including optional queue arguments. |
Runtime (Erlang VM) Flags | Control lower-level aspects of the system: memory allocation settings, inter-node communication buffer size, runtime scheduler settings and more. |
Operating System Kernel Limits | Control process limits enforced by the kernel: max open file handle limit, max number of processes and kernel threads, max resident set size and so on. |
大部分配置都可以通过
- 配置文件 rabbitmq.conf
- 环境变量文件 rabbitmq-env.conf
- 补充配置文件 advanced.config
这三个配置文件搞定了,
但是也有例外情况:
1 如果一个集群中的多个节点需要配置同样的内容
2 如果需要在运行时候修改 配置。
这个时候就需要通过 parameters 来搞定了。
parameters 可以 用rabbitmqctl 命令设置,也可以在web 页面设置
?2中参数,一种是 全局的,一种是 基于vhost 的
基于vhost 的包含三个属性 component name, a name and a value.
全局的就只有2个属性 a name and a value.
policies 是参数的一种特殊使用场景,用来设置 一组 exchange 和 queue 还有 Federation和 shovel 插件。基于vhost 的。
以下是操作命令
基于vhost
rabbitmqctl | rabbitmqctl set_parameter {-p vhost} component_name name value rabbitmqctl clear_parameter {-p vhost} component_name name rabbitmqctl list_parameters {-p vhost} |
---|---|
HTTP API | PUT /api/parameters/component_name/vhost/name DELETE /api/parameters/component_name/vhost/name GET /api/parameters |
全局的
rabbitmqctl | rabbitmqctl set_global_parameter name value rabbitmqctl clear_global_parameter name rabbitmqctl list_global_parameters |
---|---|
HTTP API | PUT /api/global-parameters/name DELETE /api/global-parameters/name GET /api/global-parameters |
为什么需要 policies?
在声明exchange or queue 的时候 ,除了强制要求的参数 durable exclusive autodelete 以外,客户端可能会添加好多其他的属性,
但是 在程序运行的时候,如果想要修改 某个属性 就需要修改代码,然后重新发布,这有点麻烦了,怎么办呢 ,policys 来解决
policy 怎么生效?
policy 属性介绍
- name: it can be anything but ASCII-based names without spaces are recommended
- pattern: a regular expression that matches one or more queue (exchange) names. Any regular expression can be used.
- definition: a set of key/value pairs (think a JSON document) that will be injected into the map of optional arguments of the matching queues and exchanges
- priority: see below
policy 去匹配满足条件的exchange和queue ,然后帮他们决定行为,一个队列或exchange 只会有一个 可用的policy,一个policy 内部可以 写入多条限制 (json格式)
apply-to 参数决定 policy 用在queue, exchange 还是both
策略生效时间 添加完毕生效,然后queue or exchang 重新创建的时候 也会生效。
示例:
An example of defining a policy looks like:
rabbitmqctl | |
---|---|
rabbitmqctl (Windows) | |
HTTP API | |
Web UI |
|
This matches the value "all" with the key "federation-upstream-set" for all exchanges with names beginning with "amq.", in the virtual host "/".
The "pattern" argument is a regular expression used to match exchange or queue names.
In the event that more than one policy can match a given exchange or queue, the policy with the greatest priority applies.
The "apply-to" argument can be "exchanges", "queues" or "all". The "apply-to" and "priority" settings are optional, in which case the defaults are "all" and "0" respectively.
组合策略
In some cases we might want to apply more than one policy definition to a resource. For example we might need a queue to be federated and mirrored. At most one policy will apply to a resource at any given time, but we can apply multiple definitions in that policy.
A federation policy definition would require an upstream set to be specified, so we would need the federation-upstream-set key in our definition. On the other hand to define some queues as mirrored, we would need the ha-mode key to be defined as well for the policy. Since the policy definition is just a JSON object, we can have both keys in the same policy definition.
Here's an example:
rabbitmqctl | |
---|---|
rabbitmqctl (Windows) | |
HTTP API | |
Web UI |
|
By doing that all the queues matched by the pattern "^hf\." will have the "federation-upstream-set" and the "ha-mode" definitions applied to them.
以上讲述的是常规policy,还有一种policy 叫做 operator policy,他只能定义四个参数
- expires
- message-ttl
- max-length
- max-length-bytes
他和 常规policy 的关系是 互相补充+ 合并的 关系。
如果常规policy 和 operator policy 都设置了同一个 参数 ,那就以比较小的值为准。
rabbitmqctl | |
---|---|
rabbitmqctl (Windows) | |
HTTP API | |
Web UI |
|