PHP code example of pandasir / rabbitmq
1. Go to this page and download the library: Download pandasir/rabbitmq 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/ */
pandasir / rabbitmq example snippets
$config = [
'default' => [
'host' => '132.75.114.99',
'port' => 5672,
'login' => 'admin',
'password' => 'abc',
'vhost' => 'admin'
]
];
e){
var_dump($e->getMessage());die;
}
try{
$mq = new \pandaSir\Mq\Connection\AMQPConnection($config);
$channel = $mq->channel();
$queue = $channel->queue('test_queue')
}catch (\Exception $e){
var_dump($e->getMessage());die;
}
try{
$mq = new \pandaSir\Mq\Connection\AMQPConnection($config);
$channel = $mq->channel();
$result = $channel->basicPublish('name is jack', 'jia.task', 'test', [
'delivery_mode' => 2
]);
}catch (\Exception $e){
var_dump($e->getMessage());die;
}
try{
$mq = new \pandaSir\Mq\Connection\AMQPConnection($config);
$channel = $mq->channel();
$callback = function (AMQPEnvelope $msg, AMQPQueue $queue) {
var_dump($msg->getBody());
$queue->ack($msg->getDeliveryTag());
};
$channel->basicConsume('test', $callback, true);
}catch (\Exception $e){
var_dump($e->getMessage());die;
}