2017 © Pedro Peláez
 

library silex-rabbitmq-provider

Rabbitmq message provider bundle for Silex2

image

exs/silex-rabbitmq-provider

Rabbitmq message provider bundle for Silex2

  • Thursday, July 23, 2015
  • by rumpranger
  • Repository
  • 8 Watchers
  • 2 Stars
  • 503 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

EXS-silex-rabbitmq-provider

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

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

The installation process is actually very simple. Set up a Silex project with Composer., (*2)

Once the new project is set up, open the composer.json file and add the exs/silex-rabbitmq-provider as a dependency: ``` js //composer.json //... "require": { //other bundles "exs/silex-rabbitmq-provider": "@dev", (*3)

Or you could just add it via the command line:

$ composer.phar require exs/silex-rabbitmq-provider ~1.0@dev, (*4)


Save the file and have composer update the project via the command line: ``` shell php composer.phar update

Composer will now update all dependencies and you should see our bundle in the list: ``` shell - Installing exs/silex-rabbitmq-provider (dev-master 463eb20) Cloning 463eb2081e7205e7556f6f65224c6ba9631e070a, (*5)


Update the app.php to include the EXS-silex-rabbitmq-provider provider: ``` php //app.php //... $app->register(new \EXS\RabbitmqProvider\Providers\Services\RabbitmqProvider());

Update your rabbitmq connection and environment in your config.php:, (*6)

//...
// 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, (*7)

//...
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, (*8)

//...
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., (*9)

Notice

This provider does not support multiple exchanges or queues., (*10)

Contributing

Anyone and everyone is welcome to contribute., (*11)

If you have any questions or suggestions please [let us know][1]., (*12)

The Versions

23/07 2015

dev-master

9999999-dev https://github.com/ExSituMarketing/EXS-silex-rabbitmq-provider

Rabbitmq message provider bundle for Silex2

  Sources   Download

MIT

The Requires

 

by slee

rabbitmq silex message provider