PHPackages                             dosomething/messagebroker-phplib - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. dosomething/messagebroker-phplib

AbandonedArchivedLibrary[Queues &amp; Workers](/categories/queues)

dosomething/messagebroker-phplib
================================

A library of functionality shared between the components that make up the DoSomething.org Message Broker system.

0.3.8(9y ago)41.9k↓100%[3 issues](https://github.com/DoSomething/messagebroker-phplib/issues)[1 PRs](https://github.com/DoSomething/messagebroker-phplib/pulls)MITPHPPHP &gt;= 5.3.0

Since Feb 10Pushed 9y ago9 watchersCompare

[ Source](https://github.com/DoSomething/messagebroker-phplib)[ Packagist](https://packagist.org/packages/dosomething/messagebroker-phplib)[ Docs](https://github.com/DoSomething/messagebroker-phplib)[ RSS](/packages/dosomething-messagebroker-phplib/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (32)Used By (0)

messagebroker-phplib
====================

[](#messagebroker-phplib)

A PHP baed library that ascts as a wrapper around the `php-amqplib/php-amqplib` AMQP PHP library. The goal is to provide utility methods to simplify some of the more common activities of interacting with a AMQP based (RabbitMQ) server.

### Usage

[](#usage)

Within the `composer.json` file of any PHP based application include this package with:

```
  "require": {
    "php": ">= 5.3.0",
    "DoSomething/messagebroker-phplib": "0.3.*",
    ...

```

### Create an instance of the class

[](#create-an-instance-of-the-class)

```
// 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));

```

\###Publish a message

```
$this->messageBroker->publish($message, );

```

\###Consume a message

How a message will be consumed is defined in the connection to the queue.

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

```

The number of messages for the consumer to reserve with each callback. This is Necessary for parallel processing when more than one consumer is running on the same queue.

```
define('QOS_SIZE', 1);

$mb->consumeMessage([new consumer class(),
