-
Notifications
You must be signed in to change notification settings - Fork 17
Add support for topic schema defined as ServiceName:methodName #23
Conversation
Vasiliev.A seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
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 explain the purpose of the task, not clear from the PR description.
use Magento\AsynchronousOperations\Model\ConfigInterface; | ||
use Magento\Framework\Communication\ConfigInterface as CommunicationConfig; | ||
|
||
class CompositeReader |
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 add class documentation
class CompositeReader | ||
{ | ||
/** | ||
* Topics with type schema is always are sync |
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.
Description does not sound right, please correct
@anvasiliev the problem described in bug was more related to the fact that in While it is not supported here https://github.com/magento/bulk-api-ce/blob/2.3-develop/app/code/Magento/AsynchronousOperations/Model/MassConsumer.php#L109 Also, I don't think we need a plugin to convert topic to asynchronous, because all topics generated with But in case if somebody uses MassConsumer to process some other queue defined manually throughthe communication.xml, the support of TOPIC_REQUEST_TYPE_METHOD will be important |
…E_METHOD, added new attribute is_synchronous for topic to communication.xsd schema
latest 2.1 develop
@@ -143,7 +144,7 @@ protected function extractTopics($config) | |||
} elseif ($requestSchema) { | |||
$output[$topicName] = [ | |||
Config::TOPIC_NAME => $topicName, | |||
Config::TOPIC_IS_SYNCHRONOUS => false, | |||
Config::TOPIC_IS_SYNCHRONOUS => $isSynchronous ?? false, |
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.
How can this request be synchronous? Please provide an example.
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.
Request will be synchronous in next etc/communication.xml configs:
- Topic attributes "request" and "response" are both defined, attribute "is_synchronous" not defined or "true".
<topic name="example.sync.topic" request="Magento\Example\Api\Data\EntityInterface" response="Magento\Example\Api\Data\EntityInterface"> <handler name="handler" type="Magento\Example\Api\EntityRepositoryInterface" method="save"/> </topic>
- Topic attribute "schema" defined and attribute "is_synchronous" not defined or "true"
<topic name="example.sync.topic" schema="Magento\Example\Api\EntityRepositoryInterface::save"> <handler name="handler" type="Magento\Example\Api\EntityRepositoryInterface" method="save"/> </topic>
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.
@anvasiliev, seems there is a bug in the implementation. If is_synchronous
is missed then extractTopicIsSynchronous
return null
which is treated as false. To avoid such issue better always return boolean from extractTopicIsSynchronous
.
Also, I suppose, @paliarush question was about what is the reason to support asynchrony for topics that only send data and don't expect any response. Looks like for the last elseif ($requestSchema)
we should always have Config::TOPIC_IS_SYNCHRONOUS => false
regardless attribute value.
Config::TOPIC_REQUEST => $methodMetadata[Config::SCHEMA_METHOD_PARAMS], | ||
Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_METHOD, | ||
Config::TOPIC_RESPONSE => $returnType, | ||
Config::TOPIC_HANDLERS => $handlers | ||
?: [self::DEFAULT_HANDLER => $methodMetadata[Config::SCHEMA_METHOD_HANDLER]] | ||
? : [self::DEFAULT_HANDLER => $methodMetadata[Config::SCHEMA_METHOD_HANDLER]] |
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.
I believe this is an accidental change.
]; | ||
} | ||
|
||
/** | ||
* Generate topic name based on service type and method name. | ||
* | ||
* Perform the following conversion: |
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.
There should be an empty line between short and long descriptions.
$serviceType, | ||
$serviceMethod, | ||
$handlers = [], | ||
$isSynchronous = null |
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.
Is this already used anywhere?
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.
was not used anywhere. Fixed in last commit
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 address comments above and cover with tests.
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 review comments and failed integration tests
* @param \DOMNode $topicNode | ||
* @return boolean|null | ||
*/ | ||
protected function extractTopicIsSynchronous($topicNode) |
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.
As this is new method it should be private
$attributeName = Config::TOPIC_IS_SYNCHRONOUS; | ||
$topicAttributes = $topicNode->attributes; | ||
if (!$topicAttributes->getNamedItem($attributeName)) { | ||
return null; |
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 avoid methods with multiple return types. If some value should be applied by default this is the best place to define it. With this PHP return type declaration should be used for new code
private function extractTopicIsSynchronous($topicNode): bool
return null; | ||
} | ||
$value = $topicAttributes->getNamedItem($attributeName)->nodeValue; | ||
$isSynchronous = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); |
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.
If XML file contains inappropriate value it should lead to an exception. Ideally, such case should be avoided by providing corresponding restrictions in XSD file.
@@ -143,7 +144,7 @@ protected function extractTopics($config) | |||
} elseif ($requestSchema) { | |||
$output[$topicName] = [ | |||
Config::TOPIC_NAME => $topicName, | |||
Config::TOPIC_IS_SYNCHRONOUS => false, | |||
Config::TOPIC_IS_SYNCHRONOUS => $isSynchronous ?? false, |
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.
@anvasiliev, seems there is a bug in the implementation. If is_synchronous
is missed then extractTopicIsSynchronous
return null
which is treated as false. To avoid such issue better always return boolean from extractTopicIsSynchronous
.
Also, I suppose, @paliarush question was about what is the reason to support asynchrony for topics that only send data and don't expect any response. Looks like for the last elseif ($requestSchema)
we should always have Config::TOPIC_IS_SYNCHRONOUS => false
regardless attribute value.
Code looks good. PR will be merged if manual QA doesn't discover bugs. |
Hi @anvasiliev, thank you for your contribution! |
Topics which configured as schema="ServiceName:methodName" always are synchronous topic type (see \Magento\Framework\Communication\Config\ReflectionGenerator::generateTopicConfigForServiceMethod ) and is not possible to use with \Magento\AsynchronousOperations\Model\MassConsumer
PR added new optional attribute "is_synchronous" in to urn:magento:framework:Communication/etc/communication.xsd which identify is topic are sync or async.
If topic attribute not defined or attribute value "true": topic are sync.
In case when topic attribute value "false": topic are async type, even if schema attribute or request+response attributes defined.
Example config:
communication.xml
queue_topology.xml
queue_consumer.xml