Skip to content

Commit da67a59

Browse files
author
Bartosz Kubicki
committed
Init repository
0 parents  commit da67a59

19 files changed

+808
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* File: MigrationCommand.php
7+
*
8+
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl>
9+
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl)
10+
*/
11+
12+
namespace LizardMedia\RabbitMqPlayground\Console\Command;
13+
14+
use LizardMedia\RabbitMqPlayground\Model\Data\Entity;
15+
use Magento\Framework\Console\Cli;
16+
use Magento\Framework\MessageQueue\PublisherInterface;
17+
use Symfony\Component\Console\Command\Command;
18+
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
21+
/**
22+
* Class MigrationCommand
23+
* @package LizardMedia\ReviewsDataMigration\Console\Command
24+
* @codeCoverageIgnore
25+
*/
26+
class FeedBufferCommand extends Command
27+
{
28+
/**
29+
* @var string
30+
*/
31+
private const TOPIC = 'entity.confirm';
32+
33+
/**
34+
* @var string
35+
*/
36+
private const COMMAND_NAME = 'feed:buffer';
37+
38+
/**
39+
* @var string
40+
*/
41+
private const COMMAND_DESC = 'Feed buffer';
42+
43+
/**
44+
* @var PublisherInterface
45+
*/
46+
private PublisherInterface $publisher;
47+
48+
/**
49+
* FeedBufferCommand constructor.
50+
* @param PublisherInterface $publisher
51+
* @param string|null $name
52+
*/
53+
public function __construct(PublisherInterface $publisher, string $name = null)
54+
{
55+
parent::__construct($name);
56+
$this->publisher = $publisher;
57+
}
58+
59+
/**
60+
* @return void
61+
*/
62+
protected function configure(): void
63+
{
64+
parent::configure();
65+
$this->setName(self::COMMAND_NAME)
66+
->setDescription(self::COMMAND_DESC);
67+
}
68+
69+
/**
70+
* @param InputInterface $input
71+
* @param OutputInterface $output
72+
* @return int
73+
*/
74+
protected function execute(InputInterface $input, OutputInterface $output): int
75+
{
76+
$entity = new Entity(rand(1, 100));
77+
$this->publisher->publish(self::TOPIC, $entity);
78+
return Cli::RETURN_SUCCESS;
79+
}
80+
}

Console/Command/FeedCommand.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* File: MigrationCommand.php
7+
*
8+
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl>
9+
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl)
10+
*/
11+
12+
namespace LizardMedia\RabbitMqPlayground\Console\Command;
13+
14+
use LizardMedia\RabbitMqPlayground\Model\Data\Entity;
15+
use Magento\Framework\Console\Cli;
16+
use Magento\Framework\MessageQueue\PublisherInterface;
17+
use Symfony\Component\Console\Command\Command;
18+
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
21+
/**
22+
* Class MigrationCommand
23+
* @package LizardMedia\ReviewsDataMigration\Console\Command
24+
* @codeCoverageIgnore
25+
*/
26+
class FeedCommand extends Command
27+
{
28+
/**
29+
* @var string
30+
*/
31+
private const TOPIC = 'entity.create';
32+
33+
/**
34+
* @var string
35+
*/
36+
private const COMMAND_NAME = 'feed';
37+
38+
/**
39+
* @var string
40+
*/
41+
private const COMMAND_DESC = 'Feed';
42+
43+
/**
44+
* @var PublisherInterface
45+
*/
46+
private PublisherInterface $publisher;
47+
48+
/**
49+
* FeedBufferCommand constructor.
50+
* @param PublisherInterface $publisher
51+
* @param string|null $name
52+
*/
53+
public function __construct(PublisherInterface $publisher, string $name = null)
54+
{
55+
parent::__construct($name);
56+
$this->publisher = $publisher;
57+
}
58+
59+
/**
60+
* @return void
61+
*/
62+
protected function configure(): void
63+
{
64+
parent::configure();
65+
$this->setName(self::COMMAND_NAME)
66+
->setDescription(self::COMMAND_DESC);
67+
}
68+
69+
/**
70+
* @param InputInterface $input
71+
* @param OutputInterface $output
72+
* @return int
73+
*/
74+
protected function execute(InputInterface $input, OutputInterface $output): int
75+
{
76+
$entity = new Entity(rand(1, 100));
77+
$this->publisher->publish(self::TOPIC, $entity);
78+
return Cli::RETURN_SUCCESS;
79+
}
80+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* File: MigrationCommand.php
7+
*
8+
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl>
9+
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl)
10+
*/
11+
12+
namespace LizardMedia\RabbitMqPlayground\Console\Command;
13+
14+
use LizardMedia\RabbitMqPlayground\Model\Data\Entity;
15+
use Magento\Framework\Console\Cli;
16+
use Magento\Framework\MessageQueue\PublisherInterface;
17+
use Symfony\Component\Console\Command\Command;
18+
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
21+
/**
22+
* Class MigrationCommand
23+
* @package LizardMedia\ReviewsDataMigration\Console\Command
24+
* @codeCoverageIgnore
25+
*/
26+
class MassFeedCommand extends Command
27+
{
28+
/**
29+
* @var string
30+
*/
31+
private const TOPIC_CREATE = 'entity.create';
32+
33+
/**
34+
* @var string
35+
*/
36+
private const TOPIC_CONFIRM = 'entity.confirm';
37+
38+
/**
39+
* @var string
40+
*/
41+
private const COMMAND_NAME = 'mass-feed';
42+
43+
/**
44+
* @var string
45+
*/
46+
private const COMMAND_DESC = 'Feed';
47+
48+
/**
49+
* @var PublisherInterface
50+
*/
51+
private PublisherInterface $publisher;
52+
53+
/**
54+
* FeedBufferCommand constructor.
55+
* @param PublisherInterface $publisher
56+
* @param string|null $name
57+
*/
58+
public function __construct(PublisherInterface $publisher, string $name = null)
59+
{
60+
parent::__construct($name);
61+
$this->publisher = $publisher;
62+
}
63+
64+
/**
65+
* @return void
66+
*/
67+
protected function configure(): void
68+
{
69+
parent::configure();
70+
$this->setName(self::COMMAND_NAME)
71+
->setDescription(self::COMMAND_DESC);
72+
}
73+
74+
/**
75+
* @param InputInterface $input
76+
* @param OutputInterface $output
77+
* @return int
78+
*/
79+
protected function execute(InputInterface $input, OutputInterface $output): int
80+
{
81+
for ($i = 0; $i <= 10000; $i++) {
82+
$entity = new Entity($i);
83+
$this->publisher->publish(self::TOPIC_CREATE, $entity);
84+
$this->publisher->publish(self::TOPIC_CONFIRM, $entity);
85+
}
86+
return Cli::RETURN_SUCCESS;
87+
}
88+
}

