Open
Description
Issue: RabbitMQ Job Consumption Fails with Dependency Resolution Exception
- Laravel version: 11.35
- RabbitMQ version: 3.8.3
- Package version: 14.1
Describe the Bug
When attempting to use a job to listen to and consume messages from another application on RabbitMQ, an error occurs during execution. This issue arises when running the job from a class in a separate Laravel service. Specifically, two Laravel services are involved in this scenario.
Steps to Reproduce
-
Configure RabbitMQ queue connection across both Laravel services as follows:
'rabbitmq' => [ // Other configurations... 'queue' => [ 'name' => env('RABBITMQ_QUEUE_NAME', 'default'), 'declare' => true, 'job' => \App\Queue\Jobs\RabbitMQJob::class, ], ]
-
Add the Job class to consume the message from the other service:
RabbitMQJob Class
<?php namespace App\Queue\Jobs; use App\Jobs\ProcessRabbitMQMessageJob; use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob as BaseJob; class RabbitMQJob extends BaseJob { /** * Fire the job. */ public function fire(): void { $payload = $this->payload(); $class = ProcessRabbitMQMessageJob::class; $method = 'handle'; ($this->instance = $this->resolve($class))->{$method}($this, $payload); $this->delete(); } }
ProcessRabbitMQMessageJob Class
<?php namespace App\Jobs; use App\Events\RabbitMQMessageReceivedEvent; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; class ProcessRabbitMQMessageJob implements ShouldQueue { use Queueable; /** * Execute the job. */ public function handle(): void { $data = $this->job->payload(); event(new RabbitMQMessageReceivedEvent($data)); } }
Current Behavior
The dispatched job fails with the following exception:
Illuminate\Contracts\Container\BindingResolutionException
vendor/laravel/framework/src/Illuminate/Container/Container.php:1216
Unresolvable dependency resolving [Parameter #3 [ <required> string $connectionName ]]
in class VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob
Expected Behavior
The job should successfully dispatch the event in the handle
method of the ProcessRabbitMQMessageJob
class.
Additional Context
- Log File: Attached for further analysis.
laravel-2024-12-26.log
Metadata
Metadata
Assignees
Labels
No labels