简体   繁体   中英

How to get Laravel 5.4 working with AWS SQS Queues

I am using Laravel 5.4 with an SQS Fifo Queue.

I can't seem to be able to get it working with my 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.

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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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