PHP code example of blackwoodseven / php-lib-amqp-service

1. Go to this page and download the library: Download blackwoodseven/php-lib-amqp-service 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/ */

    

blackwoodseven / php-lib-amqp-service example snippets



$app->register(new \BlackwoodSeven\AmqpService\ServiceProvider(), [
    'amqp.options' => [
        'product' => 'my_app_id',
        'dsn' => 'amqp://user:pass@host:port/vhost',
        'exchanges' => [
            'my_exchange_0',
            'my_exchange_1' => [
                'type' => 'topic',
            ],
        ],
        'queues' => [
            'my_queue_1' => [
                'arguments' => [],
                'bindings' => [
                    'my_exchange_1' => [
                        'my_routingkey_1',
                        'my_routingkey_2',
                    ],
                ],
            ],
        ],
    ],
]);

$default_queue = $app['amqp.queue'];

$default_queue->listenOnce(function (\PhpAmqpLib\Message\AMQPMessage $msg) {
    // do stuff...
});

$app['amqp.queues']['another_queue']->listenOnce(function (\PhpAmqpLib\Message\AMQPMessage $msg) {
    // do stuff...
});



$default_exchange = $app['amqp.exchange'];

$default_exchange->publish(
    new \PhpAmqpLib\Message\AMQPMessage('Hello world'),
    'my.routing.key'
);

$app['amqp.exchanges']['another_exchange']->publish(
    new \PhpAmqpLib\Message\AMQPMessage('Hello world'),
    'my.routing.key'
);

composer