Lumen-framework: SQS email queuing broken (Mailer is not instantiable)

Created on 19 Jul 2017  路  3Comments  路  Source: laravel/lumen-framework

  • Lumen Version: 5.4.5
  • PHP Version: 7.1.7
  • Database Driver & Version: MongoDB 3.4.6

Description:

Queuing mailables with Mail::bcc($emails)->queue($mailable); works fine, and the jobs are visible in the SQS queue. But as soon as I run php artisan queue:work --once I get

lumen.ERROR: Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Mail\Mailer] is not instantiable. in /path/to/vendor/illuminate/container/Container.php:804
Stack trace:
#0 /path/to/vendor/illuminate/container/Container.php(687): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 /path/to/vendor/illuminate/container/Container.php(565): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 /path/to/vendor/laravel/lumen-framework/src/Application.php(208): Illuminate\Container\Container->make('Illuminate\\Cont...')
#3 /path/to/vendor/illuminate/container/BoundMethod.php(155): Laravel\Lumen\Application->make('Illuminate\\Cont...')
#4 /path/to/vendor/illuminate/container/BoundMethod.php(115): Illuminate\Container\BoundMethod::addDependencyForCallParameter(Object(Laravel\Lumen\Application), Object(ReflectionParameter), Array, Array)
#5 /path/to/vendor/illuminate/container/BoundMethod.php(28): Illuminate\Container\BoundMethod::getMethodDependencies(Object(Laravel\Lumen\Application), Array, Array)
#6 /path/to/vendor/illuminate/support/helpers.php(925): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#7 /path/to/vendor/illuminate/container/BoundMethod.php(86): value(Object(Closure))
#8 /path/to/vendor/illuminate/container/BoundMethod.php(30): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#9 /path/to/vendor/illuminate/container/Container.php(524): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#10 /path/to/vendor/illuminate/bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#11 /path/to/vendor/illuminate/pipeline/Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Illuminate\Mail\SendQueuedMailable))
#12 /path/to/vendor/illuminate/pipeline/Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Mail\SendQueuedMailable))
#13 /path/to/vendor/illuminate/bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#14 /path/to/vendor/illuminate/queue/CallQueuedHandler.php(42): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Mail\SendQueuedMailable), false)
#15 /path/to/vendor/illuminate/queue/Jobs/Job.php(69): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\SqsJob), Array)
#16 /path/to/vendor/illuminate/queue/Worker.php(291): Illuminate\Queue\Jobs\Job->fire()
#17 /path/to/vendor/illuminate/queue/Worker.php(258): Illuminate\Queue\Worker->process('sqsfifo', Object(Illuminate\Queue\Jobs\SqsJob), Object(Illuminate\Queue\WorkerOptions))
#18 /path/to/vendor/illuminate/queue/Worker.php(110): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\SqsJob), 'sqsfifo', Object(Illuminate\Queue\WorkerOptions))
#19 /path/to/vendor/illuminate/queue/Console/WorkCommand.php(100): Illuminate\Queue\Worker->daemon('sqsfifo', 'https://sqs.eu-...', Object(Illuminate\Queue\WorkerOptions))
#20 /path/to/vendor/illuminate/queue/Console/WorkCommand.php(84): Illuminate\Queue\Console\WorkCommand->runWorker('sqsfifo', 'https://sqs.eu-...')
#21 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#22 /path/to/vendor/illuminate/container/BoundMethod.php(28): call_user_func_array(Array, Array)
#23 /path/to/vendor/illuminate/support/helpers.php(925): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#24 /path/to/vendor/illuminate/container/BoundMethod.php(86): value(Object(Closure))
#25 /path/to/vendor/illuminate/container/BoundMethod.php(30): Illuminate\Container\BoundMethod::callBoundMethod(Object(Laravel\Lumen\Application), Array, Object(Closure))
#26 /path/to/vendor/illuminate/container/Container.php(524): Illuminate\Container\BoundMethod::call(Object(Laravel\Lumen\Application), Array, Array, NULL)
#27 /path/to/vendor/illuminate/console/Command.php(182): Illuminate\Container\Container->call(Array)
#28 /path/to/vendor/symfony/console/Command/Command.php(264): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#29 /path/to/vendor/illuminate/console/Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#30 /path/to/vendor/symfony/console/Application.php(835): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#31 /path/to/vendor/symfony/console/Application.php(200): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 /path/to/vendor/symfony/console/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /path/to/vendor/laravel/lumen-framework/src/Console/Kernel.php(84): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /path/to/artisan(39): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Any help on this issue is greatly appreciated!

Steps To Reproduce:

Configure a normal SQS queue in AWS and configure the default lumen queue driver to be sqs (I'm using the FIFO SQS queue, which needed some tweaking to get to work).
Now, regarding issue #590, I had to manually set the queue for the Mailer instance in my own ServiceProvider.
Send an email by using Mail::to($emailAddress)->queue(new Mailable());. Make sure the job is found in AWS SQS -> then run php artisan queue:work --once and check your lumen.log for the error.

Most helpful comment

This issue can be fixed by creating a new MailServiceProvider which extends \Illuminate\Mail\MailServiceProvider and in the register function, configure the mailer: $this->app->configure('mail'); and create an alias for the mailer contract:
$this->app->alias('mailer', \Illuminate\Contracts\Mail\Mailer::class);

Register the service provider in bootstrap/app.php.

These kinds of things would be nice if they would work out of the box.

All 3 comments

This issue can be fixed by creating a new MailServiceProvider which extends \Illuminate\Mail\MailServiceProvider and in the register function, configure the mailer: $this->app->configure('mail'); and create an alias for the mailer contract:
$this->app->alias('mailer', \Illuminate\Contracts\Mail\Mailer::class);

Register the service provider in bootstrap/app.php.

These kinds of things would be nice if they would work out of the box.

@soderluk I can't solve yet. Could you show me how to?

EDIT I've got it. Thanks.

@taylorotwell
It seems that you should take a look at the question. illuminate/mail support for lumen is not ideal.

I've read some answers, and lumen will cause this error since 5.2, because it has removed 'Illuminate\Contracts\Mail\Mailer'= >'registerMailBindings' relative to 5.1.

5.1
5.2

I tried to find the answer in the update log, but I didn't seem to be so lucky.

Is it given up by lumen, or is it a bug?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

megawubs picture megawubs  路  5Comments

dunice picture dunice  路  3Comments

patrikengborg picture patrikengborg  路  3Comments

maglor picture maglor  路  3Comments

matthewsuan picture matthewsuan  路  3Comments