-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from prooph/init
Enqueue message producer.
- Loading branch information
Showing
23 changed files
with
1,699 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; | ||
} | ||
} |
Oops, something went wrong.