Skip to content

Commit b704695

Browse files
committed
[stomp] Fix timeout issue. Use milliseconds.
1 parent 7ce2d18 commit b704695

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

‎pkg/stomp/BufferedStompClient.php‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Enqueue\Stomp;
44

55
use Stomp\Client;
6+
use Stomp\Transport\Frame;
67

78
class BufferedStompClient extends Client
89
{
@@ -47,12 +48,9 @@ public function getBufferSize()
4748
}
4849

4950
/**
50-
* @param string $subscriptionId
51-
* @param int|float $timeout
52-
*
53-
* @return \Stomp\Transport\Frame
51+
* Timeout is in milliseconds.
5452
*/
55-
public function readMessageFrame($subscriptionId, $timeout)
53+
public function readMessageFrame(string $subscriptionId, int $timeout): ?Frame
5654
{
5755
// pop up frame from the buffer
5856
if (isset($this->buffer[$subscriptionId]) && ($frame = array_shift($this->buffer[$subscriptionId]))) {
@@ -63,18 +61,18 @@ public function readMessageFrame($subscriptionId, $timeout)
6361

6462
// do nothing when buffer is full
6563
if ($this->currentBufferSize >= $this->bufferSize) {
66-
return;
64+
return null;
6765
}
6866

6967
$startTime = microtime(true);
70-
$remainingTimeout = $timeout * 1000000;
68+
$remainingTimeout = $timeout * 1000;
7169

7270
while (true) {
7371
$this->getConnection()->setReadTimeout(0, $remainingTimeout);
7472

7573
// there is nothing to read
7674
if (false === $frame = $this->readFrame()) {
77-
return;
75+
return null;
7876
}
7977

8078
if ('MESSAGE' !== $frame->getCommand()) {
@@ -95,7 +93,7 @@ public function readMessageFrame($subscriptionId, $timeout)
9593
$remainingTimeout -= (microtime(true) - $startTime) * 1000000;
9694

9795
if ($remainingTimeout <= 0) {
98-
return;
96+
return null;
9997
}
10098

10199
continue;

0 commit comments

Comments
 (0)