-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Passing arguments for queues as expected #26966
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing arguments for queues as expected #26966
Conversation
Hi @bartoszkubicki. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
3362548
to
97a7874
Compare
97a7874
to
e91a3f1
Compare
Static tests seems to fail because of some copy-paste in EE. I have encountered this failure in multiple PR opened. |
@magento run all tests |
Hi @bartoszkubicki, From first looks changes looks good, but need to see the test results and analyze a bit deeper. |
(array) $binding['arguments'], | ||
(string) $connection | ||
); | ||
$this->mappedData += $queueItems; |
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.
Unfortunately it might be not an equal to the array_merge. Could you fix it as described here https://github.com/magento/magento-coding-standard/blob/develop/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.md?
@magento create issue |
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.
Hi @bartoszkubicki,
Thank you for your contribution!
Your changes looks good, but small adjustments are needed here. Could you review my comments and update your PR accordingly?
@@ -17,17 +21,17 @@ | |||
class DataMapperTest extends TestCase | |||
{ | |||
/** | |||
* @var MockObject | |||
* @var Data|MockObject | |||
*/ | |||
private $configData; |
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.
Could you add "Mock" suffix to all property names that contains mock object?
$queueItems = $this->createQueueItems($binding['destination'], $binding['topic'], $connection); | ||
$this->mappedData = array_merge($this->mappedData, $queueItems); | ||
$queueItems = $this->createQueueItems( | ||
(string) $binding['destination'], |
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.
- Could you remove the space between type casting and variable in all places in order to have similar code formatting as in other places in Magento, like this?
(string) $binding['destination'], | |
(string)$binding['destination'], |
- Do we really need this casting? Do we have any case where we'll have another type?
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.
Hello, @bartoszkubicki. Thank you for your contribution.
I've tried to reproduce the issue you've described on default Magento 2 2.4-develop branch without your fix. I've modified app/code/Magento/WebapiAsync/etc/queue_topology.xml to look like:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/topology.xsd">
<exchange name="magento" type="topic" connection="amqp">
<binding id="async.operations.all" topic="async.#" destinationType="queue" destination="async.operations.all">
<arguments>
<argument name="x-message-ttl" xsi:type="number">36000</argument>
</arguments>
</binding>
</exchange>
</config>
After that, I've checked the modified binding through RabbitMQ UI and found that argument has been applied:
Could you please confirm that issue is already fixed or provide some more detailed steps to reproduce?
Pull Request state was updated. Re-review required.
@engcom-Foxtrot I will check it. I don't remeber why this branch is set to be merged to 2.4-develop. It was problem for sure in magento 2.3 |
@engcom-Foxtrot Ok, I have checked it against 2.3 and 2.4. I can still reproduce an issue. The thing is, I was expecting to set these arguments on queue level, now I see it may work with this codebase on binding level.
Here we have different effect:
Here difference is also visible: I think our misunderstanding,in my opinion, is effect of highly inuintuitive queue declaration (#26969). They are normally declared explicitly (like in script above) and with use of Magento MQ Framework, they are "side effect" of declaring bindings. In other words queue don't have to exist when we create binding. If you can explain why all elements are not declared separately (exchange, queue) and later bound by binding I will be grateful. With fix arguments are applied both to queue and binding, which is also not perfect solution, but it is still somehow fixes the issue. From my tests, for now I assume that arguments on bindings level are not equal to bindings on queue level. I think it is still a bug, because if we would like to add some arguments on queue level - it is impossible. |
@bartekszymanski thank you for clarification, but it seems code still works incorrectly.
As I understand, you assume we should get 'x-dead-letter-exchange' argument set for both topic and queue. On bartoszkubicki:message-queue-arguments-passing-from-config branch, the topic is not created at all: |
@engcom-Foxtrot I can't locate from which place you have taken this config, but it is not about setting arguments for exchanges (it seems to be working), but for queues - so it is not relevant (as official rabbit mq docs says, in order to create working DLX fallback you have to add dlx to queue, not to another exchange, because message is sent to DLX after its expired, rejected and so on). From my tests on 2.4 you can set arguments for exchanges and bindings only. Arguments for queues are missing. I would like to have possibility to set arguments separately for queues and bindings. Basing on magento queues xmls construction, with this PR, I achieved setting queues arguments (with bindings arguments set, as a side effect). Normally (using php amq lib) you can set arguments for each component separately - exchange, queue, binding. |
@bartoszkubicki could you please provide some xml what would obviously confirm your PR is fixing the issue you described? |
@engcom-Foxtrot Me and my agency has created sample module that needs this fix - you can install it and test it or take configuration files. Without fix DLX exchanges are not configured properly. |
@engcom-Foxtrot could you review #26966 (comment) ? |
@bartoszkubicki thank you for clarification. |
QA passed. Steps:
to any queue_topology.xml file. |
Hi @bartoszkubicki, thank you for your contribution! |
Description (*)
According to docs it should be possible to declare queue with arguments (like dead-letter-exchange or message-ttl). Unfortunately during process of setting up rabbite schema, arguments are lost and queues are declared without any arguments.
It is because here arguements are always empty array. PR fixes this and also adds return type and some minor formatting fixes. If there are any tests for these class I will fix them as soon as bug will be reproduced, confirmed and my solution will be accepted.
If PR will be accepted, please port to 2.3 as well.
Manual testing scenarios (*)
queue_topology.xml
, like in dev docs.Questions or comments
Contribution checklist (*)
Resolved issues: