承接 assegaiphp/beanstalkd 相关项目开发

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

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

assegaiphp/beanstalkd

最新稳定版本:1.0.1

Composer 安装命令:

composer require assegaiphp/beanstalkd

包简介

Beanstalkd queue integration for AssegaiPHP framework, enabling job production and consumption using the Pheanstalk library.

README 文档

README

Assegai Logo

A progressive PHP framework for building efficient and scalable web applications.

AssegaiPHP Beanstalkd Queue Integration

License AssegaiPHP

This package adds Beanstalkd queue support to the AssegaiPHP framework using the Pheanstalk PHP client.

📦 Installation

Install via Composer:

composer require assegaiphp/beanstalkd

Or use the Assegai CLI:

assegai add beanstalkd

⚙️ Configuration

Add a Beanstalk driver and connection to your config/queues.php file:

<?php

return [
  'drivers' => [
    'beanstalk' => Assegai\Beanstalkd\BeanstalkdQueue::class,
  ],
  'connections' => [
    'beanstalk' => [
      'notifications' => [
        'host' => 'localhost',
        'port' => 11300,
        'connection_timeout' => 10,
        'receive_timeout' => 10,
      ],
    ],
  ],
];

💡 The format is: 'driverName.queueName', e.g., 'beanstalk.notifications'.

✨ Usage

Producing Jobs

Inject a queue instance in your service using #[InjectQueue]:

use Assegai\Core\Queues\Attributes\InjectQueue;
use Assegai\Core\Queues\Interfaces\QueueInterface;

readonly class NotificationsService
{
  public function __construct(
    #[InjectQueue('beanstalk.notifications')] private QueueInterface $queue
  ) {}

  public function send(array $payload): void
  {
    $this->queue->add($payload);
  }
}

Consuming Jobs

Create a queue consumer class with #[Processor] and extend WorkerHost:

use Assegai\Core\Queues\Attributes\Processor;
use Assegai\Core\Queues\WorkerHost;
use Assegai\Core\Queues\QueueProcessResult;
use Assegai\Core\Queues\Interfaces\QueueProcessResultInterface;

#[Processor('beanstalk.notifications')]
class NotificationsConsumer extends WorkerHost
{
  public function process(callable $callback): QueueProcessResultInterface
  {
    $job = $callback();
    $data = $job->data;

    echo "Dispatching notification: {$data->message}" . PHP_EOL;

    return new QueueProcessResult(data: ['status' => 'sent'], job: $job);
  }
}

⚠️ Do not use #[Injectable] on consumers. The process() method must accept a callable and return a QueueProcessResultInterface.

Running the Worker

Start the queue worker using:

assegai queue:work

This will continuously listen for jobs from the configured Beanstalk tube.

🧪 Testing

You can simulate jobs by calling the service from a controller or CLI command and watch the consumer terminal for output.

📚 Resources

Support

Assegai is an MIT-licensed open source project. It can grow thanks to sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Assegai is MIT licensed.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固