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

Commit 30158ca

Browse files
committed
Minor tweaks
1 parent 67c427d commit 30158ca

8 files changed

Lines changed: 50 additions & 9 deletions

File tree

examples/connect.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<?php
22
require_once __DIR__.'/../vendor/autoload.php';
33

4-
$connectionOptions = new \Nats\ConnectionOptions(
5-
[
6-
'host' => '127.0.0.1',
7-
'port' => 4222,
8-
]
9-
);
10-
11-
$c = new Nats\Connection($connectionOptions);
4+
$c = new Nats\Connection();
125
$c->connect();
136
$c->close();

examples/ping.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
$c = new Nats\Connection($connectionOptions);
1010
$c->connect();
1111

12+
13+
// TODO ping is not public.
1214
$c->ping();

examples/pubsub/pub.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
require_once __DIR__.'/../../vendor/autoload.php';
3+
4+
$client = new \Nats\Connection();
5+
$client->connect();
6+
7+
// Simple Publisher.
8+
$client->publish('foo', 'bar');
9+
$client->close();

examples/pubsub/pubsub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ function ($message) {
1818

1919
// Wait for 1 message.
2020
$client->wait(1);
21+
22+
$client->close();

examples/pubsub/sub.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
require_once __DIR__.'/../../vendor/autoload.php';
3+
4+
$client = new \Nats\Connection();
5+
$client->connect();
6+
7+
// Simple Subscriber.
8+
$client->subscribe(
9+
'foo',
10+
function ($message) {
11+
printf("Data: %s\r\n", $message->getBody());
12+
}
13+
);
14+
15+
$client->close();

examples/reqres/request.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
require_once __DIR__.'/../../vendor/autoload.php';
3+
4+
$client = new \Nats\Connection();
5+
$client->connect();
6+
7+
// Simple Publisher.
8+
// Request.
9+
$client->request(
10+
'foo',
11+
'Marty McFly',
12+
function ($message) {
13+
echo $message->getBody();
14+
}
15+
);
16+
17+
$client->close();

src/Nats/Connection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ public function request($subject, $payload, \Closure $callback)
464464
$inbox,
465465
$callback
466466
);
467+
467468
$msg = 'PUB '.$subject.' '.$inbox.' '.strlen($payload);
468469
$this->send($msg."\r\n".$payload);
469470
$this->pubs += 1;

src/Nats/EncodedConnection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Nats;
33

4+
use Nats\Encoders\Encoder;
5+
46
/**
57
* Class EncodedConnection
68
*
@@ -23,7 +25,7 @@ class EncodedConnection extends Connection
2325
* @param ConnectionOptions $options Connection options object.
2426
* @param \Nats\Encoders\Encoder|null $encoder Encoder to use with the payload.
2527
*/
26-
public function __construct(ConnectionOptions $options = null, \Nats\Encoders\Encoder $encoder = null)
28+
public function __construct(ConnectionOptions $options = null, Encoder $encoder = null)
2729
{
2830
$this->encoder = $encoder;
2931
parent::__construct($options);

0 commit comments

Comments
 (0)