dusterio / laravel-plain-sqs

Custom SQS connector for Laravel (or Lumen) that supports third-party, plain JSON messages
MIT License
131 stars 93 forks source link

Send Multiple different jobs to same QUEUE #14

Open narsariamanu opened 7 years ago

narsariamanu commented 7 years ago

I am using Lumen 5.4. I have multiple different jobs that I want to send to the same queue. In essence, I want to use the job part of the payload as well. Is there any way to do it.

dusterio commented 7 years ago

Of course you can - it's up to you :) You can save whatever you want in the SQS, as long as it fits in the maximum message size.

You just have to implement your own logic - how you choose what to do with the job/payload once you receive it somewhere

narsariamanu commented 7 years ago

@dusterio Every job that I am pushing is being handled by the default-handler and not by its respective handler. Am I missing something? Please help.

dusterio commented 7 years ago

Oh I see what you mean. Why don't you create some kind of intermediary class that fetches the payload, sees what's inside and then decides to which Job class to pass it?

What you are implementing is not really a plain SQS/JSON anymore because you want to have some important metadata in it. I'm not sure if it should be an optional part of this package or not (maybe it should)

cristiangrama commented 5 years ago

The handlers point to the queue name. Therefore you can only have one job per sqs queue.

The easiest option is to save a type in the payload and use a handler job. Then look at the type and using the factory pattern you can process the job the holds the logic for what you want by using regular Jobs and then dispatch them to be processed synchronously.

ejunker commented 5 years ago

The Dusterio\PlainSqs\Sqs\Queue::pop() method has code where it determines which Job class to use based on the config which maps queues to handlers. I think that could be extracted into a method like resolveClass($queue, $response). Then add a setter to allow the user to set their own class resolver method so that they have control over which job class to use. It would use the default class resolver method which uses the config unless it was overridden.

dusterio commented 5 years ago

@ejunker wanna make a PR? :)