PHPackages                             sunspikes/carrot - 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. sunspikes/carrot

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

sunspikes/carrot
================

A simple abstraction for RabbitMQ

v0.3.1(9y ago)5102[1 issues](https://github.com/sunspikes/carrot/issues)MITPHP

Since Aug 3Pushed 9y agoCompare

[ Source](https://github.com/sunspikes/carrot)[ Packagist](https://packagist.org/packages/sunspikes/carrot)[ RSS](/packages/sunspikes-carrot/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (4)Versions (5)Used By (0)

Carrot
======

[](#carrot)

[![SensioLabsInsight](https://camo.githubusercontent.com/055c9c6aa63f4ea1e31f463244776c4f821b654d57f95886615cf736725618f5/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f38613565363237342d616633302d343630362d386135612d3262353134646461636538652f6d696e692e706e67)](https://insight.sensiolabs.com/projects/8a5e6274-af30-4606-8a5a-2b514ddace8e)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a37b2332ebb66f40681efac152b011a0b7127d783f0b7dd10bf5f812b914cb23/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73756e7370696b65732f636172726f742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sunspikes/carrot/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/cb0e52dbea969d0a76988b1d472f5044a7ba60f8418e84873040b7a4ece46032/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73756e7370696b65732f636172726f742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sunspikes/carrot/?branch=master)[![Code Climate](https://camo.githubusercontent.com/9de1dc0100dd48ea64560eeccfffe288337a0bae489093c0bc7097817834ec40/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73756e7370696b65732f636172726f742f6261646765732f6770612e737667)](https://codeclimate.com/github/sunspikes/carrot)[![Build Status](https://camo.githubusercontent.com/b80e8f5c31f36bb111ee9a5ed91222c1d0675dd6df6aae16fb0bc5a4f26d3695/68747470733a2f2f7472617669732d63692e6f72672f73756e7370696b65732f636172726f742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sunspikes/carrot)[![Latest Stable Version](https://camo.githubusercontent.com/5d188efed8cae89a122b5fc490cdffd33e0185091860ac10fcd38561c58a2e72/68747470733a2f2f706f7365722e707567782e6f72672f73756e7370696b65732f636172726f742f762f737461626c65)](https://packagist.org/packages/sunspikes/carrot)[![License](https://camo.githubusercontent.com/ec6a84efac67acf4ff5d41bca853c2726db247969a14538850f77867a062f85e/68747470733a2f2f706f7365722e707567782e6f72672f73756e7370696b65732f636172726f742f6c6963656e7365)](https://packagist.org/packages/sunspikes/carrot)

A simple abstraction for RabbitMQ.

Carrot aims to make it easy to get started with RabbitMQ and PHP, at the same time maintaining the flexibility to implement all the supported messaging patterns.

Requirements
------------

[](#requirements)

You must have a rabbitmq server running to use this package. For more on this refer [RabbitMQ documentation](https://www.rabbitmq.com/download.html).

Installation
------------

[](#installation)

With Composer

```
$ composer require sunspikes/carrot

```

Usage
-----

[](#usage)

To configure a RabbitMQ connection

```
Carrot::config([
    'host' => '127.0.0.1',
    'port' => 5672,
    'username' => 'guest',
    'password' => 'guest',
    'vhost' => '/'
]);

```

To publish message to RabbitMQ,

```
// Create producer which sends messages to 'test-exchange'
$producer = Carrot::producer('test-exchange');

// Send a message to 'TestQueue'
$producer->send('TestQueue', [
    'text' => 'hello',
]);

```

To Consume messages from RabbitMQ

```
// Create a consumer which reads from 'test-exchange'
$consumer = Carrot::consumer('test-exchange');

// Add a listener for for queue 'TestQueue', the callback will be executed
// everytime there is a new message on this queue, which will print 'hello'
$consumer->add('TestQueue', function($message) {
    print $message->text;
});

// Listen for messages on 'test-exchange', this is a wait loop which will keep the
// consumer running till it's manually terminated or the connection is lost
$consumer->listen('test-exchange');

```

More on usage
-------------

[](#more-on-usage)

You don't have to use static methods to build and use producers and consumers, also the library makes it easy to switch between different exchange types.

For example, you can also create a direct exchange &amp; produce messages to it like,

```
$config = [
    'host' => '127.0.0.1',
    'port' => 5672,
    'username' => 'guest',
    'password' => 'guest',
    'vhost' => '/'
];

$carrot = new Carrot('test-exchange', 'direct', $config);
$producer = $carrot->getProducer();

$producer->send('TestQueue', [
    'text' => 'hello'
]);

```

Also the consumer can be created and listened to a direct exchange for messages like,

```
$carrot = new Carrot('test-exchange', 'direct', $config);
$consumer = $carrot->getConsumer();

$consumer->add('TestQueue', function($message) {
    print $message->text;
});

$consumer->listen('test-exchange');

```

By default carrot producer will automatically serialize the message and consumer will deserialize the message acknowledge the incoming messages, you could disable this delegation by setting the configuration parameter `delegate` to `false`

```
// make some message
$message = ['text' => 'hello'];

// serialize it manually
$message = json_encode($message);

// send the message
$producer->send('TestQueue', $message);

// At consumer end, handle the message manually
$consumer->add('TestQueue', function (AMQPMessage $message) use ($consumer) {
    $decoded = json_decode($message->body);

    //... do something with $decoded->text

    // if everything went fine acknowledge message
    $consumer->acknowledgeMessage($message);

    // if something went wrong with the message reject message, this will discard the message (optionally requeue the message)
    $consumer->rejectMessage($message, $requeue = false);
});

```

Example
-------

[](#example)

You can run the examples from the /example folder

First run the consumer, it will create the exchange and queue on the rabbitmq server

```
$ php example/consumer.php

[*] Consumer starting to listen for messages from rabbitmq...
[*] Received message: hello

```

As soon as you run the producer, the consumer will print the message text sent by the producer

```
$ php example/producer.php

[*] Producer started...
[*] Producer sent message to rabbitmq

```

Testing
-------

[](#testing)

Run `phpunit`

Author
------

[](#author)

Krishnaprasad MG \[@sunspikes\]

Contributing
------------

[](#contributing)

Please feel free to send pull requests.

License
-------

[](#license)

This is an open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

4

Last Release

3614d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/75611?v=4)[Krishnaprasad MG](/maintainers/sunspikes)[@sunspikes](https://github.com/sunspikes)

---

Top Contributors

[![sunspikes](https://avatars.githubusercontent.com/u/75611?v=4)](https://github.com/sunspikes "sunspikes (14 commits)")

---

Tags

clientphprabbitmq

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sunspikes-carrot/health.svg)

```
[![Health](https://phpackages.com/badges/sunspikes-carrot/health.svg)](https://phpackages.com/packages/sunspikes-carrot)
```

###  Alternatives

[vladimir-yuldashev/laravel-queue-rabbitmq

RabbitMQ driver for Laravel Queue. Supports Laravel Horizon.

2.1k10.3M32](/packages/vladimir-yuldashev-laravel-queue-rabbitmq)[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2792.4M7](/packages/bschmitt-laravel-amqp)[jwage/phpamqplib-messenger

Symfony messenger transport for the php-amqplib/php-amqplib library.

87201.9k1](/packages/jwage-phpamqplib-messenger)[hyperf/amqp

A amqplib for hyperf.

231.2M66](/packages/hyperf-amqp)[convenia/pigeon

3334.2k](/packages/convenia-pigeon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
