PHP code example of ingresse / message-queue-php
1. Go to this page and download the library: Download ingresse/message-queue-php 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/ */
ingresse / message-queue-php example snippets
$configData = [
'connection' => [
'host' => 'localhost',
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
'vhost' => '/'
],
'queues' => [
'worker.test' => [
'passive' => false,
'durable' => true,
'exclusive' => false,
'autoDelete' => false,
'delivery_mode' => 2
]
],
'exchanges' => [
'exchange.test' => [
'type' => 'fanout'
'passive' => false,
'durable' => true,
'auto_delete' => false,
'internal' => false,
'nowait' => false,
'arguments' => false,
'ticket' => false,
'delivery_mode' => 2
]
],
'consume' => [
'Simpler' => [
'noLocal' => false,
'noAck' => false,
'exclusive' => false,
'noWait' => false
]
],
'logger' => [
'host' => 'localhost',
'port' => 6379,
'key' => 'logstash',
'channel' => 'message-queue-php'
path' => '/var/log/message-queue-php.log'
]
];
$config = new MessageQueuePHP\Config\AMQPConfig($configData);
$amqpAdapter = new MessageQueuePHP\Adapter\AMQPAdapter($config);
$myPublisher = new MessageQueuePHP\Publisher\Publisher($amqpAdapter, 'worker.test');
$myPublisher
->setMessage($myData)
->send();
$subscriber = new MessageQueuePHP\Subscriber\Subscriber($amqpAdapter);
$simplerConsumer = new MessageQueuePHP\Subscriber\Consumer\SimplerConsumer;
$subscriber
->setConsumer($simplerConsumer)
->subscribe('worker.test')
->consume();