dev-master
9999999-dev https://github.com/ExSituMarketing/EXS-silex-rabbitmq-providerRabbitmq message provider bundle for Silex2
MIT
The Requires
by slee
rabbitmq silex message provider
Wallogit.com
2017 © Pedro Peláez
Rabbitmq message provider bundle for Silex2
Super simple provider for reading (consume) / writing (post) to rabbitmq from silex 2.x application., (*1)
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'
);
//...
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)
This provider does not support multiple exchanges or queues., (*10)
Anyone and everyone is welcome to contribute., (*11)
If you have any questions or suggestions please [let us know][1]., (*12)
Rabbitmq message provider bundle for Silex2
MIT
rabbitmq silex message provider