arthurhoaro/simple-php-messaging-service

SimplePMS is a PHP message service with database backend using SQLite, PostgreSQL or MySQL

dev-master 2016-05-08 12:51 UTC

This package is auto-updated.

Last update: 2024-03-10 21:21:10 UTC


README

Build Status Coverage Status

SimplePMS is a very simple messaging service component with a database backend.

It allows applications to communicate without a heavy traditional client-server architecture. It is a way to manage asynchronous, potentially long-running PHP tasks such as API requests, database export/import operations, email sending, payment notification handlers, feed generation etc.

This project is based on php-queue-manager, except I wanted my messages to be only messages. Therefore, messages are not tasks in SimplePMS and are not expected to carry business code.

SimplePMS can be integrated to any PHP based application with minimum effort, because it does not depend on any framework. PDO extension is the only requirement.

If you need a more feature-full messaging service - e.g. multiple workers consuming the same queue - consider using a robust messaging service/queue manager such as JMS, ActiveMQ, RabbitMQ, IronMQ, etc. ; even though it requires a more complex setup.

Requirements

  • PHP >5.5
  • PDO
  • Database backend (sqlite, PostgreSQL, MySQL)

Features

  • Asynchronous messaging service through database.
  • Send any type of data.
  • Multiple queues.
  • A timeout system to handle stuck messages.
  • All actions are log in the DB.

Install with Composer

  • Install dependency
{
    "require": {
        "arthurhoaro/simple-php-messaging-service": "dev-master"
    }
}
  • Create your database structure using one of the schema available in extra/.

Usage example

// Your software send a message to a worker
$message = new Anything('param');
$pms = new SimplePMS();
$pms->setPdo($pdoInstance);
$pms->send($message, 'my_queue');

// The worker reads the queue
$message = $pms->reveive('my_queue');
try {
    $message->doAnything();
    $pms->deleteMessage($message);
} catch (\Exception $e) {
    $pms->log('Can not do anything. '. $e->getMessage());
}