Refactor handlers
| Q | A |
|---|---|
| Is bugfix? | ❌ |
| New feature? | ❌ |
| Breaks BC? | ✔️ |
Drop support pre-configured handlers, make it compatible with validator/hydrator handlers way
The old way:
- Add
handler name=>handler definitionmapping to config/params - Add
handler nameto the messagegetHandlerNamemethod
The new way:
- Create a class that implements the new
MessageHandlerInterface - Add the class name to the message
getHandlermethod
The new way is similar with validator's or hydrator's way.
PR Summary
- Refactoring Message Handling
- The PR changes the terminology from
handlerNametohandlerin different classes and files for consistency. It affects the classes:Message,Queue,TestMiddleware, and various test files. This also includes renaming the methodgetHandlerNamemethod togetHandlerin theMessageInterfaceinterface.
- The PR changes the terminology from
- Alteration in
FileDownloaderandWorkerClasses- The
handlemethod in theFileDownloaderclass will now output aMessageInterfaceobject. Also, the same method in theWorkerclass will now throw aRuntimeExceptionif the handler name is not found, increasing error handling.
- The
- Removing
handlersProperty andQueueWorkerClass- The
handlersproperty has been removed from theWorkerclass constructor, and theQueueWorkerclass has been removed fromdi.phpfile, simplifying the structure.
- The
- Addition of
MessageHandlerInterfaceInterface- A new
MessageHandlerInterfaceinterface was added, which is implemented by theFakeHandlerclass, promoting code reusability and abstraction.
- A new
- Modification in
MessageConsumingTestandMiddlewareTestClassesMessageConsumingTestandMiddlewareTestnow use different classes as the handler for messages (StackMessageHandlerandNullMessageHandlerrespectively), which promotes diverse handling processes.
- Adding New Classes
- Three new classes:
ExceptionMessageHandler,NullMessageHandler, andStackMessageHandlerwere added, enhancing the system's capabilities to handle diverse message types.
- Three new classes:
- Removal of
getMessageHandlersMethod- The
getMessageHandlersmethod was removed fromTestCaseclass, reducing redundancy in the codebase.
- The
- Additional Changes in Multiple Test Methods
- Several test methods in files like
MiddlewareDispatcherTest.php,QueueTest.php,SynchronousAdapterTest.php, andWorkerTest.phpwere modified, promoting better and diverse testing with modified handler values.
- Several test methods in files like
Minor changes and adjustments were made throughout the codebase to align with these changes. Please ask if further clarification is needed.
Codecov Report
Attention: 12 lines in your changes are missing coverage. Please review.
Comparison is base (
5339df8) 83.98% compared to head (725ef84) 83.15%.
| Files | Patch % | Lines |
|---|---|---|
| src/Worker/Worker.php | 36.36% | 7 Missing :warning: |
| config/di.php | 0.00% | 5 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #182 +/- ##
============================================
- Coverage 83.98% 83.15% -0.84%
+ Complexity 359 345 -14
============================================
Files 46 46
Lines 1049 1021 -28
============================================
- Hits 881 849 -32
- Misses 168 172 +4
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
The idea was that handler is not a PHP class string because worker could be implemented in non-PHP.
Already discussed in the internal chat.
There're should be routing outside a message to be able to work with different services across the one queue.
With queue backends such as Redis, there's no external routing.
Discussed internally. It makes sense if we'll introduce "message type decorator" and "message-based handlers" for messages in a separate PR.