PHP code example of dosomething / messagebroker-phplib

1. Go to this page and download the library: Download dosomething/messagebroker-phplib 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/ */

    

dosomething / messagebroker-phplib example snippets


// RabbitMQ
$rabbitCredentials = [
    'host' =>  getenv("RABBITMQ_HOST"),
    'port' => getenv("RABBITMQ_PORT"),
    'username' => getenv("RABBITMQ_USERNAME"),
    'password' => getenv("RABBITMQ_PASSWORD"),
    'vhost' => getenv("RABBITMQ_VHOST"),
];

$config['exchange'] = array(
  'name' => $exchangeSettings->name,
  'type' => $exchangeSettings->type,
  'passive' => $exchangeSettings->passive,
  'durable' => $exchangeSettings->durable,
  'auto_delete' => $exchangeSettings->auto_delete,
);
    
$config['queue'] = array(
  'name' => $queueSetting->name,
  'passive' => $queueSetting->passive,
  'durable' =>  $queueSetting->durable,
  'exclusive' =>  $queueSetting->exclusive,
  'auto_delete' =>  $queueSetting->auto_delete,
  'routingKey' =>  $queueSetting->routing_key,
  'bindingKey' => $bindingKey,
);

$mb = new MessageBroker($rabbitCredentials, $config));

$this->messageBroker->publish($message, <routing key>);

$config['consume'] = array(
  'no_local' => $queueSetting->consume->no_local,
  'no_ack' => $queueSetting->consume->no_ack,
  'nowait' => $queueSetting->consume->nowait,
  'exclusive' => $queueSetting->consume->exclusive,
);

 public function <consumer method>($payload) {