binary-cube/carrot-mq

Carrot MQ :: Food for thought

0.1.3 2019-12-03 22:17 UTC

This package is auto-updated.

Last update: 2020-08-07 14:40:21 UTC


README

~ Enjoy your ☕ ~

Minimum PHP Version PHP >= 7.1 Latest Stable Version Total Downloads Build Status Code Coverage Quality Score License

Requirements

This package requires the following

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

Installing

  • via "composer require":

    composer require binary-cube/carrot-mq
  • via composer (manually):

    If you're using Composer to manage dependencies, you can include the following in your composer.json file:

    {
        "require": {
            "binary-cube/carrot-mq": "0.*"
        }
    }

Example of usage

<?php

use BinaryCube\CarrotMQ\CarrotMQ;
use BinaryCube\CarrotMQ\Driver\AmqpDriver;
use BinaryCube\CarrotMQ\Processor\Processor;
use BinaryCube\CarrotMQ\Extension\SignalExtension;

include __DIR__ . '/vendor/autoload.php';

$config = [
    'connections' => [
        'default' => [
            'config' => [
                'extension' => AmqpDriver::EXTENSION_AMQP_LIB,
                'host'      => '127.0.0.1',
                'port'      => '5672',
                'username'  => 'guest',
                'password'  => 'guest',
                'vhost'     => '/',
                'persisted' => false,
            ],
        ],
    ],

    'topics' => [
        'topic-id-1' => [
            'name'       => 't1',
            'connection' => 'default',
        ],
    ],

    'queues' => [
        'queue-id-1' => [
            'name'       => 'foo',
            'connection' => 'default',
            'config' => [
                'durable' => true,
                'bind' => [
                    [
                        'topic'       => 't1',
                        'routing_key' => 'some-routing-key',
                    ],
                 ],
            ],
        ],
    ],

    'publishers' => [
        'publisher-1' => [
            'topic'  => 'topic-id-1',
            'config' => [],
        ],
    ],

    'consumers' => [
        'c1' => [
            'queue'      => 'queue-id-1',
            'processor'  => function (\Interop\Amqp\AmqpMessage $message) {
                echo \vsprintf('Message body size: %s', [\mb_strlen($message->getBody())]) . PHP_EOL;
                return Processor::REQUEUE;
            },
            'config'     => [
                'receive_timeout' => 30,
                'qos' => [
                    'enabled'        => false,
                    'prefetch_size'  => 0,
                    'prefetch_count' => 0,
                    'global'         => false,
                ]
            ],
        ],
    ],
];

$carrot = new CarrotMQ($config);

$consumer = $carrot->container()->consumers()->get('c1');

$extension = new SignalExtension();


/**
 * @var BinaryCube\CarrotMQ\Consumer $consumer
 */
$consumer->extensions()->add($extension::name(), $extension);

$consumer->consume();

Bugs and feature requests

Have a bug or a feature request? Please first read the issue guidelines and search for existing and closed issues. If your problem or idea is not addressed yet, please open a new issue.

Contributing guidelines

All contributions are more than welcomed. Contributions may close an issue, fix a bug (reported or not reported), add new design blocks, improve the existing code, add new feature, and so on. In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. Read the full Code of Conduct.

Versioning

Through the development of new versions, we're going use the Semantic Versioning.

Example: 1.0.0.

  • Major release: increment the first digit and reset middle and last digits to zero. Introduces major changes that might break backward compatibility. E.g. 2.0.0
  • Minor release: increment the middle digit and reset last digit to zero. It would fix bugs and also add new features without breaking backward compatibility. E.g. 1.1.0
  • Patch release: increment the third digit. It would fix bugs and keep backward compatibility. E.g. 1.0.1

Authors

  • Banciu N. Cristian Mihai

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.