AMQP is a painless Way to Use RabbitMQ with Laravel

AMQP is a painless Way to Use RabbitMQ with Laravel

The anik/amqp package by Syed Sirajul Islam Anik is a php-amqplib wrapper that eases the consumption of RabbitMQ.

You can use this package with Laravel, Lumen, and Laravel Zero. At the time of writing, you will need to configure the service provider manually (a pull request was submitted for package discovery).

We recently wrote about a Laravel Queue Driver for RabbitMQ package, which is a queue driver that enables you to use RabbitMQ with the Laravel queue API. You can think of anik/amqp more as a general package with conveniences on top of php-amqplib, and the RabbitMQ queue driver as a drop-in driver for Laravel queues.

From the package’s readme, here’s how you might publish a message:

app('amqp')->publish('Message to direct exchange', 'routing-key', [
    'exchange' => [
        'type'    => 'direct',
        'name'    => '',

And here’s how you might consume a message:

use Anik\Amqp\ConsumableMessage;

// AmqpManager::consume($consumerHandler, $bindingKey, $config);
app('amqp')->consume(function (ConsumableMessage $message) {
    echo $message->getStream() . PHP_EOL;
}, 'routing-key', [
    'connection' => 'my-connection-name',
    'exchange'   => [
        'type'    => 'direct',
        'name'    => '',
    'queue' => [
        'name'         => '',
        'declare'      => true,
        'exclusive'    => false,
    'qos' => [
        'enabled'            => true,
        'qos_prefetch_count' => 5,

For the documentation (and for a nice overview of RabbitMQ) check out the package author’s post: RabbitMQ for PHP Developers. You can learn more about this package, get full installation instructions, and view the source code on GitHub at ssi-anik/amqp.

Filed in: News


Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Full Stack Software Engineer
Atlanta, GA or Remote
Laravel/PHP Developer
Chicago, IL
Neon One
Software Engineer, Web Applications
Vaughan, ON, Canada
Blast Motion
Contract Services Software Engineer (Laravel | Vue | Tailwind)
Riverbed Technology
Senior Laravel Developer
Wilmington, NC
GE Software Inc.
Senior Full Stack Developer (PHP | Vue | DDD)
Charleston, SC