olaurendeau/rabbit-mq-admin-toolkit-bundle

自动化 rabbitmq vhost 的配置创建/更新

v2.2.0 2021-12-07 19:00 UTC

README

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight

License Latest Stable Version Total Downloads Monthly Downloads

自动化 rabbitmq vhost 的配置创建/更新

安装

composer require olaurendeau/rabbit-mq-admin-toolkit-bundle

将 RabbitMqAdminToolkitBundle 添加到您的包中

    // config/bundles.php
<?php

return [
    ...
    Ola\RabbitMqAdminToolkitBundle\OlaRabbitMqAdminToolkitBundle::class => ['all' => true]
    ...
];

更新您的配置

# config/packages/ola_rabbit_mq_admin_toolkit.yaml
ola_rabbit_mq_admin_toolkit:
    delete_allowed: true # Allow deletion of exchange, queues and binding for updating configuration. Shouldn't be enabled in production
    connections:
        default: http://user:password@localhost:15672
    vhosts:
        default:
            name: /my_vhost
            permissions:
                user: ~
            exchanges:
                exchange.a: ~
            queues:
                queue.a:
                    bindings:
                        - { exchange: exchange.a, routing_key: "a.#" }
                        - { exchange: exchange.a, routing_key: "b.#" }

用法

只需运行 app/console rabbitmq:vhost:define

配置示例

有关完整配置选项,请参阅 app/console config:dump-reference OlaRabbitMqAdminToolkitBundle

# config/packages/ola_rabbit_mq_admin_toolkit.yaml
ola_rabbit_mq_admin_toolkit:
    delete_allowed: true # Allow deletion of exchange, queues and binding for updating configuration. Shouldn't be enabled in production
    default_vhost: test # default is "default"
    silent_failure: true # Catch all exceptions in commands. Could be use in test environment if no rabbitmq available
    connections:
        default: http://user:password@localhost:15672
        vm: http://user:password@192.168.1.1:15672
    vhosts:
        test:
            name: /test
            connection: vm # default is "default"
            permissions:
                user: ~
            exchanges:
                exchange.a:
                    durable: false # default is "true"
                exchange.b:
                    type: direct # default is "topic"
                exchange.c: ~
            queues:
                queue.a:
                    durable: false # default is "true"
                    arguments: # define arguments 
                        x-message-ttl: 5000
                    bindings:
                        - { exchange: exchange.a, routing_key: "a.#" }
                        - { exchange: exchange.b, routing_key: "b.#" }
                queue.b:
                    bindings:
                        - { exchange: exchange.a, routing_key: "a.#" }
                        - { exchange: exchange.b, routing_key: "b.#" }
                        - { exchange: exchange.c, routing_key: "c.#" }
                queue.c:
                    bindings:
                        - { exchange: exchange.a, routing_key: "a.#" }
                        - { exchange: exchange.c, routing_key: "c.#" }

分片队列

分片队列可以用于处理大量消息。

# config/packages/ola_rabbit_mq_admin_toolkit.yaml
ola_rabbit_mq_admin_toolkit:
    delete_allowed: true # Allow deletion of exchange, queues and binding for updating configuration. Shouldn't be enabled in production
    connections:
        default: http://user:password@localhost:15672
    vhosts:
        default:
            name: /my_vhost
            permissions:
                user: ~
            exchanges:
                exchange.a: ~
            queues:
                queue.a.sharded:
                    name: "queue.a.{modulus}"
                    modulus: 5
                    bindings:
                        - { exchange: exchange.a, routing_key: "a.{modulus}.#" }
                        - { exchange: exchange.a, routing_key: "b.#" }

这将生成以下配置

capture d ecran 2016-02-10 a 09 56 19

capture d ecran 2016-02-10 a 09 56 33