Skip to content

Commit

Permalink
Merge pull request #1 from prooph/init
Browse files Browse the repository at this point in the history
Enqueue message producer.
  • Loading branch information
prolic authored Jul 4, 2017
2 parents 5673354 + 57ce03e commit c61642c
Show file tree
Hide file tree
Showing 23 changed files with 1,699 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .docheader
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* This file is part of the prooph/psb-enqueue-producer.
* (c) 2017-%year% prooph software GmbH <[email protected]>
* (c) 2017-%year% Sascha-Oliver Prolic <[email protected]>
* (c) 2017-%year% Formapro <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.settings
/.project
/.buildpath
/vendor
.idea
nbproject
composer.lock
tests/Functional/queues
44 changes: 44 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
language: php

php:
- 7.1

matrix:
fast_finish: true
include:
- php: 7.1
env:
- DEPENDENCIES=""
- EXECUTE_CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.1
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"

cache:
directories:
- $HOME/.composer/cache
- $HOME/.php-cs-fixer
- $HOME/.local

before_script:
- mkdir -p "$HOME/.php-cs-fixer"
- phpenv config-rm xdebug.ini
- composer self-update
- composer update $DEPENDENCIES

script:
- if [[ $TEST_COVERAGE == 'true' ]]; then php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml; else ./vendor/bin/phpunit; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/docheader check src/ tests/; fi

after_success:
- if [[ $TEST_COVERAGE == 'true' ]]; then php vendor/bin/coveralls -v; fi

notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/61c75218816eebde4486
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) 2017, prooph software GmbH
Copyright (c) 2017, Sascha-Oliver Prolic
Copyright (c) 2017, Formapro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Enqueue Message Producer for Prooph Service Bus
===============================================

