PHP code example of foolkaka / tail

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

    

foolkaka / tail example snippets


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

//...

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

//...

return array(

    'default' => 'default_connection',

    'connections' => array(

        'default_connection' => array(
            'host'         => 'localhost',
            'port'         => 5672,
            'username'     => 'guest',
            'password'     => 'guest',
            'vhost'        => '/',
            'exchange'     => 'default_exchange_name',
            'consumer_tag' => 'consumer',
            'exchange_type'=> 'direct',
            'content_type' => 'text/plain',
            'ssl_connect'  => false,
            'ssl_options'  => [
                'cafile' => '/opt/certs/ca.cert.pem',
                'local_cert' => '/opt/certs/local_cert.pem',
                'verify_peer' => true,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            ]
        ),    
        'other_server' => array(
            'host'         => '192.168.0.10',
            'port'         => 5672,
            'username'     => 'guest',
            'password'     => 'guest',
            'vhost'        => '/',
            'exchange'     => 'default_exchange_name',
            'consumer_tag' => 'consumer',
            'exchange_type'=> 'fanout',
            'content_type' => 'application/json',
            'ssl_connect'  => false,
            'ssl_options'  => [
                'cafile' => '/opt/certs/ca.cert.pem',
                'local_cert' => '/opt/certs/local_cert.pem',
                'verify_peer' => true,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            ]
        ),
    ),
);

    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		
});