Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit eefde95

Browse files
committed
Fix timeouts by waiting for only one message
1 parent 6459b6b commit eefde95

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

examples/simpleclient/main.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
require_once __DIR__.'/../../vendor/autoload.php';
3+
4+
use Nats\Connection as NatsClient;
5+
6+
$client = new NatsClient();
7+
$client->connect();
8+
9+
printf("Connected to NATS." . PHP_EOL);
10+
11+
// Publish Subscribe.
12+
13+
// Simple Subscriber.
14+
$client->subscribe(
15+
'foo',
16+
function ($message) {
17+
printf("Data: %s\r\n" . PHP_EOL, $message->getBody());
18+
}
19+
);
20+
printf("Subscribed to 'foo' messages." . PHP_EOL);
21+
22+
// Wait for messages.
23+
printf("Wait for messages on %s subscriptions" . PHP_EOL, $client->subscriptionsCount());
24+
while (true) {
25+
$client->wait();
26+
27+
printf("Reconnecting ..." . PHP_EOL);
28+
$client->reconnect();
29+
printf("Reconnected %s subscriptions" . PHP_EOL, $client->subscriptionsCount());
30+
}

src/Nats/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public function request($subject, $payload, \Closure $callback)
437437
$this->send($msg."\r\n".$payload);
438438
$this->pubs += 1;
439439

440-
$this->wait(2);
440+
$this->wait(1);
441441
}
442442

443443
/**

0 commit comments

Comments
 (0)