1

I’d like to use Yii2-queue extension. In my project I use Beanstalk and I have more than 100 different queue channels/tubes. What is the correct way to use more than one queue channel/tube for a single queue server?

It does not seem right to me to add 100+ queue components in common/config/main.php with the same configuration where only channel/tube name would differ.

main.php:

...
'mainQueue' => [
    'class' => 'yii\queue\beanstalk\Queue',
    'tube'  => 'mainQueue',
],
'secondQueue' => [
    'class' => 'yii\queue\beanstalk\Queue',
    'tube'  => 'secondQueue',
],
'thirdQueue' => [
    'class' => 'yii\queue\beanstalk\Queue',
    'tube'  => 'thirdQueue',
],
'fourthQueue' => [
    'class' => 'yii\queue\beanstalk\Queue',
    'tube'  => 'fourthQueue',
],
'webhookQueue' => [
    'class' => 'yii\queue\beanstalk\Queue',
    'tube'  => 'webhookQueue',
],
'workerDataQueue' => [
    'class' => 'yii\queue\beanstalk\Queue',
    'tube'  => 'workerDataQueue',
],
'userEventsQueue' => [
    'class' => 'yii\queue\beanstalk\Queue',
    'tube'  => 'userEventsQueue',
],
...
theduck
  • 2,589
  • 13
  • 17
  • 23
  • looks like its the way to go if you have more channels, look at this [example](https://www.yiiframework.com/extension/yiisoft/yii2-queue/doc/guide/2.1/en/usage#multiple-queues) – Muhammad Omer Aslam Dec 03 '19 at 11:18
  • @MuhammadOmerAslam it seems like a poor design to me. Because all of these queue components will be instantiated no matter what, RAM will be allocated and so on - even if the app does not require any of it at given time – Mark Skachkov Dec 03 '19 at 13:21
  • 1
    well i think you can still create an object on runtime using `Yii::createObject()` if you think that initializing them via `config` would be a performance penalty. like for instance `Yii::createObject(['class'=>yii\queue\beanstalk\Queue::class,'tube'=>'userEventQueue'])` – Muhammad Omer Aslam Dec 03 '19 at 14:03

0 Answers0