Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/antidot-framework/message-queue

Message queue for Antidot Framework.
https://github.com/antidot-framework/message-queue

hacktoberfest php queue-workers

Last synced: 3 days ago
JSON representation

Message queue for Antidot Framework.

Awesome Lists containing this project

README

        

# Antidot Framework Message Queue

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/antidot-framework/message-queue/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/antidot-framework/message-queue/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/antidot-framework/message-queue/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/antidot-framework/message-queue/?branch=master)
[![Type Coverage](https://shepherd.dev/github/antidot-framework/message-queue/coverage.svg)](https://shepherd.dev/github/antidot-framework/message-queue)
[![Psalm Level](https://shepherd.dev/github/antidot-framework/message-queue/level.svg)](https://shepherd.dev/github/antidot-framework/message-queue)
[![Build Status](https://scrutinizer-ci.com/g/antidot-framework/message-queue/badges/build.png?b=master)](https://scrutinizer-ci.com/g/antidot-framework/message-queue/build-status/master)
[![Code Intelligence Status](https://scrutinizer-ci.com/g/antidot-framework/message-queue/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence)

Message queue implementation using [enqueue/enqueue](https://github.com/php-enqueue/enqueue-dev) for Antidot Framework.

```bash
composer require antidot-fw/message-queue
```

## Message Queue

> A message queue is an asynchronous communication method. It allows storing messages in the queue system until they are consumed and destroyed.
>Each message is processed only once by a unique consumer.

### Different Queue Systems

* Null Queue
* Filesystem Queue
* DBAL Queue
* Redis Queue
* Beanstalk
* Amazon SQS

Each implementation will have different configuration details, see concrete documentation section. Furthermore,
you can use any of [systems implemented in the PHP-enqueue package](https://php-enqueue.github.io/transport), making the needed factories.
### Usage

You can define as many contexts as you need. You can bind each context to different queues.
Once you have created a Context class, you can start sending jobs to the queue.
The job should contain the queue name, the message type, and the message itself.

```php
get(\Antidot\Queue\Producer::class);
$producer->enqueue(Job::create('some_queue', 'some_message', 'Hola Mundo!!'));
```

Start listening a queue

```bash
bin/console queue:start default # "default is the queue name"
```

Now you can configure actions for the message types received by the queue.
The action is a callable class that receives a JobPayload as the first parameter.

### Jobs and Producer

A Job is a class responsible for transport given data to the queue. It is composed of two parameters: the Queue name as a single string,
and the JobPayload with the data to process in the queue. JsonPayload is a JSON serializable object composed of two other parameters:
the message type and the message data as string or array.

Once you have a job class, you need to pass it to the producer to send the message to the queue. See the example below.
```php
get(Producer::class);

// Send String Job of type "some_message_type" to "default" queue.
$job1 = Job::create('default', 'some_message_type', 'Hello world!!');
$producer->enqueue($job1);

// Send Array Job of type "other_message_type" to "other_queue" queue.
$job2 = Job::create('other_queue', 'other_message_type', ['greet' => 'Hello world!!']);
$producer->enqueue($job2);

```

### Actions

The actions are invokable classes that will execute when the queue processes the given message. This class has a unique parameter, the JobPayload.

```php