webit / message-bus-sf-process
1.0.0
2018-01-03 22:34 UTC
Requires
- php: >=7.0
- symfony/process: ^3.0|^4.0
- webit/message-bus: ^1.0.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpspec/phpspec: ^4.2.0
- webit/test-tools: ^1.0.0
Suggests
- symfony/console: To use console commands for Utils and Listeners
Provides
This package is auto-updated.
Last update: 2024-11-20 22:59:20 UTC
README
Symfony Process infrastructure for Message Bus
Installation
composer require webit/message-bus-sf-process=^1.0.0
Usage
ProcessFactory
To use both ProcessPublisher or ProcessConsumer instance of ProcessFactory is needed.
use Webit\MessageBus\Message; use Symfony\Component\Process\Process; class MyProcessFactory implements ProcessFactory { /** * @inheritdoc */ public function create(Message $message) { return new Process( sprintf( '/usr/local/my-binary.php %s %s', escapeshellarg($message->type()), escapeshellarg($message->content()) ) ); } }
Synchronous ProcessLauncher
To run process synchronously use SynchronousProcessLauncher
use Webit\MessageBus\Infrastructure\Symfony\Process\Launcher\SynchronousProcessLauncher; $myFactory = new MyProcessFactory(); $launcher = new SynchronousProcessLauncher($myFactory);
Asynchronous ProcessLauncher
To run process asynchronously use AsynchronousProcessLauncher
use Webit\MessageBus\Infrastructure\Symfony\Process\Launcher\ParallelProcessManager; use Webit\MessageBus\Infrastructure\Symfony\Process\Launcher\AsynchronousProcessLauncher; $myFactory = new MyProcessFactory(); $launcher = new AsynchronousProcessLauncher( $myFactory, new ParallelProcessManager($maxParallelProcessNumber = 5) // to run at most 5 parallel processes );
Publisher integration
Configured ProcessLauncher can be used with ProcessPublisher
use Webit\MessageBus\Infrastructure\Symfony\Process\ProcessPublisher; use Webit\MessageBus\Message; $publisher = new ProcessPublisher($launcher); $publisher->publish(new Message('type', 'content'));
Consumer integration
Configured ProcessLauncher can be used with ProcessConsumer
use Webit\MessageBus\Infrastructure\Symfony\Process\ProcessConsumer; use Webit\MessageBus\Message; $consumer = new ProcessConsumer($launcher); $consumer->consume(new Message('type', 'content'));
Running tests
Install dependencies with composer
docker-compose run --rm composer docker-compose run --rm spec