assegaiphp/beanstalkd
Beanstalkd queue integration for AssegaiPHP framework, enabling job production and consumption using the Pheanstalk library.
Maintainers
Requires
- php: >=8.3
- assegaiphp/common: ^0.4.4
- pda/pheanstalk: ^7.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT 5fe230766aea49b26d87aad57021375a6acc29f3
- Andrew Masiye <amasiye313.woop@gmail.com>
This package is auto-updated.
Last update: 2026-06-25 23:13:36 UTC
README
๐ Assegai LogoA progressive PHP framework for building efficient and scalable web applications.
AssegaiPHP Beanstalkd Queue Integration
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. Theprocess()method must accept acallableand return aQueueProcessResultInterface.
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
- Author - Andrew Masiye
- Website - https://assegaiphp.com
- Twitter - @assegaiphp
License
Assegai is MIT licensed.
