-
Notifications
You must be signed in to change notification settings - Fork 439
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
Convert between Message::$expire and DbalMessage::$timeToLive #396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ public function createTransportMessage(Message $message) | |
$transportMessage->setMessageId($message->getMessageId()); | ||
$transportMessage->setTimestamp($message->getTimestamp()); | ||
$transportMessage->setDeliveryDelay($message->getDelay()); | ||
$transportMessage->setTimeToLive($message->getExpire()); | ||
$transportMessage->setReplyTo($message->getReplyTo()); | ||
$transportMessage->setCorrelationId($message->getCorrelationId()); | ||
if (array_key_exists($message->getPriority(), self::$priorityMap)) { | ||
|
@@ -97,6 +98,8 @@ public function createClientMessage(PsrMessage $message) | |
$clientMessage->setContentType($message->getHeader('content_type')); | ||
$clientMessage->setMessageId($message->getMessageId()); | ||
$clientMessage->setTimestamp($message->getTimestamp()); | ||
$timeToLive = $message->getTimeToLive(); | ||
$clientMessage->setExpire((null === $timeToLive) ? null : (int) round($timeToLive)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
$clientMessage->setDelay($message->getDeliveryDelay()); | ||
$clientMessage->setReplyTo($message->getReplyTo()); | ||
$clientMessage->setCorrelationId($message->getCorrelationId()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,7 @@ public function testShouldConvertTransportMessageToClientMessage() | |
$transportMessage->setTimestamp(1000); | ||
$transportMessage->setPriority(2); | ||
$transportMessage->setDeliveryDelay(12345); | ||
$transportMessage->setTimeToLive(67890); | ||
|
||
$driver = new DbalDriver( | ||
$this->createPsrContextMock(), | ||
|
@@ -118,11 +119,29 @@ public function testShouldConvertTransportMessageToClientMessage() | |
$this->assertSame('ContentType', $clientMessage->getContentType()); | ||
$this->assertSame(1000, $clientMessage->getTimestamp()); | ||
$this->assertSame(12345, $clientMessage->getDelay()); | ||
|
||
$this->assertNull($clientMessage->getExpire()); | ||
$this->assertSame(67890, $clientMessage->getExpire()); | ||
$this->assertSame(MessagePriority::NORMAL, $clientMessage->getPriority()); | ||
} | ||
|
||
public function testShouldRoundTransportMessageTimeToLiveToNearestIntegerWhenConvertingToClientMessage() | ||
{ | ||
$driver = new DbalDriver( | ||
$this->createPsrContextMock(), | ||
$this->createDummyConfig(), | ||
$this->createDummyQueueMetaRegistry() | ||
); | ||
|
||
$transportMessage = new DbalMessage(); | ||
|
||
$transportMessage->setTimeToLive(1.4); | ||
$clientMessage = $driver->createClientMessage($transportMessage); | ||
$this->assertSame(1, $clientMessage->getExpire()); | ||
|
||
$transportMessage->setTimeToLive(1.5); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI. It is 1.5 milliseconds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did this because the $transportMessage value can be |
||
$clientMessage = $driver->createClientMessage($transportMessage); | ||
$this->assertSame(2, $clientMessage->getExpire()); | ||
} | ||
|
||
public function testShouldConvertClientMessageToTransportMessage() | ||
{ | ||
$clientMessage = new Message(); | ||
|
@@ -163,6 +182,7 @@ public function testShouldConvertClientMessageToTransportMessage() | |
$this->assertSame([ | ||
'key' => 'val', | ||
], $transportMessage->getProperties()); | ||
$this->assertSame(123, $transportMessage->getTimeToLive()); | ||
$this->assertSame('MessageId', $transportMessage->getMessageId()); | ||
$this->assertSame(1000, $transportMessage->getTimestamp()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
$message->getExpire() * 1000
as clients message uses seconds where transport uses miliseconds