Send to a Laravel Queue an instance of SesClient from AWS sdk for php

578 Views Asked by At

I'm using the Amazon sdk for php to send emails through the Simple Email Service all this using Lumen Framework.

I'm using the client class of the sdk instead of the mailables classes of Laravel because I need to add some metadata to my emails the problem comes when I try to push the emails to a queue because the SesClient from the AWS sdk forbids the serialization and Laravel/Lumen uses this function to create the queue

I tried to wrap the class but it didn't work also I found some package to use the SesClient but none of them allows me to add metadata

I'm open to all kind of solutions, if you need more info just let me know and I will answer the questions

Thanks in advance

1

There are 1 best solutions below

0
On BEST ANSWER

TL;DR

There is not a way to do achieve this

Explanation

The long answer is you need to change the approach to the problem

Since the AWS Client class raise an exception on the magic method __sleep you can't directly send the class to a Laravel queue because part of the process to send it is serialize the class.

You extend the class and overwrite the method but this will bring you problems in the future due to a callbacks inside of the AWS Client class.

To solve this you need to extract the class out of the Laravel Job class, this can be done creating a class to wrap your process and inside of this class create an instance of the AWS Client