tourze / workerman-messenger-bundle
Workerman + Symfony Messenger
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/tourze/workerman-messenger-bundle
Requires
- php: ^8.1
- ext-pcntl: *
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/event-dispatcher: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/messenger: ^6.4
- workerman/workerman: ^5.1
Requires (Dev)
- maglnet/composer-require-checker: ^4
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-10-31 16:51:52 UTC
README
A Symfony Bundle that integrates Workerman with Symfony Messenger, providing seamless message processing statistics and event handling in high-performance Workerman environments.
Installation
composer require tourze/workerman-messenger-bundle
Quick Start
- Enable the Bundle
Add the bundle to your config/bundles.php:
<?php return [ // ... other bundles Tourze\WorkermanMessengerBundle\WorkermanMessengerBundle::class => ['all' => true], ];
- Configure Symfony Messenger (if not already configured)
# config/packages/messenger.yaml framework: messenger: transports: async: '%env(MESSENGER_TRANSPORT_DSN)%' routing: 'App\Message\YourMessage': async
- Run with Workerman
<?php // workerman.php use Workerman\Worker; use App\Kernel; $kernel = new Kernel('prod', false); $kernel->boot(); $worker = new Worker(); $worker->onMessage = function($connection, $data) use ($kernel) { // Your message processing logic here // Statistics will be automatically tracked by the bundle }; Worker::runAll();
Features
- Automatic Statistics Tracking: Automatically increments Workerman statistics when Symfony Messenger processes messages
- Environment Detection: Only activates when running in Workerman environment
- Zero Configuration: Works out of the box with sensible defaults
- Event-Driven Architecture: Uses Symfony Event Dispatcher for loose coupling
How It Works
The bundle provides an event subscriber that listens to Symfony Messenger events:
- WorkerMessageHandledEvent: Increments- total_requestcounter
- WorkerMessageFailedEvent: Increments- send_failcounter
The statistics are only updated when running in a Workerman environment, making it safe to use in both traditional web and Workerman contexts.
Code Example
<?php use Symfony\Component\Messenger\MessageBusInterface; use App\Message\ProcessDataMessage; class DataProcessor { public function __construct( private MessageBusInterface $bus ) {} public function processData(array $data): void { // Dispatch message - statistics will be automatically tracked $this->bus->dispatch(new ProcessDataMessage($data)); } }
Testing
# Run tests ./vendor/bin/phpunit packages/workerman-messenger-bundle/tests # Run static analysis php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/workerman-messenger-bundle
Requirements
- PHP ^8.3
- Symfony ^7.3
- Workerman ^5.1
License
This package is open-sourced software licensed under the MIT license.