laravel-sqs-fifo-queue icon indicating copy to clipboard operation
laravel-sqs-fifo-queue copied to clipboard

Are Queued Event Listeners not fully supported?

Open ChristianChoi opened this issue 3 years ago • 2 comments

I have an event with one of its listeners implementing ShouldQueue with connection set to sqs-fifo like this:

class MyEventListener implements ShouldQueue
{
    public $connection = 'sqs-fifo';

    public function handle($event)
    {
        logger()->debug('queued event listener handled');
    }
}

This works fine. However, I don't seem to be able to specify the Message Group ID. I have tried the following:

  1. use SqsFifoQueueable;-trait and call $this->onMessageGroup('custom-group'); in the listener __construct()
  2. Specify $messageGroupId property manually: public $messageGroupId = 'custom-group';

Both messages sent to my SQS FIFO queue have default Message Group ID, not custom-group as I had hoped.

Am I missing something? Or is using Queued Event Listeners simply not supported (yet)?

ChristianChoi avatar Apr 13 '21 11:04 ChristianChoi

@ChristianChoi,

Unfortunately, queued event handlers are not supported (yet).

I took a look at Laravel's implementation, and the problem is that your listener isn't actually what is sent to the queue. Laravel creates an instance of the CallQueuedListener class and copies the queue settings defined on your listener onto that new class instance, and pushes that onto the queue. Since this is all built into Laravel, it doesn't know anything about the custom message group or deduplicator settings defined on your listener, so those settings don't get propagated to the job Laravel creates.

The only way I see to implement this currently would be for this package to extend and replace the Laravel event dispatcher. It's doable, but I'm wary of the package taking on that responsibility.

patrickcarlohickman avatar Apr 16 '21 00:04 patrickcarlohickman

I got to the same conclusion and understand the worry about extending Laravel's event dispatcher. However, it would be nice if your documentation would mention this one case is not yet supported, as it's a built-in Laravel feature.

For now, I will change my code to dispatch Jobs instead.

Thank you for a great package!

ChristianChoi avatar Apr 16 '21 05:04 ChristianChoi

The readme has been updated to mention that queued event listeners are not supported right now. I will make a comment on this issue if they ever are supported.

Thanks, Patrick

patrickcarlohickman avatar Mar 09 '23 07:03 patrickcarlohickman