PHP code example of teclaelvis / rabbitmq-phalcon-adapter

1. Go to this page and download the library: Download teclaelvis/rabbitmq-phalcon-adapter 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/ */

    

teclaelvis / rabbitmq-phalcon-adapter example snippets


use Pmqelvis\QueueManagerFactory;
use Pmqelvis\RabbitMQAdapter;

= new RabbitMQAdapter('localhost', 5672, 'guest', 'guest');
$queueFactory = new QueueManagerFactory($adapter);


$adapter = new RabbitMQAdapter('localhost', 5672, 'guest', 'guest', true);
 
// continue with the configuration
...

$di->set('queue', function () use ($config) {
    $ssl = getenv('APPLICATION_ENV') != 'development';
    $adapter = new RabbitMQAdapter(
        $config->rabbitmq->host,
        $config->rabbitmq->port,
        $config->rabbitmq->user,
        $config->rabbitmq->password,
        $ssl
    );
    return new QueueManagerFactory($adapter);
});


$queueFactory = $this->di->get('queue');

...



use Pmqelvis\QueueManagerFactory;
use Pmqelvis\RabbitMQAdapter;

$queueFactory = new QueueManagerFactory($adapter);
 */
...
...

$queue = $queueFactory->build('test', 'producer', 'test-exchange');
// or
$queue = $queueFactory->buildProducer('test' ,'test-exchange');
$queue->publish('Hello World from my library');
    

use Pmqelvis\QueueManagerFactory;
use Pmqelvis\RabbitMQAdapter;

 $queueFactory = new QueueManagerFactory($adapter);
 */
...
...


$queue = $queueFactory->build('test','consumer' ,'test-exchange');
// or
$queue = $queueFactory->buildConsumer('test' ,'test-exchange');

$queue->consume(function ($message) {
    echo $message->body;
    $message->ack();
});