mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-27 17:31:20 -06:00
Updated to latest common, with unified publishing API
This commit is contained in:
parent
233bb603cf
commit
791d6b7e57
@ -43,18 +43,17 @@
|
||||
"php-middleware/request-id": "^4.1",
|
||||
"pugx/shortid-php": "^1.0",
|
||||
"ramsey/uuid": "^4.2",
|
||||
"shlinkio/shlink-common": "dev-main#4019020 as 4.5",
|
||||
"shlinkio/shlink-common": "dev-main#b3848ad as 4.5",
|
||||
"shlinkio/shlink-config": "^1.6",
|
||||
"shlinkio/shlink-event-dispatcher": "^2.4",
|
||||
"shlinkio/shlink-importer": "^3.0",
|
||||
"shlinkio/shlink-installer": "dev-develop#f76e9aa as 7.2",
|
||||
"shlinkio/shlink-ip-geolocation": "^2.2",
|
||||
"symfony/console": "^6.0",
|
||||
"symfony/filesystem": "^6.0",
|
||||
"symfony/lock": "^6.0",
|
||||
"symfony/mercure": "^0.6",
|
||||
"symfony/process": "^6.0",
|
||||
"symfony/string": "^6.0"
|
||||
"symfony/console": "^6.1",
|
||||
"symfony/filesystem": "^6.1",
|
||||
"symfony/lock": "^6.1",
|
||||
"symfony/process": "^6.1",
|
||||
"symfony/string": "^6.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"cebe/php-openapi": "^1.7",
|
||||
@ -71,7 +70,7 @@
|
||||
"roave/security-advisories": "dev-master",
|
||||
"shlinkio/php-coding-standard": "~2.3.0",
|
||||
"shlinkio/shlink-test-utils": "^3.0.1",
|
||||
"symfony/var-dumper": "^6.0",
|
||||
"symfony/var-dumper": "^6.1",
|
||||
"veewee/composer-run-parallel": "^1.1"
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -6,8 +6,9 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\RabbitMq;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\Update;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlCreated;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Topic;
|
||||
@ -17,7 +18,7 @@ use Throwable;
|
||||
class NotifyNewShortUrlToRabbitMq
|
||||
{
|
||||
public function __construct(
|
||||
private readonly RabbitMqPublishingHelperInterface $rabbitMqHelper,
|
||||
private readonly PublishingHelperInterface $rabbitMqHelper,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly DataTransformerInterface $shortUrlTransformer,
|
||||
@ -43,10 +44,10 @@ class NotifyNewShortUrlToRabbitMq
|
||||
}
|
||||
|
||||
try {
|
||||
$this->rabbitMqHelper->publishPayloadInQueue(
|
||||
['shortUrl' => $this->shortUrlTransformer->transform($shortUrl)],
|
||||
$this->rabbitMqHelper->publishUpdate(Update::forTopicAndPayload(
|
||||
Topic::NEW_SHORT_URL->value,
|
||||
);
|
||||
['shortUrl' => $this->shortUrlTransformer->transform($shortUrl)],
|
||||
));
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->debug('Error while trying to notify RabbitMQ with new short URL. {e}', ['e' => $e]);
|
||||
}
|
||||
|
@ -6,8 +6,9 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\RabbitMq;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\Update;
|
||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Topic;
|
||||
@ -19,7 +20,7 @@ use function Functional\each;
|
||||
class NotifyVisitToRabbitMq
|
||||
{
|
||||
public function __construct(
|
||||
private readonly RabbitMqPublishingHelperInterface $rabbitMqHelper,
|
||||
private readonly PublishingHelperInterface $rabbitMqHelper,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly DataTransformerInterface $orphanVisitTransformer,
|
||||
@ -48,7 +49,9 @@ class NotifyVisitToRabbitMq
|
||||
$payload = $this->visitToPayload($visit);
|
||||
|
||||
try {
|
||||
each($queues, fn (string $queue) => $this->rabbitMqHelper->publishPayloadInQueue($payload, $queue));
|
||||
each($queues, fn (string $queue) => $this->rabbitMqHelper->publishUpdate(
|
||||
Update::forTopicAndPayload($queue, $payload),
|
||||
));
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->debug('Error while trying to notify RabbitMQ with new visit. {e}', ['e' => $e]);
|
||||
}
|
||||
|
@ -6,8 +6,9 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\RedisPubSub;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Shlinkio\Shlink\Common\Cache\RedisPublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\Update;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlCreated;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Topic;
|
||||
@ -16,7 +17,7 @@ use Throwable;
|
||||
class NotifyNewShortUrlToRedis
|
||||
{
|
||||
public function __construct(
|
||||
private readonly RedisPublishingHelperInterface $redisHelper,
|
||||
private readonly PublishingHelperInterface $redisHelper,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly DataTransformerInterface $shortUrlTransformer,
|
||||
@ -42,10 +43,10 @@ class NotifyNewShortUrlToRedis
|
||||
}
|
||||
|
||||
try {
|
||||
$this->redisHelper->publishPayloadInQueue(
|
||||
['shortUrl' => $this->shortUrlTransformer->transform($shortUrl)],
|
||||
$this->redisHelper->publishUpdate(Update::forTopicAndPayload(
|
||||
Topic::NEW_SHORT_URL->value,
|
||||
);
|
||||
['shortUrl' => $this->shortUrlTransformer->transform($shortUrl)],
|
||||
));
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->debug('Error while trying to notify Redis pub/sub with new short URL. {e}', ['e' => $e]);
|
||||
}
|
||||
|
@ -6,8 +6,9 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\RedisPubSub;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Shlinkio\Shlink\Common\Cache\RedisPublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\Update;
|
||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Topic;
|
||||
@ -18,7 +19,7 @@ use function Functional\each;
|
||||
class NotifyVisitToRedis
|
||||
{
|
||||
public function __construct(
|
||||
private readonly RedisPublishingHelperInterface $redisHelper,
|
||||
private readonly PublishingHelperInterface $redisHelper,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly DataTransformerInterface $orphanVisitTransformer,
|
||||
@ -48,7 +49,9 @@ class NotifyVisitToRedis
|
||||
$payload = $this->visitToPayload($visit);
|
||||
|
||||
try {
|
||||
each($queues, fn (string $queue) => $this->redisHelper->publishPayloadInQueue($payload, $queue));
|
||||
each($queues, fn (string $queue) => $this->redisHelper->publishUpdate(
|
||||
Update::forTopicAndPayload($queue, $payload),
|
||||
));
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->debug('Error while trying to notify Redis pub/sub with new visit. {e}', ['e' => $e]);
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\Update;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlCreated;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq;
|
||||
@ -35,7 +36,7 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->helper = $this->prophesize(RabbitMqPublishingHelperInterface::class);
|
||||
$this->helper = $this->prophesize(PublishingHelperInterface::class);
|
||||
$this->em = $this->prophesize(EntityManagerInterface::class);
|
||||
$this->logger = $this->prophesize(LoggerInterface::class);
|
||||
$this->options = new RabbitMqOptions(['enabled' => true]);
|
||||
@ -59,7 +60,7 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
|
||||
$this->em->find(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->logger->warning(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->logger->debug(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->helper->publishPayloadInQueue(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->helper->publishUpdate(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@ -77,7 +78,7 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
|
||||
$find->shouldHaveBeenCalledOnce();
|
||||
$logWarning->shouldHaveBeenCalledOnce();
|
||||
$this->logger->debug(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->helper->publishPayloadInQueue(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->helper->publishUpdate(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@ -89,9 +90,8 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
|
||||
($this->listener)(new ShortUrlCreated($shortUrlId));
|
||||
|
||||
$find->shouldHaveBeenCalledOnce();
|
||||
$this->helper->publishPayloadInQueue(
|
||||
Argument::type('array'),
|
||||
Topic::NEW_SHORT_URL->value,
|
||||
$this->helper->publishUpdate(
|
||||
Argument::that(fn (Update $update) => $update->topic === Topic::NEW_SHORT_URL->value),
|
||||
)->shouldHaveBeenCalledOnce();
|
||||
$this->logger->debug(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
@ -104,7 +104,7 @@ class NotifyNewShortUrlToRabbitMqTest extends TestCase
|
||||
{
|
||||
$shortUrlId = '123';
|
||||
$find = $this->em->find(ShortUrl::class, $shortUrlId)->willReturn(ShortUrl::withLongUrl(''));
|
||||
$publish = $this->helper->publishPayloadInQueue(Argument::cetera())->willThrow($e);
|
||||
$publish = $this->helper->publishUpdate(Argument::cetera())->willThrow($e);
|
||||
|
||||
($this->listener)(new ShortUrlCreated($shortUrlId));
|
||||
|
||||
|
@ -14,7 +14,8 @@ use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
|
||||
use Shlinkio\Shlink\Common\UpdatePublishing\Update;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated;
|
||||
@ -42,7 +43,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->helper = $this->prophesize(RabbitMqPublishingHelperInterface::class);
|
||||
$this->helper = $this->prophesize(PublishingHelperInterface::class);
|
||||
$this->em = $this->prophesize(EntityManagerInterface::class);
|
||||
$this->logger = $this->prophesize(LoggerInterface::class);
|
||||
$this->options = new RabbitMqOptions(['enabled' => true, 'legacy_visits_publishing' => true]);
|
||||
@ -67,7 +68,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
$this->em->find(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->logger->warning(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->logger->debug(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->helper->publishPayloadInQueue(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->helper->publishUpdate(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@ -85,7 +86,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
$findVisit->shouldHaveBeenCalledOnce();
|
||||
$logWarning->shouldHaveBeenCalledOnce();
|
||||
$this->logger->debug(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->helper->publishPayloadInQueue(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
$this->helper->publishUpdate(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,16 +98,15 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
$visitId = '123';
|
||||
$findVisit = $this->em->find(Visit::class, $visitId)->willReturn($visit);
|
||||
$argumentWithExpectedChannels = Argument::that(
|
||||
static fn (string $channel) => contains($expectedChannels, $channel),
|
||||
static fn (Update $update) => contains($expectedChannels, $update->topic),
|
||||
);
|
||||
|
||||
($this->listener)(new VisitLocated($visitId));
|
||||
|
||||
$findVisit->shouldHaveBeenCalledOnce();
|
||||
$this->helper->publishPayloadInQueue(
|
||||
Argument::type('array'),
|
||||
$argumentWithExpectedChannels,
|
||||
)->shouldHaveBeenCalledTimes(count($expectedChannels));
|
||||
$this->helper->publishUpdate($argumentWithExpectedChannels)->shouldHaveBeenCalledTimes(
|
||||
count($expectedChannels),
|
||||
);
|
||||
$this->logger->debug(Argument::cetera())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
{
|
||||
$visitId = '123';
|
||||
$findVisit = $this->em->find(Visit::class, $visitId)->willReturn(Visit::forBasePath(Visitor::emptyInstance()));
|
||||
$publish = $this->helper->publishPayloadInQueue(Argument::cetera())->willThrow($e);
|
||||
$publish = $this->helper->publishUpdate(Argument::cetera())->willThrow($e);
|
||||
|
||||
($this->listener)(new VisitLocated($visitId));
|
||||
|
||||
@ -171,7 +171,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
($this->listener)(new VisitLocated($visitId));
|
||||
|
||||
$findVisit->shouldHaveBeenCalledOnce();
|
||||
$this->helper->publishPayloadInQueue(Argument::that($assertPayload), Argument::type('string'))
|
||||
$this->helper->publishUpdate(Argument::that($assertPayload))
|
||||
->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
@ -180,7 +180,8 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
yield 'non-legacy non-orphan visit' => [
|
||||
true,
|
||||
$visit = Visit::forValidShortUrl(ShortUrl::withLongUrl(''), Visitor::emptyInstance()),
|
||||
function (array $payload) use ($visit): bool {
|
||||
function (Update $update) use ($visit): bool {
|
||||
$payload = $update->payload;
|
||||
Assert::assertEquals($payload, $visit->jsonSerialize());
|
||||
Assert::assertArrayNotHasKey('visitedUrl', $payload);
|
||||
Assert::assertArrayNotHasKey('type', $payload);
|
||||
@ -193,7 +194,8 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
yield 'non-legacy orphan visit' => [
|
||||
true,
|
||||
Visit::forBasePath(Visitor::emptyInstance()),
|
||||
function (array $payload): bool {
|
||||
function (Update $update): bool {
|
||||
$payload = $update->payload;
|
||||
Assert::assertArrayHasKey('visitedUrl', $payload);
|
||||
Assert::assertArrayHasKey('type', $payload);
|
||||
|
||||
@ -203,7 +205,8 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
yield 'legacy non-orphan visit' => [
|
||||
false,
|
||||
$visit = Visit::forValidShortUrl(ShortUrl::withLongUrl(''), Visitor::emptyInstance()),
|
||||
function (array $payload) use ($visit): bool {
|
||||
function (Update $update) use ($visit): bool {
|
||||
$payload = $update->payload;
|
||||
Assert::assertArrayHasKey('visit', $payload);
|
||||
Assert::assertArrayHasKey('shortUrl', $payload);
|
||||
Assert::assertIsArray($payload['visit']);
|
||||
@ -217,7 +220,8 @@ class NotifyVisitToRabbitMqTest extends TestCase
|
||||
yield 'legacy orphan visit' => [
|
||||
false,
|
||||
Visit::forBasePath(Visitor::emptyInstance()),
|
||||
function (array $payload): bool {
|
||||
function (Update $update): bool {
|
||||
$payload = $update->payload;
|
||||
Assert::assertArrayHasKey('visit', $payload);
|
||||
Assert::assertArrayNotHasKey('shortUrl', $payload);
|
||||
Assert::assertIsArray($payload['visit']);
|
||||
|
Loading…
Reference in New Issue
Block a user