hgtan/rabbitmq-bundle

你好 RabbitMq Bundle

dev-master / 1.0.1.x-dev 2015-07-23 08:38 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:42:52 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Build Status Coverage Status Quality Score HHVM Status

SensioLabsInsight

通过使用php-amqplib库和以下bundle在您的应用程序中通过RabbitMQ进行消息传递

安装

步骤 1: 使用Composer

composer.json

    php composer.phar require hgtan/rabbitmq-bundle:dev-master

步骤 2: 注册bundle

然后使用您的kernel注册bundle

    <?php

    // in AppKernel::registerBundles()
    $bundles = array(
        // ...
        new Hgtan\Bundle\HelloRabbitMqBundle\HgtanHelloRabbitMqBundle(),
        // ...
    );

步骤 3: 配置bundle

    # app/config/config.yml
    old_sound_rabbit_mq:
        connections:
            default:
                host:     'localhost'
                port:     5672
                user:     'guest'
                password: 'guest'
                vhost:    '/'
                lazy:     false
                #connection_timeout: 3
                #read_write_timeout: 3

                # requires php-amqplib v2.4.1+ and PHP5.4+
                #keepalive: false

                # requires php-amqplib v2.4.1+
                #heartbeat: 0
        producers:
            hello_world:
                connection:       default
                exchange_options: {name: 'hello', type: direct}
                class:            Hgtan\Bundle\HelloRabbitMqBundle\Cakper\HelloProducer
        consumers:
            hello_world:
                connection:       default
                exchange_options: {name: 'hello', type: direct}
                queue_options:    {name: 'hello'}
                callback:         hello_world_service

导入HelloRabbitMqBundle路由文件

    # app/config/routing.yml
    hgtan_hello_rabbit_mq:
        resource: "@HgtanHelloRabbitMqBundle/Controller/"
        type:     annotation
        prefix:   /

步骤 4: 示例

    #RabbitMQ Management
    https://:15672/#/

    $ php app/console server:run

    $ php app/console rabbitmq:consumer hello_world

    # Limit number of messages
    $ php app/console rabbitmq:consumer hello_world -m 10

    http://127.0.0.1:8000/hello/rabbitmq