2 years ago
#30546
mankowitz
Rate limiting queued mail in Laravel 8
I am attempting to use rate limiting to throttle outgoing mail in a laravel 8 project. I have two mail queues, named email
and email2
. I want each queue to limit to 15 emails per minute.
In my AppServiceProvider.php, I have
RateLimiter::for('email', function ($job) {
return Limit::perMinute(15)->by($job->queue);
});
This is one of my mailables
class AuthTokenMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public function __construct(int $code)
{
$this->onQueue('email');
}
public function build()
{
return $this->text('emails.authtoken');
}
public function middleware()
{
return [new RateLimited('email')];
}
}
But when I run it, there is no throttling. I am still getting >50 emails per minute.
laravel
laravel-8
rate-limiting
0 Answers
Your Answer