Use [Enqueue](https://github.com/php-enqueue/enqueue-dev) as a message producer for [Prooph Service Bus](https://github.com/prooph/service-bus).

## Installation

You can install the producer via composer by executing `$ composer require prooph/psb-enqueue-producer`.

## Usage

Check the [EnqueueMessageProducerTest](tests/Functional/EnqueueMessageProducerTest.php). Set up the producer is a straightforward task. Most of
the required components are provided by PSB and Enqueue. This package only provides the glue code needed to let both
systems work together.

## Why Enqueue producer

* You choose a transport from [many supported ones](https://github.com/php-enqueue/enqueue-dev/tree/master/docs/transport).
* Could be used from Symfony as well as plain PHP.
* Supports delayed messages (if transport supports it).
* Supports events, commands and queues with possibility to get result.
* Simple and clean code.

## Support

- Ask prooph questions on [prooph-users](https://groups.google.com/forum/?hl=de#!forum/prooph) google group.
- Ask enqueue questions in [enqueue](https://gitter.im/php-enqueue/Lobby) gitter chat.
- File issues at [https://github.com/prooph/psb-enqueue-producer/issues](https://github.com/prooph/psb-enqueue-producer/issues).
- Say hello in the [prooph gitter](https://gitter.im/prooph/improoph) chat.

## License

It is released under the [MIT License](LICENSE).
19 changes: 13 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,26 @@
],
"require": {
"php": "^7.1",
"enqueue/enqueue": "^0.5",
"prooph/common" : "^4.1",
"prooph/service-bus" : "^6.0"
"enqueue/enqueue": "^0.5.1",
"prooph/common" : "^4.1",
"prooph/service-bus" : "^6.0"
},
"require-dev": {
"react/promise": "^2.4.1",
"react/promise": "^2.4.1",
"enqueue/simple-client": "^0.5",
"symfony/filesystem": "^2.1|^3",
"enqueue/fs": "^0.5",
"container-interop/container-interop": "^1.1",
"enqueue/null": "^0.5",
"psr/container": "^1.0",
"sandrokeil/interop-config": "^2.0.1",
"phpspec/prophecy": "^1.7",
"prooph/php-cs-fixer-config": "^0.1.1",
"phpunit/phpunit": "^6.0"
"phpunit/phpunit": "^6.0",
"malukenho/docheader": "^0.1.4"
},
"suggest" : {
"psr/container": "^1.0 for usage of provided factories",
"sandrokeil/interop-config": "For usage of provided factories"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuite name="Prooph ServiceBus Enqueue MessageProducer Test Suite">
<directory>./tests/</directory>
</testsuite>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
92 changes: 92 additions & 0 deletions src/Container/EnqueueMessageProcessorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* This file is part of the prooph/psb-enqueue-producer.
* (c) 2017-2017 prooph software GmbH <[email protected]>
* (c) 2017-2017 Sascha-Oliver Prolic <[email protected]>
* (c) 2017-2017 Formapro <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\ServiceBus\Message\Enqueue\Container;

use Interop\Config\ConfigurationTrait;
use Interop\Config\ProvidesDefaultOptions;
use Interop\Config\RequiresConfigId;
use Prooph\ServiceBus\CommandBus;
use Prooph\ServiceBus\EventBus;
use Prooph\ServiceBus\Exception\InvalidArgumentException;
use Prooph\ServiceBus\Message\Enqueue\EnqueueMessageProcessor;
use Prooph\ServiceBus\Message\Enqueue\EnqueueSerializer;
use Prooph\ServiceBus\QueryBus;
use Psr\Container\ContainerInterface;

class EnqueueMessageProcessorFactory implements ProvidesDefaultOptions, RequiresConfigId
{
use ConfigurationTrait;
/**
* @var string
*/
private $messageProducerCallbackName;

/**
* Creates a new instance from a specified config, specifically meant to be used as static factory.
*
* In case you want to use another config key than provided by the factories, you can add the following factory to
* your config:
*
* <code>
* <?php
* return [
* 'message_producer' => [EnqueueMessageProcessorFactory::class, 'message_producer_name'],
* ];
* </code>
*
* @throws InvalidArgumentException
*/
public static function __callStatic(string $messageProducerCallbackName, array $arguments): EnqueueMessageProcessor
{
if (! isset($arguments[0]) || ! $arguments[0] instanceof ContainerInterface) {
throw new InvalidArgumentException(
sprintf('The first argument must be of type %s', ContainerInterface::class)
);
}

return (new static($messageProducerCallbackName))->__invoke($arguments[0]);
}

public function __construct(string $messageProducerCallbackName)
{
$this->messageProducerCallbackName = $messageProducerCallbackName;
}

public function __invoke(ContainerInterface $container): EnqueueMessageProcessor
{
$options = $this->options($container->get('config'), $this->messageProducerCallbackName);

return new EnqueueMessageProcessor(
$container->get($options['command_bus']),
$container->get($options['event_bus']),
$container->get($options['query_bus']),
$container->get($options['serializer'])
);
}

public function dimensions(): iterable
{
return ['prooph', 'enqueue-producer', 'message_processor'];
}

public function defaultOptions(): iterable
{
return [
'command_bus' => CommandBus::class,
'event_bus' => EventBus::class,
'query_bus' => QueryBus::class,
'serializer' => EnqueueSerializer::class,
];
}
}
90 changes: 90 additions & 0 deletions src/Container/EnqueueMessageProducerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* This file is part of the prooph/psb-enqueue-producer.
* (c) 2017-2017 prooph software GmbH <[email protected]>
* (c) 2017-2017 Sascha-Oliver Prolic <[email protected]>
* (c) 2017-2017 Formapro <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\ServiceBus\Message\Enqueue\Container;

use Enqueue\SimpleClient\SimpleClient;
use Interop\Config\ConfigurationTrait;
use Interop\Config\ProvidesDefaultOptions;
use Interop\Config\RequiresConfigId;
use Prooph\ServiceBus\Exception\InvalidArgumentException;
use Prooph\ServiceBus\Message\Enqueue\EnqueueMessageProducer;
use Prooph\ServiceBus\Message\Enqueue\EnqueueSerializer;
use Psr\Container\ContainerInterface;

class EnqueueMessageProducerFactory implements ProvidesDefaultOptions, RequiresConfigId
{
use ConfigurationTrait;
/**
* @var string
*/
private $messageProducerCallbackName;

/**
* Creates a new instance from a specified config, specifically meant to be used as static factory.
*
* In case you want to use another config key than provided by the factories, you can add the following factory to
* your config:
*
* <code>
* <?php
* return [
* 'message_producer' => [EnqueueMessageProducerFactory::class, 'message_producer_name'],
* ];
* </code>
*
* @throws InvalidArgumentException
*/
public static function __callStatic(string $messageProducerCallbackName, array $arguments): EnqueueMessageProducer
{
if (! isset($arguments[0]) || ! $arguments[0] instanceof ContainerInterface) {
throw new InvalidArgumentException(
sprintf('The first argument must be of type %s', ContainerInterface::class)
);
}

return (new static($messageProducerCallbackName))->__invoke($arguments[0]);
}

public function __construct(string $messageProducerCallbackName)
{
$this->messageProducerCallbackName = $messageProducerCallbackName;
}

public function __invoke(ContainerInterface $container): EnqueueMessageProducer
{
$options = $this->options($container->get('config'), $this->messageProducerCallbackName);

return new EnqueueMessageProducer(
$container->get($options['client'])->getProducer(),
$container->get($options['serializer']),
$options['command_name'],
$options['reply_timeout']
);
}

public function dimensions(): iterable
{
return ['prooph', 'enqueue-producer', 'message_producer'];
}

public function defaultOptions(): iterable
{
return [
'client' => SimpleClient::class,
'serializer' => EnqueueSerializer::class,
'command_name' => 'prooph_bus',
'reply_timeout' => 30000, // 30sec
];
}
}
Loading

0 comments on commit c61642c

Please sign in to comment.