PHP code example of mookofe / tail

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

    

mookofe / tail example snippets


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

//...

$app->configure('tail-settings');
$app->register(Mookofe\Tail\LumenServiceProvider::class);

//...

return array(

    'default' => 'default_connection',

    'connections' => array(

        'default_connection' => array(
            'host'                => 'localhost',
            'port'                => 5672,
            'username'            => 'guest',
            'password'            => 'guest',
            'vhost'               => '/',
            'ssl_context_options' => null,
            'connection_timeout'  => 3,
            'read_write_timeout'  => 50,   //should be at least 2x heartbeat (if using heartbeat)
            'keepalive'           => true, //l_context_options' => array(
                'capath'      => '/etc/ssl/certs',
                'cafile'      => './startssl_ca.pem',
                'verify_peer' => true,
            ),
            'connection_timeout'  => 3.0,
            'read_write_timeout'  => 3.0,
            'keepalive'           => false,
            'heartbeat'           => 0,
            'exchange'            => 'default_exchange_name',
            'consumer_tag'        => 'consumer',
            'exchange_type'       => 'fanout',
            'content_type'        => 'application/json'
        ),
    ),
);

    Tail::add('queue-name', 'message');
	
    Tail::add('queue-name', 'message', array('connection_name' => 'connection_name_config_file'));

    Tail::add('queue-name', 'message', array('exchange' => 'exchange_name'));

    Tail::add('queue-name', '{ 'message' : 'message' }', array('content_type' => 'application/json'));

	$options = array (
		'connection_name' => 'connection_name_config_file',
		'exchange' => 'exchange_name',
		'vhost' => 'vhost'
	);	
	
    Tail::add('queue-name', 'message', $options);

	$message = new Tail::createMessage;
	$message->queue_name = 'queue-name';
	$message->message = 'message';
	$message->connection_name = 'connection_name_in_config_file';
	$message->exchange = 'exchange_name';
	$message->vhost = 'vhost';
	$message->content_type = 'content/type'

	$message->save();

Tail::listen('queue-name', function ($message) {
    		
	//Your message logic code
});

$options = array(
	'message_limit' => 50,
	'time' => 60,
	'empty_queue_timeout' => 5,
	'connection_name' => 'connection_name_in_config_file',
    'exchange' => 'exchange_name',
    'vhost' => 'vhost'
);

Tail::listenWithOptions('queue-name', $options, function ($message) {
    		
	//Your message logic code		
});