承接 tourze/symfony-async-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tourze/symfony-async-bundle

最新稳定版本:0.0.9

Composer 安装命令:

composer require tourze/symfony-async-bundle

包简介

Symfony异步模块

README 文档

README

English | 中文

Latest Version Total Downloads License

A Symfony bundle that provides asynchronous command execution and service method invocation capabilities using Symfony Messenger.

Features

  • Asynchronous command execution with full support for options and arguments
  • Service method invocation through the #[Async] attribute
  • Built-in error handling and logging
  • Automatic retry mechanism for failed operations
  • Delayed execution support
  • Full integration with Symfony Messenger

Requirements

  • PHP 8.1 or higher
  • Symfony 6.4 or higher
  • Symfony Messenger component

Installation

composer require tourze/symfony-async-bundle

Configuration

Enable the bundle in your config/bundles.php:

return [
    // ...
    Tourze\Symfony\Async\AsyncBundle::class => ['all' => true],
];

Make sure you have configured Symfony Messenger with appropriate transport for async messages.

Quick Start

Asynchronous Command Execution

<?php

use Symfony\Component\Messenger\MessageBusInterface;use Symfony\Component\Messenger\Stamp\AsyncStamp;use Tourze\AsyncCommandBundle\Message\RunCommandMessage;

class MyController
{
    public function __construct(
        private readonly MessageBusInterface $messageBus
    ) {}

    public function someAction()
    {
        // Create a message to run a command asynchronously
        $message = new RunCommandMessage();
        $message->setCommand('app:my-command');
        $message->setOptions([
            '--option1' => 'value1',
            '--option2' => 'value2'
        ]);

        // Dispatch to queue
        $this->messageBus->dispatch($message, [
            new AsyncStamp()
        ]);

        return 'Command queued for execution';
    }
}

Using Async Attribute

You can mark any service method for asynchronous execution using the #[Async] attribute:

<?php

namespace App\Service;

use Tourze\Symfony\AopAsyncBundle\Attribute\Async;

class ReportGenerator
{
    #[Async(retryCount: 3, delayMs: 5000)]
    public function generateLargeReport(int $userId): void
    {
        // This method will be executed asynchronously
        // with 3 retry attempts and 5-second delay

        // ...time-consuming operations
    }
}

Then call the method normally:

$reportGenerator->generateLargeReport(123);
// This returns immediately, with the actual work happening in the background

Contributing

Please see CONTRIBUTING.md for details.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-27