-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bartosz Kubicki
committed
Oct 23, 2020
0 parents
commit da67a59
Showing
19 changed files
with
808 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* File: MigrationCommand.php | ||
* | ||
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl> | ||
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl) | ||
*/ | ||
|
||
namespace LizardMedia\RabbitMqPlayground\Console\Command; | ||
|
||
use LizardMedia\RabbitMqPlayground\Model\Data\Entity; | ||
use Magento\Framework\Console\Cli; | ||
use Magento\Framework\MessageQueue\PublisherInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class MigrationCommand | ||
* @package LizardMedia\ReviewsDataMigration\Console\Command | ||
* @codeCoverageIgnore | ||
*/ | ||
class FeedBufferCommand extends Command | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const TOPIC = 'entity.confirm'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const COMMAND_NAME = 'feed:buffer'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const COMMAND_DESC = 'Feed buffer'; | ||
|
||
/** | ||
* @var PublisherInterface | ||
*/ | ||
private PublisherInterface $publisher; | ||
|
||
/** | ||
* FeedBufferCommand constructor. | ||
* @param PublisherInterface $publisher | ||
* @param string|null $name | ||
*/ | ||
public function __construct(PublisherInterface $publisher, string $name = null) | ||
{ | ||
parent::__construct($name); | ||
$this->publisher = $publisher; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function configure(): void | ||
{ | ||
parent::configure(); | ||
$this->setName(self::COMMAND_NAME) | ||
->setDescription(self::COMMAND_DESC); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$entity = new Entity(rand(1, 100)); | ||
$this->publisher->publish(self::TOPIC, $entity); | ||
return Cli::RETURN_SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* File: MigrationCommand.php | ||
* | ||
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl> | ||
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl) | ||
*/ | ||
|
||
namespace LizardMedia\RabbitMqPlayground\Console\Command; | ||
|
||
use LizardMedia\RabbitMqPlayground\Model\Data\Entity; | ||
use Magento\Framework\Console\Cli; | ||
use Magento\Framework\MessageQueue\PublisherInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class MigrationCommand | ||
* @package LizardMedia\ReviewsDataMigration\Console\Command | ||
* @codeCoverageIgnore | ||
*/ | ||
class FeedCommand extends Command | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const TOPIC = 'entity.create'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const COMMAND_NAME = 'feed'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const COMMAND_DESC = 'Feed'; | ||
|
||
/** | ||
* @var PublisherInterface | ||
*/ | ||
private PublisherInterface $publisher; | ||
|
||
/** | ||
* FeedBufferCommand constructor. | ||
* @param PublisherInterface $publisher | ||
* @param string|null $name | ||
*/ | ||
public function __construct(PublisherInterface $publisher, string $name = null) | ||
{ | ||
parent::__construct($name); | ||
$this->publisher = $publisher; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function configure(): void | ||
{ | ||
parent::configure(); | ||
$this->setName(self::COMMAND_NAME) | ||
->setDescription(self::COMMAND_DESC); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$entity = new Entity(rand(1, 100)); | ||
$this->publisher->publish(self::TOPIC, $entity); | ||
return Cli::RETURN_SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* File: MigrationCommand.php | ||
* | ||
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl> | ||
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl) | ||
*/ | ||
|
||
namespace LizardMedia\RabbitMqPlayground\Console\Command; | ||
|
||
use LizardMedia\RabbitMqPlayground\Model\Data\Entity; | ||
use Magento\Framework\Console\Cli; | ||
use Magento\Framework\MessageQueue\PublisherInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class MigrationCommand | ||
* @package LizardMedia\ReviewsDataMigration\Console\Command | ||
* @codeCoverageIgnore | ||
*/ | ||
class MassFeedCommand extends Command | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private const TOPIC_CREATE = 'entity.create'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const TOPIC_CONFIRM = 'entity.confirm'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const COMMAND_NAME = 'mass-feed'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private const COMMAND_DESC = 'Feed'; | ||
|
||
/** | ||
* @var PublisherInterface | ||
*/ | ||
private PublisherInterface $publisher; | ||
|
||
/** | ||
* FeedBufferCommand constructor. | ||
* @param PublisherInterface $publisher | ||
* @param string|null $name | ||
*/ | ||
public function __construct(PublisherInterface $publisher, string $name = null) | ||
{ | ||
parent::__construct($name); | ||
$this->publisher = $publisher; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function configure(): void | ||
{ | ||
parent::configure(); | ||
$this->setName(self::COMMAND_NAME) | ||
->setDescription(self::COMMAND_DESC); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
for ($i = 0; $i <= 10000; $i++) { | ||
$entity = new Entity($i); | ||
$this->publisher->publish(self::TOPIC_CREATE, $entity); | ||
$this->publisher->publish(self::TOPIC_CONFIRM, $entity); | ||
} | ||
return Cli::RETURN_SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* File: CommissionInterface.php | ||
* | ||
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl> | ||
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl) | ||
*/ | ||
|
||
namespace LizardMedia\RabbitMqPlayground\Model\Data; | ||
|
||
/** | ||
* Class Entity | ||
* @package LizardMedia\Model\Data\RabbitMqPlayground | ||
* @codeCoverageIgnore | ||
*/ | ||
class Entity | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private int $id; | ||
|
||
/** | ||
* Entity constructor. | ||
* @param int $id | ||
*/ | ||
public function __construct(int $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* @return void | ||
* @SuppressWarnings(PHPMD.ShortVariable) | ||
*/ | ||
public function setId(int $id): void | ||
{ | ||
$this->id = $id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* File: RetryConsumerHandler.php | ||
* | ||
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl> | ||
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl) | ||
*/ | ||
|
||
namespace LizardMedia\RabbitMqPlayground\Queue\Consumer; | ||
|
||
use LizardMedia\MessageQueue\Api\Queue\Consumer\EnvelopeCallbackFactoryInterface; | ||
use LizardMedia\MessageQueue\Queue\Consumer\ConsumerWithInjectableEnvelopeCallback; | ||
use Magento\Framework\MessageQueue\CallbackInvokerInterface; | ||
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface as UsedConsumerConfig; | ||
|
||
/** | ||
* Class RetryConsumerHandler | ||
* @package LizardMedia\RabbitMqPlayground\Queue\Consumer | ||
* @codeCoverageIgnore | ||
*/ | ||
class RetryConsumerHandler extends ConsumerWithInjectableEnvelopeCallback | ||
{ | ||
/** | ||
* RetryConsumerHandler constructor. | ||
* @param EnvelopeCallbackFactoryInterface $envelopeCallbackFactory | ||
* @param CallbackInvokerInterface $invoker | ||
* @param UsedConsumerConfig $configuration | ||
* @param string $envelopeCallbackType | ||
*/ | ||
public function __construct( | ||
EnvelopeCallbackFactoryInterface $envelopeCallbackFactory, | ||
CallbackInvokerInterface $invoker, | ||
UsedConsumerConfig $configuration, | ||
string $envelopeCallbackType | ||
) { | ||
parent::__construct($envelopeCallbackFactory, $invoker, $configuration, $envelopeCallbackType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* File: Creation.php | ||
* | ||
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl> | ||
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl) | ||
*/ | ||
|
||
namespace LizardMedia\RabbitMqPlayground\Queue\ConsumerHandler\Entity; | ||
|
||
use LizardMedia\RabbitMqPlayground\Model\Data\Entity; | ||
use RuntimeException; | ||
|
||
/** | ||
* Class Creation | ||
* @package LizardMedia\RabbitMqPlayground\Queue\ConsumerHandler\Entity | ||
* @codeCoverageIgnore | ||
*/ | ||
class Cancellation | ||
{ | ||
/** | ||
* @param Entity $entity | ||
* @return void | ||
*/ | ||
public function execute(Entity $entity): void | ||
{ | ||
$id = $entity->getId(); | ||
sleep(10); | ||
if ($id > 50) { | ||
echo $entity->getId(), "\n"; | ||
} else { | ||
echo $entity->getId(), "\n", 'Error cancellation...', "\n"; | ||
throw new RuntimeException(); | ||
} | ||
} | ||
} |
Oops, something went wrong.