Skip to content

[dbal] Use string-based UUIDs instead of binary #698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/dbal/DbalConsumerHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function fetchMessage(array $queues, int $redeliveryDelay): ?DbalMessa
->set('redeliver_after', ':redeliverAfter')
->andWhere('id = :messageId')
->andWhere('delivery_id IS NULL')
->setParameter('deliveryId', $deliveryId->getBytes(), Type::GUID)
->setParameter('deliveryId', $deliveryId, Type::GUID)
->setParameter('redeliverAfter', $now + $redeliveryDelay, Type::BIGINT)
;

Expand All @@ -68,7 +68,7 @@ protected function fetchMessage(array $queues, int $redeliveryDelay): ?DbalMessa
->select('*')
->from($this->getContext()->getTableName())
->andWhere('delivery_id = :deliveryId')
->setParameter('deliveryId', $deliveryId->getBytes(), Type::GUID)
->setParameter('deliveryId', $deliveryId, Type::GUID)
->setMaxResults(1)
->execute()
->fetch();
Expand Down Expand Up @@ -152,7 +152,7 @@ private function deleteMessage(string $deliveryId): void

$this->getConnection()->delete(
$this->getContext()->getTableName(),
['delivery_id' => Uuid::fromString($deliveryId)->getBytes()],
['delivery_id' => $deliveryId],
['delivery_id' => Type::GUID]
);
}
Expand Down
9 changes: 2 additions & 7 deletions pkg/dbal/DbalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
use Interop\Queue\Queue;
use Interop\Queue\SubscriptionConsumer;
use Interop\Queue\Topic;
use Ramsey\Uuid\Codec\OrderedTimeCodec;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;

class DbalContext implements Context
{
Expand Down Expand Up @@ -154,9 +151,7 @@ public function convertMessage(array $arrayMessage): DbalMessage
);

if (isset($arrayMessage['id'])) {
$uuidCodec = new OrderedTimeCodec((new UuidFactory())->getUuidBuilder());

$message->setMessageId($uuidCodec->decodeBytes($arrayMessage['id'])->toString());
$message->setMessageId($arrayMessage['id']);
}
if (isset($arrayMessage['queue'])) {
$message->setQueue($arrayMessage['queue']);
Expand All @@ -171,7 +166,7 @@ public function convertMessage(array $arrayMessage): DbalMessage
$message->setPublishedAt((int) $arrayMessage['published_at']);
}
if (isset($arrayMessage['delivery_id'])) {
$message->setDeliveryId(Uuid::fromBytes($arrayMessage['delivery_id'])->toString());
$message->setDeliveryId($arrayMessage['delivery_id']);
}
if (isset($arrayMessage['redeliver_after'])) {
$message->setRedeliverAfter((int) $arrayMessage['redeliver_after']);
Expand Down
11 changes: 1 addition & 10 deletions pkg/dbal/DbalProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
use Interop\Queue\Exception\InvalidMessageException;
use Interop\Queue\Message;
use Interop\Queue\Producer;
use Ramsey\Uuid\Codec\OrderedTimeCodec;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;

class DbalProducer implements Producer
{
Expand All @@ -37,18 +35,12 @@ class DbalProducer implements Producer
*/
private $context;

/**
* @var OrderedTimeCodec
*/
private $uuidCodec;

/**
* @param DbalContext $context
*/
public function __construct(DbalContext $context)
{
$this->context = $context;
$this->uuidCodec = new OrderedTimeCodec((new UuidFactory())->getUuidBuilder());
}

/**
Expand All @@ -71,15 +63,14 @@ public function send(Destination $destination, Message $message): void
}

$body = $message->getBody();
$uuid = Uuid::uuid4();

$publishedAt = null !== $message->getPublishedAt() ?
$message->getPublishedAt() :
(int) (microtime(true) * 10000)
;

$dbalMessage = [
'id' => $this->uuidCodec->encodeBinary($uuid),
'id' => Uuid::uuid4(),
'published_at' => $publishedAt,
'body' => $body,
'headers' => JSON::encode($message->getHeaders()),
Expand Down
4 changes: 2 additions & 2 deletions pkg/dbal/Tests/DbalConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testShouldDeleteMessageOnAcknowledge()
->method('delete')
->with(
'some-table-name',
['delivery_id' => $deliveryId->getBytes()],
['delivery_id' => $deliveryId->toString()],
['delivery_id' => Type::GUID]
)
;
Expand Down Expand Up @@ -141,7 +141,7 @@ public function testShouldDeleteMessageFromQueueOnReject()
->method('delete')
->with(
'some-table-name',
['delivery_id' => $deliveryId->getBytes()],
['delivery_id' => $deliveryId->toString()],
['delivery_id' => Type::GUID]
)
;
Expand Down