简体   繁体   English

如何使Laravel 5.4与AWS SQS队列一起使用

[英]How to get Laravel 5.4 working with AWS SQS Queues

I am using Laravel 5.4 with an SQS Fifo Queue. 我正在将Laravel 5.4与SQS Fifo队列一起使用。

I can't seem to be able to get it working with my SQS Fifo Queue. 我似乎无法使其与SQS Fifo Queue一起使用。 To Queue my email job. 排队我的电子邮件作业。

Can anyone with experience of this point me in the right direction for how to get laravel working with my SQS Fifo Queue. 任何有此经验的人都可以向我指出如何使laravel与SQS Fifo Queue一起使用的正确方向。

This is my controller code to add the job to the queue: 这是我的控制器代码,用于将作业添加到队列中:

(new ReferFriendEmail($referFriendObj))->onConnection('my_sqs_fifo');

This is the code of my job: 这是我的工作代码:

class ReferFriendEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $referFriendObj = false;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($referFriendObj)
    {
        $this->referFriendObj = $referFriendObj;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(  )
    {
        $input = $this->referFriendObj->input;

        Mail::send( 'emails.refer-a-friend', 
            [
                'user' => $this->referFriendObj->from_user_info,
                'first_name' => strtoupper( trim( $this->referFriendObj->from_user_info->first_name)),
                'unique_link' => $this->referFriendObj->unique_link,
            ],
            function ($m) use ( $input ) {
                    $m->from('ryan_hughes_smith@live.co.uk', 'Kuflink');
                    $m->to($input['to_email'], $input['to_email'] )->subject( "You've been referred to Kuflink by " . $input['first_name'] );
            }
        );

        Email_user_referrer::where('email' , $input['to_email'])
                            ->update(['flag_email_sent' => 1]);
    }
}

It just seems nothing is going sqs. 似乎一切都没有进展。 I am using it as the driver. 我正在使用它作为驱动程序。

Per the comments, you're creating the job, but you aren't actually sending it. 根据评论,您正在创建作业,但实际上并没有发送它。 The dispatch helper does this for you : dispatch助手为您执行以下操作

$job = (new ReferFriendEmail($referFriendObj))->onConnection('my_sqs_fif‌​o');
dispatch($job);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM