exs/silex-rabbitmq-provider 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

exs/silex-rabbitmq-provider

Composer 安装命令:

composer require exs/silex-rabbitmq-provider

包简介

Rabbitmq message provider bundle for Silex2

README 文档

README

Super simple provider for reading (consume) / writing (post) to rabbitmq from silex 2.x application.

Installing the EXS-silex-rabbitmq-provider in a Silex project

The installation process is actually very simple. Set up a Silex project with Composer.

Once the new project is set up, open the composer.json file and add the exs/silex-rabbitmq-provider as a dependency:

//composer.json
//...
"require": {
        //other bundles
        "exs/silex-rabbitmq-provider": "@dev"

Or you could just add it via the command line:

$ composer.phar require exs/silex-rabbitmq-provider ~1.0@dev

Save the file and have composer update the project via the command line:

php composer.phar update

Composer will now update all dependencies and you should see our bundle in the list:

  - Installing exs/silex-rabbitmq-provider (dev-master 463eb20)
    Cloning 463eb2081e7205e7556f6f65224c6ba9631e070a

Update the app.php to include the EXS-silex-rabbitmq-provider provider:

//app.php
//...
$app->register(new \EXS\RabbitmqProvider\Providers\Services\RabbitmqProvider());

Update your rabbitmq connection and environment in your config.php:

//...
// Rabbit MQ connection
$app['rabbit.connections'] = array(
    'default' => array(
        'host' => 'localhost',
        'port' => 5672,
        'user' => 'REPLACE_YOUR_USER_NAME',
        'password' => 'REPLACE_YOUR_PASSWORD',
        'vhost' => 'REPLACE_YOUR_VHOST_NAME'
    )
);

// rabbitmq provider environment
$app['exs.rabbitmq.env'] = array(        
    'exchange' => 'REPLACE_EXCHANGE_NAME',
    'type' => 'REPLACE_EXCHANGE_TYPE',
    'queue' => 'REPLACE_QUEUE_NAME',
    'key' => 'REPLACE_ROUTING_KEY_NAME' 
 );
//...

USAGE

Publish messages to the new exchange queue

//...
use EXS\RabbitmqProvider\Services\PostmanService;

$postman = new PostmanService();

//Publish messages to the new exchange queue
$postman->publish($YOUR_MESSAGE_HERE, false);

//Publish messages to the existing exchange queue by other rabbitmq bundle
$postman->publish($YOUR_MESSAGE_HERE);
or 
$postman->publish($YOUR_MESSAGE_HERE, true);
// setting isDeclared parameter to true will declare the new exchange queue if it doesn't exist.
//...

Consume messages from the queue

//...
use EXS\RabbitmqProvider\Services\ConsumerService;

$consumer = new ConsumerService();

// Get all messages from the queue
$messages = $this->consumerService->consumeAll();
// Get 1000 messages from the queue
$messages = $this->consumerService->consumeWithLimit(1000);

// Get all messages from the existing exchange queue by other rabbitmq bundle
$messages = $this->consumerService->consumeAll(false);
or
// Get 1000 messages from the new echange queue
$messages = $this->consumerService->consumeWithLimit(1000, false);
// setting isDeclared parameter to true will declare the new exchange queue if it doesn't exist
//...

And now you can publish and consume messages with rabbitmq.

Notice

This provider does not support multiple exchanges or queues.

Contributing

Anyone and everyone is welcome to contribute.

If you have any questions or suggestions please let us know.

统计信息

  • 总下载量: 1.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 11
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-20