2
votes

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('[email protected]', '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.

1
Is laravel.com/docs/5.4/queues not sufficient? To my knowledge, there's nothing specific to SQS FIFO queues that make them different for Laravel's purposes. They should work out-of-the-box. What exactly are you having trouble with?ceejayoz
I have a route where the user can submit as many email addresses as possible to refer their friends to our platform. My Main problem is my job is never being run and I can't see anything in my queue on AWS SQS console. This gets run in my code (new ReferFriendEmail($referFriendObj))->onConnection('my_sqs_fifo'); I have no errors and all config is pointing to my SQS queue and nothing is happening.Ryan Wilson
Can you share your code? Did you call the dispatch() function on the job?ceejayoz
I see you've edited in some code, but I'm more interested in where (new ReferFriendEmail($referFriendObj))->onConnection('my_sqs_fifo') happens. Per the docs, it should be dispatch()ed.ceejayoz
No I used this: (new ReferFriendEmail($referFriendObj))->onConnection('sqs');Ryan Wilson

1 Answers

4
votes

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);