Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue is created with the wrong channel #106

Open
romkatsu opened this issue Nov 21, 2021 · 1 comment
Open

Queue is created with the wrong channel #106

romkatsu opened this issue Nov 21, 2021 · 1 comment
Assignees
Labels
status:under development Someone is working on a pull request. type:docs Documentation
Milestone

Comments

@romkatsu
Copy link
Member

What steps will reproduce the problem?

Configure queue

    'yiisoft/yii-queue' => [
        'handlers' => [
            'yii-queue-1' => [new \App\Job\HandlerOne(), 'handle'],
        ],
        'channel-definitions' => [
            'yii-queue-1' => \Yiisoft\Yii\Queue\AMQP\Adapter::class,
        ],
    ],

Push message:

$message = new \Yiisoft\Yii\Queue\Message\Message('yii-queue-1', ['message']);
$this->queueFactory->get('yii-queue-1')->push($message);

What is the expected result?

A queue will be created 'yii-queue-1'

What do you get instead?

A queue has been created with the default name 'yii-queue'

изображение

Additional info

There will be no problem if configured like this:

'channel-definitions' => [
    'yii-queue-1' =>  static fn(\Yiisoft\Yii\Queue\AMQP\Adapter $adapter) => $adapter->withChannel('yii-queue-1'),
],

The problem is in the factory, here:
https://github.com/yiisoft/yii-queue/blob/master/src/QueueFactory.php#L89

@samdark samdark added the type:bug Bug label Nov 21, 2021
@viktorprogger
Copy link
Contributor

Hi, @romkatsu. I remember I've talked to you in PM about that. And we didn't fully understand each other that time. Now I'm ready to clarify the rest. In my opinion the only bug is in docs.

  1. Message name
'handlers' => [
    'yii-queue-1' => [new \App\Job\HandlerOne(), 'handle'],
],

In this example you are ready to handle messages with name yii-queue-1, and it doesn't matter, from which channel/queue.

  1. Channel name
'channel-definitions' => [
    'yii-queue-1' => \Yiisoft\Yii\Queue\AMQP\Adapter::class,
],

Here the key yii-queue-1 is just an application-defined channel name. And its value, \Yiisoft\Yii\Queue\AMQP\Adapter::class, is a definition of the channel. You can use any definition supported by yiisoft/definitions. In this particular case you just say "Give me the default instance of Adapter::class from the container". To set a different queue name for the amqp adapter, you can use the $adapter->withChannel() method. You can even use a different adapter here (i.e. for redis, or the synchronous one).

@viktorprogger viktorprogger added type:docs Documentation and removed type:bug Bug labels Feb 14, 2022
@viktorprogger viktorprogger added this to the 1.0.0-alpha1 milestone Nov 10, 2022
@viktorprogger viktorprogger added the status:under development Someone is working on a pull request. label May 28, 2023
@viktorprogger viktorprogger self-assigned this May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:under development Someone is working on a pull request. type:docs Documentation
Projects
None yet
Development

No branches or pull requests

3 participants