GithubHelp home page GithubHelp logo

riser101 / php-rmqlib Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 21 KB

This is a php wrapper built on top of php-amqplib (@videlalvaro).

License: MIT License

PHP 100.00%
rabbitmq php amqp messaging exchanges publisher-subscriber heartbeat queues async acknowledgement

php-rmqlib's Introduction

RabbitMQ PHP Library

This library is for consuming/publishing to RabbitMQ queues using PHP. It is build on top of php-amqplib which extends the AMQP protocol for RabbitMQ.

Installation

The recommended way to install php-rmqlib is through Composer.

  1. Clone this repo and run php composer.phar install inside library root to install library dependencies.

  2. Now edit QueueConfig.json in library root so that php-rmqlib can talk to your rabbitmq deploy.

     {
         "host": "ip_of_your_deployed_instance_of_rabbitmq",
         "port": 5672,
         "username": "your_rabbitmq_account_username",
         "password": "your_rabbitmq_account_password",
         "vhost": "cs",
         "heartbeat": 10
     }
    
  3. Next, at the top of your PHP script require the rmq.php file : require 'path/to/rabbitmqlib/src/rmq.php';

All done, you're ready to use the awesomeness!

Usage

To use this library, initialize the RabbitMQ class object.

Example 1

This example pushes your messages into the configured queue:

//takes path to QueueConfig.json and log file. Creates a new library object.
$rmq_object = new RabbitMQLib\RabbitMQ(__DIR__ . 'QueueConfig.json', __DIR__ . 'log.txt');
//pushes your job to the queue
$rmq_object->send($queue_name, 'your_message_goes_here', $params);

Example 2

This example pulls your messages into the configured queue:

$rmq_object = new RabbitMQLib\RabbitMQ(__DIR__ . 'QueueConfig.json', __DIR__ . 'log.txt');
//pulls a job from the queue
$res = $rmq_object->get($queue);

Methods

__constructor

It will throw RuntimeExpection if the log file is not writable.

connect

void RabbitMQ::connect()

Connects to the queue

  • Visibility: public

close

void RabbitMQ::connect()

Closes connection and channel to the queue

  • Visibility: public

send

void RabbitMQ::send(string $queue, string $message, object $params)

Post new message to the queue

  • Visibility: public

Arguments

  • $queue string - The name of the queue to use
  • $message string - The message to be posted to queue
  • $params object - Contains message headers

get

void RabbitMQ::get(string $queue)

Get message from queue

  • Visibility: public

Arguments

  • $queue string - The name of the queue to use

ack

void RabbitMQ::ack(string $queue, object $params)

Removes message from the queue

  • Visibility: public

Arguments

  • $queue string - The name of the queue to use
  • $params object - Contains the message object returned by the get method

subscribe

void RabbitMQ::subscribe(string $queue, function $callback)

Subscribes to queue

  • Visibility: public

Arguments

  • $queue string - The name of the queue to use
  • $callback function - Callback function that recieves the message object

requeue

void RabbitMQ::requeue(string $queue, object $params)

Requeues messages back to the queue by sending nacks.

  • Visibility: public

Arguments

  • $queue string - The name of the queue to use
  • $params object - The $msg object returned from the queue

License

Copyright (c) 2015 Yousuf Syed [email protected], contributors. Released under the MIT license

php-rmqlib's People

Contributors

nousernameblah avatar riser101 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  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.