PHP code example of williamespindola / rabbitmq-service-provider
1. Go to this page and download the library: Download williamespindola/rabbitmq-service-provider library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
williamespindola / rabbitmq-service-provider example snippets
$app->post('/message', function(Request $request) use ($app){
$producer = $app['rabbit.producer']['my_exchange_name'];
$producer->publish('Some message');
return new Response($msg_body);
});
use Silex\Application;
use fiunchinho\Silex\Provider\RabbitServiceProvider;
$app = new Application();
$app->register(new RabbitServiceProvider());
$app->register(new RabbitServiceProvider(), [
'rabbit.connections' => [
'default' => [
'host' => 'localhost',
'port' => 5672,
'user' => 'guest',
'password' => 'guest',
'vhost' => '/',
'lazy' => false,
'connection_timeout' => 3,
'read_write_timeout' => 6,
'keepalive' => false,
'heartbeat' => 3
],
'another' => [
'host' => 'another_host',
'port' => 5672,
'user' => 'guest',
'password' => 'guest',
'vhost' => '/'
'lazy' => false,
'connection_timeout' => 3,
'read_write_timeout' => 6,
'keepalive' => false,
'heartbeat' => 3
]
],
'rabbit.producers' => [
'first_producer' => [
'connection' => 'another',
'exchange_options' => ['name' => 'a_exchange', 'type' => 'topic']
],
'second_producer' => [
'connection' => 'default',
'exchange_options' => ['name' => 'a_exchange', 'type' => 'topic']
],
],
'rabbit.consumers' => [
'a_consumer' => [
'connection' => 'default',
'exchange_options' => ['name' => 'a_exchange','type' => 'topic'],
'queue_options' => ['name' => 'a_queue', 'routing_keys' => ['foo.#']],
'callback' => 'your_consumer_service',
'graceful_max_execution' => [
'timeout' => 900,
'exit_code' => 10,
],
]
]
]);
#!/usr/bin/env php
se fiunchinho\Silex\Provider\RabbitServiceProvider;
use fiunchinho\Silex\Command\Consumer;
use Ivoba\Silex\Provider\ConsoleServiceProvider;
$app = new Application();
me' => 'my_exchange_name','type' => 'topic'],
'queue_options' => ['name' => 'a_queue', 'routing_keys' => ['foo.#']],
'callback' => 'my_service'
]
]
));
$app->register(new ConsoleServiceProvider(), array(
'console.name' => 'MyApplication',
'console.version' => '1.0.0',
'console.project_directory' => __DIR__
));
$application = $app['console'];
$application->add(new Consumer());
$application->run();