Integrated PublishUpdatesGenerator in NotifyNewShortUrlToRabbitMq listener

This commit is contained in:
Alejandro Celaya
2022-07-27 10:18:28 +02:00
parent 7e8109caa3
commit 3c042c4011
3 changed files with 14 additions and 15 deletions

View File

@@ -6,12 +6,10 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\RabbitMq;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
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;
use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface;
use Shlinkio\Shlink\Core\Options\RabbitMqOptions;
use Throwable;
@@ -19,9 +17,9 @@ class NotifyNewShortUrlToRabbitMq
{
public function __construct(
private readonly PublishingHelperInterface $rabbitMqHelper,
private readonly PublishingUpdatesGeneratorInterface $updatesGenerator,
private readonly EntityManagerInterface $em,
private readonly LoggerInterface $logger,
private readonly DataTransformerInterface $shortUrlTransformer,
private readonly RabbitMqOptions $options,
) {
}
@@ -44,10 +42,7 @@ class NotifyNewShortUrlToRabbitMq
}
try {
$this->rabbitMqHelper->publishUpdate(Update::forTopicAndPayload(
Topic::NEW_SHORT_URL->value,
['shortUrl' => $this->shortUrlTransformer->transform($shortUrl)],
));
$this->rabbitMqHelper->publishUpdate($this->updatesGenerator->newShortUrlUpdate($shortUrl));
} catch (Throwable $e) {
$this->logger->debug('Error while trying to notify RabbitMQ with new short URL. {e}', ['e' => $e]);
}