PHPackages                             kastilyo/rabbit-hole - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. kastilyo/rabbit-hole

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

kastilyo/rabbit-hole
====================

RabbitHole RabbitMQ library

v0.0.2(8y ago)09MITPHPPHP &gt;=5.6.0

Since Oct 18Pushed 8y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

rabbit-hole
===========

[](#rabbit-hole)

[![Code Climate](https://camo.githubusercontent.com/6e3b213b13d608986ce2c1df726991bb5239c1e47a26713d96cca5681b19c5f4/68747470733a2f2f636f6465636c696d6174652e636f6d2f7265706f732f3536316130346361363935363830323132373030383362642f6261646765732f31343436336663313563643638666566623730362f6770612e737667)](https://codeclimate.com/repos/561a04ca69568021270083bd/feed)

[![Test Coverage](https://camo.githubusercontent.com/4953da1933ee72b85191208e056436be6761074aee278d710101b5ef96bbfa9e/68747470733a2f2f636f6465636c696d6174652e636f6d2f7265706f732f3536316130346361363935363830323132373030383362642f6261646765732f31343436336663313563643638666566623730362f636f7665726167652e737667)](https://codeclimate.com/repos/561a04ca69568021270083bd/coverage)

This is a RabbitMQ library heavily inspired by [Hutch](https://github.com/gocardless/hutch). So far, I've only come up with basic subscribing mechanisms. I would like to expand on this by providing support for batch processing. I'm planning to add publishing mechanisms and then support for RPC patterns. And finally, I would like to add running mechanisms ie. managing and running multiple subscribers of varying configurations simultaneously which will likely be the most difficult and at which point it would be considered highly experimental and perhaps an abuse and misuse of PHP as it's not typically intended for such things.

RabbitHole provides mechanisms for consuming messages from RabbitMQ exchanges without the low-level boilerplate. The tradeoff for that is that this library operates under several assumptions as to how RabbitMQ is being used:

- Exchanges created by RabbitHole subscribers are durable topic exchanges.
- Similarly, queues created by RabbitHole subscribers will be durable.

Thus, RabbitHole is intended for users who want to minimize data loss.

Usage
-----

[](#usage)

A subscriber class made with RabbitHole must implement the SubscriberInterface and use the SubscriberTrait. It must set a property of `$amqp_connection` to an AMQPConnection instance. Lastly, it must acknowledge messages processed by its `processMessage` implemenation.

Consider the following example Subscriber implementation taken directly from the test source.

```
namespace Kastilyo\RabbitHole\Spec;

use AMQPConnection;
use AMQPEnvelope;
use Kastilyo\RabbitHole\Subscriber\SubscriberTrait;
use Kastilyo\RabbitHole\Subscriber\SubscriberInterface;

/**
 * This is a test SubscriberInterface implementation that mixes in SubscriberTrait.
 * It represents the intended use of this library.
 */
class Subscriber implements SubscriberInterface
{
    use SubscriberTrait;

    public function __construct(AMQPConnection $amqp_connection)
    {
        $this->setAMQPConnection($amqp_connection);
    }

    public function getExchangeName()
    {
        return 'test_exchange';
    }

    public function getQueueName()
    {
        return 'test_queue';
    }

    public function getBindingKeys()
    {
        return ['test.info'];
    }

    public function processMessage(AMQPEnvelope $amqp_envelope)
    {
        echo $amqp_envelope->getBody(), PHP_EOL;
        $this->acknowledgeMessage($amqp_envelope);
    }
}
```

This class happens to get an `AMQPConnection` instance through constructor injection sets its `$amqp_connection` property with the `setAMQPConnection` method provided by the `SubscriberTrait`.

This class implements `SubscriberInterface` which includes several static getter methods.

`getExchangeName` should return the name of the durable topic exchange to declare. The name of the exchange this class will declare is 'test\_exchange'.

`getQueueName` should return the name of the durable queue to declare. The name this class will read from is 'test\_queue'.

`getBindingKeys` should return an array of routing keys which may contain the '\*' or '#' wildcards. This class only binds 'test.info' to the queue.

Also part of the `SubscriberInterface` is the `processMessage` instance method which is the callback for messages in the queue. This implementation simply prints the message body with a newline and then acknowledges the message.

To actually consume messages, the `consume` method provided by the `SubscriberTrait` must be called on the `Subscriber` instance. It will declare the exchange and queue, and begin consuming messages according to the above.

```
$amqp_connection = new AMQPConnection([
    'host' => 'localhost',
    'port' => 5672,
    'login' => 'guest',
    'password' => 'guest',
]);
$subscriber = new Kastilyo\RabbitHole\Spec\Subscriber($amqp_connection);
$subscriber->consume();
```

If you have docker and would like to test this out, you can clone this repo and install all dependencies, including dev ones, with `composer install`.

Run `docker run -d -p 15672:15672 -p 5672:5672 rabbitmq:3-management` which will run a RabbitMQ docker container with the management installed with the default credentials of 'guest'/'guest', forwarding ports 15672 and 5672, in the background. The management web interface should be accessible from localhost:15672 and any services running on the host machine should be able to interface with the container through localhost:5672.

Begin a terminal session and then run `php dev/consumer.php` from the root of the project directory which will wait for messages to come in from the queue.

From the rabbitmq management plugin web interface, there should both be a 'test\_exchange' exchange and 'test\_queue' queue which has the routing key, 'test.info', bound to it.

From the exchange panel, select 'test\_exchange' and publish a message with a routing key of 'test.info' and some identifiable content.

The terminal session running `php dev/consumer.php` should have produced the output of the content set in the published message. Graphs in the management interface should also indicate that a message was published, consumed and acknowledged.

In the future, I'll add a Dockerfile to the dev directory to deploy the repo itself to run in a container.

Dependencies
------------

[](#dependencies)

PHP &gt;= 5.6.0

This library was built using the [calcinai/php-amqplib-bridge](https://github.com/calcinai/php-amqplib-bridge) package for the possibility of compatibility with both the [videlalvaro/php-amqplib](https://github.com/videlalvaro/php-amqplib) package and the PECL AMQP extension. However, I've never run any of the code with the PECL extension myself and can't confirm that it works but theorertically, it should.

Style and Naming Conventions
----------------------------

[](#style-and-naming-conventions)

For the coding style, I tried to follow PSR coding style guidelines. When it came to naming conventions, I suffixed any traits with 'Trait' and interfaces with 'Interface'. Any other file in the 'src' directory should be a class. I also used underscored names for variables and properties if only to easily visually distinguish them from methods. There are no functions but if there were, I'd underscore them as well.

Testing
-------

[](#testing)

I used the awesome [kahlan](https://github.com/crysalead/kahlan) testing framework.

```
$ ./vendor/bin/kahlan
```

Credits
-------

[](#credits)

- [markalexandercastillo](https://github.com/markalexandercastillo)
- [burntbrowniez](https://github.com/burntbrowniez)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

22

—

LowBetter than 24% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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 ~541 days

Total

2

Last Release

3269d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/33ed14a4284d16bf6bbdcef45e8099d4025aa671e7e9636d56f9110f43f92dbf?d=identicon)[kastilyo](/maintainers/kastilyo)

---

Top Contributors

[![markalexandercastillo](https://avatars.githubusercontent.com/u/1994663?v=4)](https://github.com/markalexandercastillo "markalexandercastillo (38 commits)")

### Embed Badge

![Health badge](/badges/kastilyo-rabbit-hole/health.svg)

```
[![Health](https://phpackages.com/badges/kastilyo-rabbit-hole/health.svg)](https://phpackages.com/packages/kastilyo-rabbit-hole)
```

###  Alternatives

[symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k775.6M1.6k](/packages/symfony-routing)[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k72.4M299](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k302.1M1.1k](/packages/php-http-discovery)[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k62.5M221](/packages/nelmio-api-doc-bundle)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k47.0M210](/packages/api-platform-core)[spatie/crawler

Crawl all internal links found on a website

2.8k15.7M46](/packages/spatie-crawler)

PHPackages © 2026

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