Connecting different Yii2 apps to the same queue
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.1k
- Forks
- 285
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 2
Description
What steps will reproduce the problem?
On the producer:
'queue' => [
'class' => \yii\queue\db\Queue::class,
'mutex' => \yii\mutex\PgsqlMutex::class,
'strictJobType' => false,
'serializer' => \yii\queue\serializers\JsonSerializer::class,
],
On the consumer:
'queue' => [
'class' => \yii\queue\db\Queue::class,
'mutex' => \yii\mutex\PgsqlMutex::class,
'strictJobType' => false,
'serializer' => \yii\queue\serializers\JsonSerializer::class,
'on beforeExec' => function ($ev) {
print_r($ev);
$ev->handled = true;
},
],
Then, in the producer:
\Yii::$app->queue->push(['foobar' => 12345]);
What's expected?
Unserialized job data easily accessible somehow to the consumer.
What do you get instead?
Impossible to get direct access to the unserialized job data.
Looking into unserializeMessage() (see below) we see that the unserialized job is returned only if it is a JobInterface object, which obviously it is not (i.e. it is a PHP array just unserialized from a JSON string).
The only way I could manage to access the data is to get the (serialized) JSON string using $ev->error->getSerialized(), and then decode it. That does not look right to me.
Not sure of it is a bug, or design decision. However, this issue makes it very difficult to (ironically) two Yii2 apps that do not share the same codebase to communicate.
Additional info
- As you can see from the examples, I am using Postgres+DB driver, but I guess this an issue common to all drivers.
| Q | A |
|---|---|
| Yii version | 2.0.20 |
| PHP version | 7.3 |
| Operating system | Debian (stretch) |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/Queue.php around unserializeMessage(), using the linked lines and the producer and consumer configurations in the issue. Reproduce the DB queue flow with the JSON serializer and inspect the beforeExec event. Done means the consumer can access the unserialized array directly when the producer and consumer do not share job classes, with behavior covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, postgresql
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100