Coder Social home page Coder Social logo

rabbitmq_client's Introduction

rabbitmq_client (CodeIgniter)

CodeIgniter Library used to easilly interract with RabbitMQ 🐰❀

πŸ“š Dependencies

  • PHP 5.4+ (with Composer)
  • Rabbit MQ Installed on your server (at least 3.5.*)
  • php-amqplib
  • CodeIgniter Framework (3.1.8+ recommanded)

πŸ”° Installation

➑️ Step 1 : Library installation by Composer

Just by running following command in the folder of your project :

composer require romainrg/rabbitmq_client

Or by adding following lines to your composer.json file :

"require": {
    "romainrg/rabbitmq_client": "^6.2.0"
},

Don't forget to include your autoload to CI config file :

$config['composer_autoload'] = FCPATH.'vendor/autoload.php';

➑️ Step 2 : Run a composer update in the directory of your project with the following command :

$ composer require romainrg/rabbitmq_client

➑️ Step 3 : Create the following config file

You have to create it in the CI config folder located in ./application/config/rabbitmq.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Config for Rabbit MQ Library
 */
$config['rabbitmq'] = array(
    'host' => 'localhost',     // <- Your Host       (default: localhost)
    'port' => 5672,            // <- Your Port       (default: 5672)
    'user' => 'username',      // <- Your User       (default: guest)
    'pass' => 'password',      // <- Your Password   (default: guest)
    'vhost' => '/',            // <- Your Vhost      (default: /)
    'allowed_methods' => null, // <- Allowed methods (default: null)
    'non_blocking' => false,   // <- Your Host       (default: false)
    'timeout' => 0             // <- Timeout         (default: 0)          
);

➑️ Step 4 : Load the library in your CI Core Controller file

(Or just in a CI Controller)

$this->load->add_package_path(APPPATH . 'third_party/rabbitmq');
$this->load->library('rabbitmq');
$this->load->remove_package_path(APPPATH . 'third_party/rabbitmq');

➑️ Step 5 : Enjoy and give me some improvements or ideas ! ;)

Examples

➑️ Pushing some datas in a Queue:

This will create, if it does not exist, the 'hello_queue' queue and insert 'Hello World !' text inside it.

$this->rabbitmq->push('hello_queue', 'Hello World !');

If you want to run your CI Controller Method with CLI command :

$ php www.mywebsite.com/index.php 'controller' 'method'

You will have the following return

$ [+] Pushing 'Hello World !' to 'hello_queue' -> OK

➑️ Fetching some datas from a Queue (only in CLI at this time):

This will fetch last inserted datas from the 'hello_queue' in real time, with parmanent mode activated and '_process' callback function.

The PHP Code :

return $this->rabbitmq->pull('hello_queue', true, array($this, '_process'));

Run it in CLI :

$ php www.mywebsite.com/index.php 'controller' 'method'

➑️ Pushing some datas in a Queue with additional parameters:

This will create, if it does not exist, the 'hello_queue' queue and insert 'Hello World !' text inside it, the third parameter TRUE set the durability of the 'hello_queue' (TRUE = permanent, FALSE = not permanent), the last parameter 'delivery_mode (2)' makes message persistent (you can also add some parameters to this array).

$this->rabbitmq->push('hello_queue', 'Hello World !', TRUE, array('delivery_mode' => 2));

For more CodeIgniter libraries, give me a 🍺😁

> Beer road

πŸ”’ License

GNU General Public License v3.0

rabbitmq_client's People

Contributors

dcsadmin avatar romainrg avatar slucienvauthier-santiane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rabbitmq_client's Issues

Renaming rabbitmq Connection

Its a wonderful day i got this code and is working pefect but my problem is how to make my connection known when i open rabbitmq interface it shows undefined connection please will you do a needful?

Unable to install the library using composer

Hi.

I am using CI 3.1.9. when I try to install using composer, I get the following error:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for codeigniter/framework dev-rabbitmq -> satisfiable by codeigniter/framework[dev-rabbitmq].
- romainrg/rabbitmq_client 6.2.0 requires codeigniter/framework ^3.1 -> satisfiable by codeigniter/framework[3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.1.5, 3.1.6, 3.1.7, 3.1.8, 3.1.9].
- Can only install one of: codeigniter/framework[3.1.0, dev-rabbitmq].
- Can only install one of: codeigniter/framework[3.1.1, dev-rabbitmq].
- Can only install one of: codeigniter/framework[3.1.2, dev-rabbitmq].
- Can only install one of: codeigniter/framework[3.1.3, dev-rabbitmq].
- Can only install one of: codeigniter/framework[3.1.4, dev-rabbitmq].
- Can only install one of: codeigniter/framework[3.1.5, dev-rabbitmq].
- Can only install one of: codeigniter/framework[3.1.6, dev-rabbitmq].
- Can only install one of: codeigniter/framework[3.1.7, dev-rabbitmq].
- Can only install one of: codeigniter/framework[3.1.8, dev-rabbitmq].
- Can only install one of: codeigniter/framework[3.1.9, dev-rabbitmq].
- Installation request for romainrg/rabbitmq_client ^6.2.0 -> satisfiable by romainrg/rabbitmq_client[6.2.0].

Any help on this is much appreciated. Thanks

CodeIgniter: Unable to obtain lock

Hi, I'm unable to receive messages through the client. Please advice.

How to listen to the queue in real time through CodeIgniter ?

ERROR - 2018-12-18 00:36:10 --> Session: Unable to obtain lock for ci_session:xxx.xxx.xx.xxx:mg5m2vm69lsataf41bg3plpg6j1htvl7 after 30 attempts, aborting.

Thank you!

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.