PHP code example of tzmudz / rabbitmq_rpc

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

    

tzmudz / rabbitmq_rpc example snippets


$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();

$producer = new Tzm\Rpc\Producer('long_task_queue_name');

$producer = new Tzm\Rpc\Producer();
$producer->setQueueName('long_task_queue_name');

$producer = new Tzm\Rpc\Producer();
$producer->setQueueName('long_task_queue_name')->call($message);

$producet = new Tzm\Rpc\Producer();
$producer->withoutWaiting()->call($message);

public function handleMessage($message)
{
    echo $message;
}

public function handleError(\Exception $e)
{
    Log::error($e->getMessage());
}

public function handleMessage($message)
{
    $this->setResult('this_will_be_returned_to_Producer');
}

namespace Tzm\Rpc;

class EchoMessage extends Consumer
{
    protected function handleMessage($message)
    {
        echo $message;
    }

    protected function handleError(\Exception $e)
    {
        \Log::error($e->getMessage()); // In Laravel Log exception message
    }
}

$consumer = new EchoMessage();
$consumer->run();

[04.11 11:03:49] [NEW] New request
[04.11 11:03:49] [OK] New request