1. Go to this page and download the library: Download puzzle/amqp 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/ */
puzzle / amqp example snippets
uzzle\Configuration\Memory;
use Puzzle\AMQP\Clients\Pecl;
use Puzzle\AMQP\Messages\Message;
$configuration = new Memory(array(
'amqp/broker/host' => 'myRabbit',
'amqp/broker/login' => 'guest',
'amqp/broker/password' => 'guest',
'amqp/broker/vhost' => '/',
'app/id' => 'myApp',
));
$client = new Pecl($configuration);
$message = new Message('my.routing.key');
$message->setJson([
'key' => 'value',
'key2' => 'value2',
]);
$client->publish('myExchange', $message);
use Puzzle\AMQP\Consumers;
use Puzzle\AMQP\Clients;
use Puzzle\AMQP\Workers\ProcessorInterfaceAdapter;
use Puzzle\Configuration\Memory;
$configuration = new Memory(array(
'amqp/broker/host' => 'rabbitmq',
'amqp/broker/login' => 'guest',
'amqp/broker/password' => 'guest',
'amqp/broker/vhost' => '/',
'app/id' => 'myApp',
));
$consumer = new Consumers\Simple();
$worker = new ExampleWorker();
$consumer->consume(
new ProcessorInterfaceAdapter($worker),
new Clients\Pecl($configuration),
'queue.name'
);
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use Puzzle\AMQP\ReadableMessage;
use Puzzle\AMQP\Workers\Worker;
class ExampleWorker implements Worker
{
use LoggerAwareTrait;
public function __construct()
{
$this->logger = new NullLogger();
}
public function process(ReadableMessage $message): void
{
// your code here
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.