Skip to content

Error: Unresolvable dependency resolving [Parameter #3 [ <required> string $connectionName ]] in class VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob #614

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

Open
Ojsholly opened this issue Dec 26, 2024 · 1 comment
Assignees

Comments

@Ojsholly
Copy link

Ojsholly commented Dec 26, 2024

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

  1. 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,
        ],
    ]
  2. 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

@yusufalper
Copy link

This problem still persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants