PHP code example of filld / larabbit

1. Go to this page and download the library: Download filld/larabbit 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/ */

    

filld / larabbit example snippets


return [

    'use' => 'production',

    'properties' => [

        'production' => [
            'host'                => env('RABBITMQ_HOST', 'localhost'),
            'port'                => env('RABBITMQ_PORT', 5672),
            'username'            => env('RABBITMQ_USERNAME'),
            'password'            => env('RABBITMQ_PASSWORD'),
            'vhost'               => env('RABBITMQ_VHOST'),
            'exchanges'           => [
                                         [
                                             'exchange'              => 'exchange_name',
                                             'exchange_type'         => 'topic',
                                             'exchange_passive'      => false,
                                             'exchange_durable'      => true,
                                             'exchange_auto_delete'  => false,
                                             'exchange_internal'     => false,
                                             'exchange_nowait'       => false,
                                             'exchange_properties'   => [],
                         
                                             'routing' => [
                                                 'routing.key.one',
                                                 'routing.key.two',
                                         ]
                                     ],
            'consumer_tag'        => 'consumer',
            'ssl_options'         => [], // See https://secure.php.net/manual/en/context.ssl.php
            'connect_options'     => [], // See https://github.com/php-amqplib/php-amqplib/blob/master/PhpAmqpLib/Connection/AMQPSSLConnection.php
            'queue_properties'    => ['x-ha-policy' => ['S', 'all']],
            'timeout'             => 0
        ],

    ],

];

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
*/

//...

$app->configure('amqp');
$app->register(Filld\Amqp\LumenServiceProvider::class);

//...

$app->withFacades();

'Filld\Amqp\AmqpServiceProvider',

'Amqp' => 'Filld\Amqp\Facades\Amqp',

'connect_options'     => [
    'capath' => '/etc/ssl/certs',
    'cafile' => env('RABBITMQ_SSL_CERT', storage_path() . '/certs/cacert.pem'),
    'verify_peer' => true
],

    Amqp::publish('routing-key', 'message');
	
    Amqp::publish('routing-key', 'message' , ['queue' => 'queue-name']);
	
    Amqp::publish('routing-key', 'message' , ['exchange' => 'amq.direct']);

    Amqp::publish('routing-key', 'message', [
        'queue_properties' => [
            "x-ha-policy" => ["S", "all"],
            'x-message-ttl' => ['I', 86400000],
            'x-dead-letter-exchange' => ['S', 'orders_dead_letter'],
        ],
        'queue' => 'orders'
    ]);

Amqp::consume('queue-name', function ($message, $resolver) {
    		
   var_dump($message->body);

   $resolver->acknowledge($message);

   $resolver->stopWhenProcessed();
        
});

Amqp::consume('queue-name', function ($message, $resolver) {
    		
   var_dump($message->body);

   $resolver->acknowledge($message);
        
});

Amqp::consume('queue-name', function ($message, $resolver) {
    		
   var_dump($message->body);

   $resolver->acknowledge($message);
      
}, [
	'timeout' => 2,
	'vhost'   => 'vhost3'
]);

\Amqp::publish('', 'message' , [
    'exchange_type' => 'fanout',
    'exchange' => 'amq.fanout',
]);

\Amqp::consume('', function ($message, $resolver) {
    var_dump($message->body);
    $resolver->acknowledge($message);
}, [
    'exchange' => 'amq.fanout',
    'exchange_type' => 'fanout',
    'queue_force_declare' => true,
    'queue_exclusive' => true,
    'persistent' => true// 
js
"filld/larabbit": "2.*"
batch
$ php composer update

$ php composer