ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModuleMysqlMq\Model;
|
||||
|
||||
class DataObject extends \Magento\Framework\Api\AbstractExtensibleObject
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_get('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
return $this->setData('name', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getEntityId()
|
||||
{
|
||||
return $this->_get('entity_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $entityId
|
||||
* @return $this
|
||||
*/
|
||||
public function setEntityId($entityId)
|
||||
{
|
||||
return $this->setData('entity_id', $entityId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOutputPath()
|
||||
{
|
||||
return $this->_get('outputPath');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return $this
|
||||
*/
|
||||
public function setOutputPath($path)
|
||||
{
|
||||
return $this->setData('outputPath', $path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModuleMysqlMq\Model;
|
||||
|
||||
class DataObjectRepository
|
||||
{
|
||||
/**
|
||||
* @param DataObject $dataObject
|
||||
* @param string $requiredParam
|
||||
* @param int|null $optionalParam
|
||||
* @return null
|
||||
*/
|
||||
public function delayedOperation(
|
||||
\Magento\TestModuleMysqlMq\Model\DataObject $dataObject,
|
||||
$requiredParam,
|
||||
$optionalParam = null
|
||||
) {
|
||||
$output = "Processed '{$dataObject->getEntityId()}'; "
|
||||
. "Required param '{$requiredParam}'; Optional param '{$optionalParam}'\n";
|
||||
file_put_contents($dataObject->getOutputPath(), $output);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModuleMysqlMq\Model;
|
||||
|
||||
use LogicException;
|
||||
use Magento\Framework\MessageQueue\ConnectionLostException;
|
||||
|
||||
/**
|
||||
* Test message processor is used by \Magento\MysqlMq\Model\PublisherConsumerTest
|
||||
*/
|
||||
class Processor
|
||||
{
|
||||
/**
|
||||
* @param DataObject $message
|
||||
*/
|
||||
public function processMessage($message)
|
||||
{
|
||||
file_put_contents(
|
||||
$message->getOutputPath(),
|
||||
"Processed {$message->getEntityId()}" . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataObject $message
|
||||
*/
|
||||
public function processObjectCreated($message)
|
||||
{
|
||||
file_put_contents(
|
||||
$message->getOutputPath(),
|
||||
"Processed object created {$message->getEntityId()}" . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataObject $message
|
||||
*/
|
||||
public function processCustomObjectCreated($message)
|
||||
{
|
||||
file_put_contents(
|
||||
$message->getOutputPath(),
|
||||
"Processed custom object created {$message->getEntityId()}" . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataObject $message
|
||||
*/
|
||||
public function processObjectUpdated($message)
|
||||
{
|
||||
file_put_contents(
|
||||
$message->getOutputPath(),
|
||||
"Processed object updated {$message->getEntityId()}" . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataObject $message
|
||||
*/
|
||||
public function processMessageWithException($message)
|
||||
{
|
||||
file_put_contents($message->getOutputPath(), "Exception processing {$message->getEntityId()}");
|
||||
throw new LogicException(
|
||||
"Exception during message processing happened. Entity: {{$message->getEntityId()}}"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ConnectionLostException
|
||||
*/
|
||||
public function processMessageWithConnectionException()
|
||||
{
|
||||
throw new ConnectionLostException(
|
||||
"Connection exception during message processing happened."
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Communication/etc/communication.xsd">
|
||||
<topic name="demo.exception" request="Magento\TestModuleMysqlMq\Model\DataObject"/>
|
||||
<topic name="demo.connection.exception" request="Magento\TestModuleMysqlMq\Model\DataObject"/>
|
||||
<topic name="test.schema.defined.by.method" schema="Magento\TestModuleMysqlMq\Model\DataObjectRepository::delayedOperation" is_synchronous="false"/>
|
||||
<topic name="demo.object.created" request="Magento\TestModuleMysqlMq\Model\DataObject"/>
|
||||
<topic name="demo.object.updated" request="Magento\TestModuleMysqlMq\Model\DataObject"/>
|
||||
<topic name="demo.object.custom.created" request="Magento\TestModuleMysqlMq\Model\DataObject"/>
|
||||
</config>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
|
||||
<module name="Magento_TestModuleMysqlMq" active="true">
|
||||
</module>
|
||||
</config>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/queue.xsd">
|
||||
<broker topic="demo.exception" type="db" exchange="magento">
|
||||
<queue consumer="demoConsumerWithException" name="queue-exception" handler="Magento\TestModuleMysqlMq\Model\Processor::processMessageWithException"/>
|
||||
</broker>
|
||||
<broker topic="demo.connection.exception" type="db" exchange="magento">
|
||||
<queue consumer="demoConsumerWithConnectionException" name="queue-connection-exception" handler="Magento\TestModuleMysqlMq\Model\Processor::processMessageWithConnectionException"/>
|
||||
</broker>
|
||||
<broker topic="test.schema.defined.by.method" type="db" exchange="magento">
|
||||
<queue consumer="delayedOperationConsumer" name="demo-queue-6" handler="Magento\TestModuleMysqlMq\Model\DataObjectRepository::delayedOperation"/>
|
||||
</broker>
|
||||
<broker topic="demo.object.created" type="db" exchange="magento">
|
||||
<queue consumer="demoConsumerQueueOne" name="queue-created" handler="\Magento\TestModuleMysqlMq\Model\Processor::processObjectCreated"/>
|
||||
</broker>
|
||||
<broker topic="demo.object.updated" exchange="magento" type="db">
|
||||
<queue consumer="demoConsumerQueueTwo" name="queue-updated" handler="\Magento\TestModuleMysqlMq\Model\Processor::processObjectUpdated"/>
|
||||
</broker>
|
||||
<broker topic="demo.object.custom.created" exchange="magento" type="db">
|
||||
<queue consumer="demoConsumerQueueThree" name="queue-custom-created" handler="\Magento\TestModuleMysqlMq\Model\Processor::processCustomObjectCreated"/>
|
||||
</broker>
|
||||
</config>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/consumer.xsd">
|
||||
<consumer name="demoConsumerQueueOne" queue="queue-created" connection="db" handler="Magento\TestModuleMysqlMq\Model\Processor::processObjectCreated"/>
|
||||
<consumer name="demoConsumerQueueTwo" queue="queue-updated" connection="db" handler="Magento\TestModuleMysqlMq\Model\Processor::processObjectUpdated"/>
|
||||
<consumer name="demoConsumerQueueThree" queue="queue-custom-created" connection="db" handler="Magento\TestModuleMysqlMq\Model\Processor::processCustomObjectCreated"/>
|
||||
<consumer name="demoConsumerWithException" queue="queue-exception" connection="db" handler="Magento\TestModuleMysqlMq\Model\Processor::processMessageWithException"/>
|
||||
<consumer name="demoConsumerWithConnectionException" queue="queue-connection-exception" connection="db" handler="Magento\TestModuleMysqlMq\Model\Processor::processMessageWithConnectionException"/>
|
||||
<consumer name="delayedOperationConsumer" queue="demo-queue-6" connection="db" handler="Magento\TestModuleMysqlMq\Model\DataObjectRepository::delayedOperation"/>
|
||||
</config>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/publisher.xsd">
|
||||
<publisher topic="demo.exception">
|
||||
<connection name="db" exchange="magento"/>
|
||||
</publisher>
|
||||
<publisher topic="demo.connection.exception">
|
||||
<connection name="db" exchange="magento"/>
|
||||
</publisher>
|
||||
<publisher topic="test.schema.defined.by.method">
|
||||
<connection name="db" exchange="magento"/>
|
||||
</publisher>
|
||||
<publisher topic="demo.object.created">
|
||||
<connection name="db" exchange="magento"/>
|
||||
</publisher>
|
||||
<publisher topic="demo.object.updated">
|
||||
<connection name="db" exchange="magento"/>
|
||||
</publisher>
|
||||
<publisher topic="demo.object.custom.created">
|
||||
<connection name="db" exchange="magento"/>
|
||||
</publisher>
|
||||
</config>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
-->
|
||||
<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="db">
|
||||
<binding id="demo.exception.consumer" topic="demo.exception" destination="queue-exception" destinationType="queue"/>
|
||||
<binding id="demo.connection.exception.consumer" topic="demo.connection.exception" destination="queue-connection-exception" destinationType="queue"/>
|
||||
<binding id="test.schema.defined.by.method" topic="test.schema.defined.by.method" destination="demo-queue-6" destinationType="queue"/>
|
||||
<binding id="demo.object.created" topic="demo.object.created" destination="queue-created" destinationType="queue"/>
|
||||
<binding id="demo.object.updated" topic="demo.object.updated" destination="queue-updated" destinationType="queue"/>
|
||||
<binding id="demo.object.all" topic="demo.object.*" destination="queue-custom-created" destinationType="queue"/>
|
||||
</exchange>
|
||||
</config>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\Component\ComponentRegistrar;
|
||||
|
||||
$registrar = new ComponentRegistrar();
|
||||
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleMysqlMq') === null) {
|
||||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleMysqlMq', __DIR__);
|
||||
}
|
||||
Reference in New Issue
Block a user