我有两个环境,QA(1个网络服务器)和Prod(负载均衡器后面有2个网络服务器),它们使用数据库队列设置方式相同。
在QA上一切正常。
On Production,我有一些奇怪的行为...... Mailable使用Queue工作正常,但电子邮件通知不适用于队列。
如果我从通知中删除队列,则会发送电子邮件。
在QA上,我可以看到在作业表中创建的两个作业。 在Prod上,只有Mailable在作业表中创建。
激活电子邮件示例:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class SendActivationEmail extends Notification implements ShouldQueue
{
use Queueable;
protected $token;
/**
* Create a new notification instance.
*
* SendActivationEmail constructor.
* @param $token
*/
public function __construct($token)
{
$this->token = $token;
$this->onQueue('social');
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Activation email')
->greeting('xxxxxx - Hello!')
->line('You need to activate your email before you can start using all of our services.')
->action('Activate Email', route('authenticated.activate', ['token' => $this->token]))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
我的.env文件:
QUEUE_DRIVER=database
文件config / queue.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Queue Driver
|--------------------------------------------------------------------------
|
| The Laravel queue API supports a variety of back-ends via an unified
| API, giving you convenient access to each back-end using the same
| syntax for each one. Here you may set the default queue driver.
|
| Supported: "null", "sync", "database", "beanstalkd",
| "sqs", "iron", "redis"
|
*/
'default' => env('QUEUE_DRIVER', 'database'),
/*
|--------------------------------------------------------------------------
| Queue Connections
|--------------------------------------------------------------------------
|
| Here you may configure the connection information for each server that
| is used by your application. A default configuration has been added
| for each back-end shipped with Laravel. You are free to add more.
|
*/
'connections' => [
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
我的Mailable与队列一起工作:
Mail::to($user->email)
->queue(new Welcome($user));
非常感谢你的帮助
答案 0 :(得分:0)
我想这与.env文件有关
只需确保两个env文件都使用正确的队列驱动程序。
您的队列工作者已启用(Cron,supervisorcrl ..)