Model/Data/Entity.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* File: CommissionInterface.php
7+
*
8+
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl>
9+
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl)
10+
*/
11+
12+
namespace LizardMedia\RabbitMqPlayground\Model\Data;
13+
14+
/**
15+
* Class Entity
16+
* @package LizardMedia\Model\Data\RabbitMqPlayground
17+
* @codeCoverageIgnore
18+
*/
19+
class Entity
20+
{
21+
/**
22+
* @var int
23+
*/
24+
private int $id;
25+
26+
/**
27+
* Entity constructor.
28+
* @param int $id
29+
*/
30+
public function __construct(int $id)
31+
{
32+
$this->id = $id;
33+
}
34+
35+
/**
36+
* @return int
37+
*/
38+
public function getId(): int
39+
{
40+
return $this->id;
41+
}
42+
43+
/**
44+
* @param int $id
45+
* @return void
46+
* @SuppressWarnings(PHPMD.ShortVariable)
47+
*/
48+
public function setId(int $id): void
49+
{
50+
$this->id = $id;
51+
}
52+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* File: RetryConsumerHandler.php
7+
*
8+
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl>
9+
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl)
10+
*/
11+
12+
namespace LizardMedia\RabbitMqPlayground\Queue\Consumer;
13+
14+
use LizardMedia\MessageQueue\Api\Queue\Consumer\EnvelopeCallbackFactoryInterface;
15+
use LizardMedia\MessageQueue\Queue\Consumer\ConsumerWithInjectableEnvelopeCallback;
16+
use Magento\Framework\MessageQueue\CallbackInvokerInterface;
17+
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface as UsedConsumerConfig;
18+
19+
/**
20+
* Class RetryConsumerHandler
21+
* @package LizardMedia\RabbitMqPlayground\Queue\Consumer
22+
* @codeCoverageIgnore
23+
*/
24+
class RetryConsumerHandler extends ConsumerWithInjectableEnvelopeCallback
25+
{
26+
/**
27+
* RetryConsumerHandler constructor.
28+
* @param EnvelopeCallbackFactoryInterface $envelopeCallbackFactory
29+
* @param CallbackInvokerInterface $invoker
30+
* @param UsedConsumerConfig $configuration
31+
* @param string $envelopeCallbackType
32+
*/
33+
public function __construct(
34+
EnvelopeCallbackFactoryInterface $envelopeCallbackFactory,
35+
CallbackInvokerInterface $invoker,
36+
UsedConsumerConfig $configuration,
37+
string $envelopeCallbackType
38+
) {
39+
parent::__construct($envelopeCallbackFactory, $invoker, $configuration, $envelopeCallbackType);
40+
}
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* File: Creation.php
7+
*
8+
* @author Bartosz Kubicki bartosz.kubicki@lizardmedia.pl>
9+
* @copyright Copyright (C) 2020 Lizard Media (http://lizardmedia.pl)
10+
*/
11+
12+
namespace LizardMedia\RabbitMqPlayground\Queue\ConsumerHandler\Entity;
13+
14+
use LizardMedia\RabbitMqPlayground\Model\Data\Entity;
15+
use RuntimeException;
16+
17+
/**
18+
* Class Creation
19+
* @package LizardMedia\RabbitMqPlayground\Queue\ConsumerHandler\Entity
20+
* @codeCoverageIgnore
21+
*/
22+
class Cancellation
23+
{
24+
/**
25+
* @param Entity $entity
26+
* @return void
27+
*/
28+
public function execute(Entity $entity): void
29+
{
30+
$id = $entity->getId();
31+
sleep(10);
32+
if ($id > 50) {
33+
echo $entity->getId(), "\n";
34+
} else {
35+
echo $entity->getId(), "\n", 'Error cancellation...', "\n";
36+
throw new RuntimeException();
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)