Giter Site home page Giter Site logo

amqp's Introduction

anik/amqp

anik/amqp is a php-amqplib wrapper that eases the consumption of RabbitMQ. A painless way of using RabbitMQ.

You can use this package with

Requirements

This package requires the following

  • php >= 7.0
  • ext-bcmath
  • ext-sockets

Installation

The package works with Laravel, Lumen & Laravel zero. Install it via composer.

composer require anik/amqp

For Laravel 

  • Add provider in your config/app.php providers array.
'providers' => [
    /// ... 
    Anik\Amqp\ServiceProviders\AmqpServiceProvider::class,
]
  • Add configuration file amqp.php in your config directory with the following command.
php artisan vendor:publish --provider=Anik\Amqp\ServiceProviders\AmqpServiceProvider

For Lumen

  • Add the service provider in your bootstrap/app.php file.
$app->register(Anik\Amqp\ServiceProviders\AmqpServiceProvider::class);
  • Add configuration amqp.php in your config directory by copying it from vendor/anik/amqp/src/config/amqp.php.

N.B: For Lumen, you don't need to enable Facade.

For Laravel Zero

  • Add provider in your config/app.php providers array.
'providers' => [
    /// ... 
    Anik\Amqp\ServiceProviders\AmqpServiceProvider::class,
]
  • Add configuration amqp.php in your config directory by copying it from vendor/anik/amqp/src/config/amqp.php.

Usage

  • To Publish a message
<?php
// AmqpManager::publish($msg, $routing, $config);
app('amqp')->publish('Message to direct exchange', 'routing-key', [
    'exchange' => [
        'type'    => 'direct',
        'name'    => 'direct.exchange',
    ],
]);
  • To consume a message
<?php
use Anik\Amqp\ConsumableMessage;

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

Documentation

The full documentation of this package is written in this article

Issues & PR

To err is human.

  • If the package generates any issue, please report it. Mention procedures to reproduce it.
  • I would like to merge your PRs if they enrich the package or solve any existing issue.

amqp's People

Contributors

ssi-anik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.