New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.7] Add queue payload customization feature #23606
Conversation
* @param int $retryAfter | ||
* @param int|null $blockFor | ||
* @param \Illuminate\Contracts\Redis\Factory $redis | ||
* @param string $default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep 2 spaces in thr phpdoc for param annotations, like it was before, everywhere.
$this->redis = $redis; | ||
$this->default = $default; | ||
$this->blockFor = $blockFor; | ||
$this->redis = $redis; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't align these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style updated.
Honestly way to many changes. Something like this should be able to be accomplished easier. |
@taylorotwell I knew this would happen, faster than I expect.. 馃槯 I accept this, but how to accomplish this exactly? |
@GrahamCampbell Do you use PhpStorm? How to accomplish this?
|
FWIW I'd really love to see this implemented in some form or another. I did some research on the topic, seems like implementing |
Finally I'm not alone. 馃槃
You can serialize job to some really simple and readable JSON string (even protobuf), so other program language can process it, or you can unserialize it back, and return the essential attributes to Laravel like this: <?php
public function unserialize($raw, $connectionName, $queueName)
{
$parameters = json_decode($raw);
if ($connectionName === 'awesome' && $queueName === 'laravel') {
$jobClass = 'a';
} else {
$jobClass = 'b';
}
return [
'displayName' => 'My RabbitMQ Job',
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
'data' => [
'commandName' => $jobClass,
'command' => serialize(new $jobClass($parameters['product_id'])),
],
];
} Last serialize part is a little bit nasty, but I think we can figure it out, that's why I need some discussion. This PR is backward compatible, even the Redis queue that is using Lua. At last, if Taylor doesn't approve this PR, maybe these's no point to do it this way. 馃 |
Goal
Allow developer to customize payload of queue job.
Why
Developer using message queue to decouple logic into different services, some of these services may not be PHP application.
Here is how a Redis queue payload looks like:
Use NodeJS to generating this? No way.
To achieve communication between different languages, the only way is customizing payload (in an out) to a simpler JSON (or other format) without the overhead, like this:
Just let another adapter to translate this back to job handler (using payload, connection name and queue name, it's possible).
And that's what I did for my project (using RabbitMQ).
Changes
I added a
PayloadSerializer
interface to handle serialization that is hard-coded originally.Allow developer configure
PayloadSerializer
inconfig/queue.php
(Connection => PayloadSerializer).Backward compatible.
Discussion
This is a huge change, but maybe few developers are really need this feature.
What are you think about this? 馃槂