PHPackages                             ahmedessam/lararabbit - 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. ahmedessam/lararabbit

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

ahmedessam/lararabbit
=====================

A powerful and elegant RabbitMQ integration for Laravel applications, providing a simple and efficient way to manage message queues and event-driven architectures.

v1.0.0(1y ago)010MITPHPPHP ^8.2

Since May 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/aahmedessam30/lararabbit)[ Packagist](https://packagist.org/packages/ahmedessam/lararabbit)[ RSS](/packages/ahmedessam-lararabbit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

LaraRabbit: Elegant RabbitMQ integration for Laravel
====================================================

[](#lararabbit-elegant-rabbitmq-integration-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2647e564d14773a201ce0459fe44f0191d6335d912c2d42dd0256cf8eacf7363/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61686d6564657373616d2f6c6172617261626269742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahmedessam/lararabbit)[![Total Downloads](https://camo.githubusercontent.com/067711d9eeae4a1c9b36930a247021a4b325b46a1a0d24ac3a76cc82be23c4f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61686d6564657373616d2f6c6172617261626269742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahmedessam/lararabbit)[![License](https://camo.githubusercontent.com/fd9c4d3e73f362111feabceca75362e4093790ae5e99c4ac9fd6526c138bf60e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61686d6564657373616d2f6c6172617261626269742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahmedessam/lararabbit)

LaraRabbit is a comprehensive, production-ready RabbitMQ integration package for Laravel designed specifically for microservices architecture. It provides an elegant abstraction over the PHP-AMQPLIB library with resilience patterns, performance optimizations, and developer-friendly features.

Features
--------

[](#features)

- **Simple, Expressive API**: Intuitive interface for publishing and consuming messages
- **Resilience Patterns**: Circuit breaker and retry mechanisms to handle RabbitMQ outages gracefully
- **Automatic Reconnection**: Smart reconnection with exponential backoff and configurable retry limits
- **Multiple Serialization Formats**: Support for JSON and MessagePack serialization
- **Message Validation**: Schema validation for messages before publishing
- **Dead Letter Queue Support**: Built-in handling for failed messages
- **Telemetry &amp; Observability**: Comprehensive logging and metrics
- **Batch Processing Optimization**: Efficient handling of large message batches with progress tracking
- **Delivery Tag Caching**: Improved reliability for message acknowledgement in complex scenarios
- **Configurable Error Handling**: Fine-grained control over error behavior
- **Predefined Queues**: Configure queues centrally and reuse them across your application
- **Event Publishing**: Structured events with automatic metadata and correlation tracking

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

[](#installation)

```
composer require ahmedessam/lararabbit
```

The package will automatically register its service provider if you're using Laravel's package auto-discovery.

Configuration
-------------

[](#configuration)

Publish the configuration files:

```
# Publish the main configuration file
php artisan vendor:publish --tag=lararabbit-config

# Publish the predefined queues configuration
php artisan vendor:publish --tag=lararabbit-queues-config
```

This will create:

- `config/rabbitmq.php` file with all general configuration options
- `config/rabbitmq-queues.php` file for predefined queue configurations

Basic Usage
-----------

[](#basic-usage)

### Publishing Messages

[](#publishing-messages)

```
use AhmedEssam\LaraRabbit\Facades\RabbitMQ;

// Simple publish
RabbitMQ::publish('order.created', [
    'order_id' => 123,
    'customer_id' => 456,
    'amount' => 99.99
]);

// Publish with options
RabbitMQ::publish('order.created', $data, [
    'message_id' => $uuid,
    'priority' => 5,
    'headers' => ['source' => 'api']
]);

// Publish event with automatic metadata
RabbitMQ::publishEvent('OrderCreated', [
    'order_id' => 123,
    'customer_id' => 456,
    'amount' => 99.99
]);

// Batch publishing
$messages = [
    [
        'routingKey' => 'order.created',
        'data' => ['order_id' => 123]
    ],
    [
        'routingKey' => 'order.created',
        'data' => ['order_id' => 124]
    ]
];
RabbitMQ::publishBatch($messages);
```

### Consuming Messages

[](#consuming-messages)

```
use AhmedEssam\LaraRabbit\Facades\RabbitMQ;
use PhpAmqpLib\Message\AMQPMessage;

// Set up a queue and bind it to the exchange
RabbitMQ::setupQueue('orders_service', ['order.created', 'order.updated']);

// Consume messages from a queue
RabbitMQ::consume('orders_service', function ($data, AMQPMessage $message) {
    // Process the message data
    echo "Received message: " . print_r($data, true);

    // If you return false, the message will not be acknowledged
    return true;
});
```

### Using Predefined Queues

[](#using-predefined-queues)

```
// Set up a predefined queue from configuration
RabbitMQ::setupPredefinedQueue('order_service');

// Consume from a predefined queue
RabbitMQ::consumeFromPredefinedQueue('order_service', function ($data, $message) {
    // Process the message data
    Log::info("Processing order", $data);
    return true;
});
```

### Using Dead Letter Queues

[](#using-dead-letter-queues)

```
use AhmedEssam\LaraRabbit\Facades\RabbitMQ;

// Set up a queue with a dead letter queue for failed messages
RabbitMQ::setupDeadLetterQueue(
    'orders_service',
    'orders_service_failed',
    ['order.failed']
);

// Consume messages from the dead letter queue
RabbitMQ::consume('orders_service_failed', function ($data, $message) {
    // Process failed messages
    Log::error('Failed to process order', $data);
});
```

### CLI Commands

[](#cli-commands)

List all queues:

```
php artisan lararabbit:list-queues
```

Purge a queue:

```
php artisan lararabbit:purge-queue orders_service
```

Advanced Usage
--------------

[](#advanced-usage)

### Message Validation

[](#message-validation)

```
// Register a schema
app(MessageValidatorInterface::class)->registerSchema('order.created', [
    'order_id' => 'required|integer',
    'customer_id' => 'required|integer',
    'amount' => 'required|numeric'
]);

// Publish with validation
RabbitMQ::publish('order.created', $data, [
    'schema' => 'order.created'
]);
```

### Serialization Formats

[](#serialization-formats)

```
// Set serialization format globally
RabbitMQ::setSerializationFormat('msgpack');

// Or use different formats for different messages
RabbitMQ::setSerializationFormat('json')->publish('order.created', $data);
RabbitMQ::setSerializationFormat('msgpack')->publish('inventory.updated', $data);
```

### Connection Management

[](#connection-management)

The package handles connections efficiently, but you can manually manage them:

```
// Get the connection manager
$connectionManager = RabbitMQ::getConnectionManager();

// Close connection when done
RabbitMQ::closeConnection();
```

### Error Handling and Reconnection

[](#error-handling-and-reconnection)

LaraRabbit provides robust error handling and automatic reconnection capabilities:

```
// Configure error handling options in config/rabbitmq.php
'consumer' => [
    'throw_exceptions' => false,      // Whether to throw exceptions during processing
    'reconnect_delay' => 5,           // Seconds to wait before reconnection
    'reconnect_max_retries' => 3,     // Maximum reconnection attempts
    'stop_on_critical_error' => false,// Whether to stop consumption on critical errors
    'requeue_on_error' => false,      // Whether to requeue failed messages
],

// Consumption will automatically handle reconnection
RabbitMQ::consume('orders_service', function ($data, $message) {
    try {
        // Process message
        return true; // Acknowledge on success
    } catch (\Exception $e) {
        // Failed messages will be handled according to configuration
        return false; // Reject the message
    }
});
```

For more details on error handling, see [ERROR\_HANDLING.md](docs/ERROR_HANDLING.md).

Testing
-------

[](#testing)

The package includes a PHPUnit test suite. You can run the tests with:

```
composer test
```

You can also run individual test suites:

```
# Run only unit tests (no RabbitMQ connection required)
composer test:unit

# Run integration tests (requires RabbitMQ connection)
composer test:integration
```

> Note: Some tests may fail if a RabbitMQ server is not available. This is expected behavior as certain tests require an actual connection to RabbitMQ. These tests are skipped by default in CI environments.

Documentation
-------------

[](#documentation)

LaraRabbit includes comprehensive documentation to help you get the most out of the package:

- [Getting Started Guide](docs/GETTING_STARTED.md) - Essential steps to begin using LaraRabbit
- [Configuration Guide](docs/CONFIGURATION.md) - Detailed configuration options
- [Publishing Messages](docs/PUBLISHING.md) - Advanced publishing techniques
- [Consuming Messages](docs/CONSUMING.md) - Consuming messages efficiently
- [Error Handling](docs/ERROR_HANDLING.md) - Robust error handling strategies
- [Advanced Usage](docs/ADVANCED.md) - Advanced patterns and techniques

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

Security
--------

[](#security)

### Security Recommendations

[](#security-recommendations)

When using LaraRabbit in production environments, consider these security recommendations:

1. **Use SSL/TLS**: Always enable the SSL connection to RabbitMQ in production environments by setting `RABBITMQ_SSL=true` and providing proper certificates.
2. **Custom Credentials**: Never use the default guest/guest credentials in production. Create a dedicated user with appropriate permissions.
3. **Message Validation**: Always use schema validation for messages to prevent malformed data.
4. **Secure Vhost**: Use a dedicated virtual host for your application and limit access to it.
5. **Network Segmentation**: Place RabbitMQ behind a firewall and only allow connections from trusted sources.

### Reporting Security Vulnerabilities

[](#reporting-security-vulnerabilities)

If you discover a security vulnerability within LaraRabbit, please send an email to . All security vulnerabilities will be promptly addressed.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details on how to contribute to this package.

Credits
-------

[](#credits)

- [Ahmed Essam](https://github.com/aahmedessam30)
- [All Contributors](../../contributors)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance49

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

371d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/14383efd445985cf037e39f51ce0228eab1800ddf41cd845457daae1bcd8c192?d=identicon)[aahmedessam30](/maintainers/aahmedessam30)

---

Top Contributors

[![aahmedessam30](https://avatars.githubusercontent.com/u/63825434?v=4)](https://github.com/aahmedessam30 "aahmedessam30 (2 commits)")

---

Tags

laravelevent-drivenqueuerabbitmqmessagingmicroservices

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ahmedessam-lararabbit/health.svg)

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

###  Alternatives

[nuwber/rabbitevents

The Nuwber RabbitEvents package

120515.8k3](/packages/nuwber-rabbitevents)[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2752.3M7](/packages/bschmitt-laravel-amqp)[mookofe/tail

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

5552.5k](/packages/mookofe-tail)[iamfarhad/laravel-rabbitmq

A robust RabbitMQ driver for Laravel Queue with advanced message queuing, reliable delivery, and high-performance async processing capabilities

3215.6k](/packages/iamfarhad-laravel-rabbitmq)[convenia/pigeon

3233.0k](/packages/convenia-pigeon)

PHPackages © 2026

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