1. Go to this page and download the library: Download huaji-team/rabbitmq-client 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/ */
huaji-team / rabbitmq-client example snippets
use PhpRabbitMQClient\Config;
use PhpRabbitMQClient\Client;
use PhpRabbitMQClient\Message\ProducerMessage;
$conf = new Config([
'host' => '*****',
'port' => 5672,
'user' => 'admin',
'password' => '123456',
'vhost' => '/',
]);
$client = new Client($conf);
$msg = new ProducerMessage(
[
'a' => 1,
'b' => 2
],
'liu-exchange',
'liu-routeking'
);
$client->produce($msg);
$msg->getExchangeBuilder()
use PhpRabbitMQClient\Config;
use PhpRabbitMQClient\Client;
use PhpRabbitMQClient\Message\ConsumerMessage;
use PhpAmqpLib\Message\AMQPMessage;
$conf = new Config([
'host' => '*****',
'port' => 5672,
'user' => 'admin',
'password' => '123456',
'vhost' => '/',
]);
$client = new Client($conf);
class Consumer extends ConsumerMessage
{
public function __construct(string $exchange, $routingKey, string $queue)
{
parent::__construct($exchange, $routingKey, $queue);
}
public function consumeMessage($data, \PhpAmqpLib\Message\AMQPMessage $message): bool
{
print_r($data);
return true;
}
}
$consumer = new Consumer('liu-exchange', 'liu-routeking', 'liu-queue');
//$consumer->setNoACK(true);
//$consumer->isRequeue(false);
$client->consume($consumer);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.