Webador / SlmQueue

Laminas / Mezzio module that integrates with various queue management systems.
Other
138 stars 57 forks source link

I can't retrieve a queue from the QueueManager when working with Mezzio #235

Closed settermjd closed 3 years ago

settermjd commented 3 years ago

I'm trying to use the library, along with rnd-cosoft/slm-queue-rabbitmq with a Mezzio application, and for the most part everything works just fine. However, when I try to retrieve the default queue, or any queue, from the QueuePluginManager, I'm unable to. I get two errors, depending on what I try to do:

I get this one if I use a string name, such as "default".

A plugin by the name "default" was not found in the plugin manager SlmQueue\Queue\QueuePluginManager

I get the following error if I use an existing *Queue class, such as by caling $queue = $this->queuePluginManager->get(RabbitMqQueue::class).

Too few arguments to function SlmQueueRabbitMq\Queue\RabbitMqQueue::__construct(), 0 passed in /.../vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php on line 31 and exactly 4 expected

As a bit of background:

$queuePluginManager is instantiated as follows:

$queue = $this->queuePluginManager->get(RabbitMqQueue::class)

Here is the relevant section of slm_queue.global.php:

return [
    'slm_queue' => [
        'queue_manager' => [
            'factories' => [
                'default' => \SlmQueueRabbitMq\Factory\RabbitMqQueueFactory::class,
            ]
        ]
    ]
];

And here are (most of) the applications dependencies:

return [
    'dependencies' => [
        'factories'  => [
            Worker\RabbitMqWorker::class => Factory\RabbitMqWorkerFactory::class,
            'SlmQueueRabbitMq\Config' => ConfigFactory::class,
            JobPluginManager::class => JobPluginManagerFactory::class,
            StrategyPluginManager::class => StrategyPluginManagerFactory::class,
            QueuePluginManager::class => QueuePluginManagerFactory::class,
            Queue\RabbitMqQueue::class => RabbitMqQueueFactory::class,
        ],
    ],
];
roelvanduijnhoven commented 3 years ago

@settermjd The way you initialize and call looks correct to me! I have no experience myself with using the RabbitMq version, but that should run just fine.

$this->queuePluginManager->get('default')

This is the correct way to get access to the queue. So it really should respond with a queue instance.

and for the most part everything works just fine

Do you mean you can actually run jobs from the queue? But it will only fail when you programmatically try to access the queue?

Are you sure you load this part of the configuration? Could you for example test if chaning the RabbitMqQueueFactory part to some rubish, or simply adding a typo to this PHP file will change the execution?

return [
    'slm_queue' => [
        'queue_manager' => [
            'factories' => [
                'default' => \SlmQueueRabbitMq\Factory\RabbitMqQueueFactory::class,
            ]
        ]
    ]
];

Let me know! Would love to help.