Skip to content

Commit

Permalink
Init repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Kubicki committed Oct 23, 2020
0 parents commit da67a59
Show file tree
Hide file tree
Showing 19 changed files with 808 additions and 0 deletions.
80 changes: 80 additions & 0 deletions Console/Command/FeedBufferCommand.php
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;
}
}
80 changes: 80 additions & 0 deletions Console/Command/FeedCommand.php
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;
}
}
88 changes: 88 additions & 0 deletions Console/Command/MassFeedCommand.php
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;
}
}
52 changes: 52 additions & 0 deletions Model/Data/Entity.php
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;
}
}
41 changes: 41 additions & 0 deletions Queue/Consumer/RetryConsumerHandler.php
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);
}
}
39 changes: 39 additions & 0 deletions Queue/ConsumerHandler/Entity/Cancellation.php
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();
}
}
}
Loading

0 comments on commit da67a59

Please sign in to comment.