tourze/workerman-messenger-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/workerman-messenger-bundle

最新稳定版本:0.1.0

Composer 安装命令:

composer require tourze/workerman-messenger-bundle

包简介

Workerman + Symfony Messenger

README 文档

README

PHP Version License Build Status Code Coverage

English | 中文

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

  1. Enable the Bundle

Add the bundle to your config/bundles.php:

<?php

return [
    // ... other bundles
    Tourze\WorkermanMessengerBundle\WorkermanMessengerBundle::class => ['all' => true],
];
  1. Configure Symfony Messenger (if not already configured)
# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
            'App\Message\YourMessage': async
  1. 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_request counter
  • WorkerMessageFailedEvent: Increments send_fail counter

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.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-21