Skip to content

Introduce message class resolver#310

Open
vjik wants to merge 1 commit into
masterfrom
message-class-resolver
Open

Introduce message class resolver#310
vjik wants to merge 1 commit into
masterfrom
message-class-resolver

Conversation

@vjik

@vjik vjik commented Jun 15, 2026

Copy link
Copy Markdown
Member
Q A
Is bugfix?
New feature? ✔️
Breaks BC? ✔️
Tests pass? ✔️
Fix #292

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (31c3cb5) to head (00c11c4).

Files with missing lines Patch % Lines
src/Message/Serializer/MessageSerializer.php 0.00% 5 Missing ⚠️
...essage/ClassResolver/ArrayMessageClassResolver.php 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             master    #310   +/-   ##
========================================
  Coverage      0.00%   0.00%           
+ Complexity      336     334    -2     
========================================
  Files            50      51    +1     
  Lines           920     918    -2     
========================================
+ Misses          920     918    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vjik vjik requested a review from a team June 15, 2026 14:14
@vjik vjik added the status:code review The pull request needs review. label Jun 15, 2026
Comment thread config/di.php
MessageClassResolverInterface::class => [
'class' => ArrayMessageClassResolver::class,
'__construct()' => [
'map' => $params['yiisoft/queue']['message-class-map'],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have just handlers, "messages" makes more sense:

Suggested change
'map' => $params['yiisoft/queue']['message-class-map'],
'map' => $params['yiisoft/queue']['messages'],

Comment thread config/params.php
'middlewares-push' => [],
'middlewares-consume' => [],
'middlewares-fail' => [],
'message-class-map' => [],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'message-class-map' => [],
'messages' => [],

I'd also move that as 1st array key so it will be message, handlers etc. The drawback here is that we repeat the same thing two times:

'messages' => [
    'process-pdf' => ProcessPdfMessage::class,
],
'handlers' => [
    'process-pdf' => ProcessPdfMessageHandler::class,
],

Could be possibly combined:

'messages' => [
    'process-pdf' => [ProcessPdfMessage::class, ProcessPdfMessageHandler::class],
],


- **Queue names** — configure queue/back-end per logical queue name via [`yiisoft/queue.queues` config](queue-names.md) when you need to parallelize message handling or send some of them to a different application.
- **Named handlers or callable definitions** — map a short message type to a callable in [`yiisoft/queue.handlers` config](message-handler-advanced.md) when another application is the message producer and you cannot use FQCN as message type.
- **Message class map** — map message types to specific message classes so that `unserialize()` reconstructs the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to use the full interface name, or else unserialize() will be confused with the native PHP function.

- **Queue names** — configure queue/back-end per logical queue name via [`yiisoft/queue.queues` config](queue-names.md) when you need to parallelize message handling or send some of them to a different application.
- **Named handlers or callable definitions** — map a short message type to a callable in [`yiisoft/queue.handlers` config](message-handler-advanced.md) when another application is the message producer and you cannot use FQCN as message type.
- **Message class map** — map message types to specific message classes so that `unserialize()` reconstructs the
original typed object instead of falling back to `GenericMessage`. Configure via `yiisoft/queue.message-class-map`:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
original typed object instead of falling back to `GenericMessage`. Configure via `yiisoft/queue.message-class-map`:
original typed object instead of falling back to `GenericMessage`. Configure via `yiisoft/queue.messages`:

```php
return [
'yiisoft/queue' => [
'message-class-map' => [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'message-class-map' => [
'messages' => [

/**
* Resolves message classes from a predefined map of type-to-class associations.
*/
final class ArrayMessageClassResolver implements MessageClassResolverInterface

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other implementations do you see?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid having PHP class in the message after serialization

2 participants