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

Commit ade4ce4

Browse files
committed
Merge branch 'release/0.8.3'
2 parents 4c2d04d + 8f9537c commit ade4ce4

21 files changed

Lines changed: 637 additions & 313 deletions

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ services:
33
- docker
44
language: php
55
php:
6-
- 5.5
76
- 5.6
87
- 7
98
- 7.1

README.md

Lines changed: 81 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ A PHP client for the [NATS messaging system](https://nats.io).
2121
Requirements
2222
------------
2323

24-
* php 5.5+
24+
* php 5.6+
2525
* [nats](https://github.com/derekcollison/nats) or [gnatsd](https://github.com/apcera/gnatsd)
2626

2727

@@ -58,30 +58,93 @@ Composer will download all the dependencies defined in composer.json, and prepar
5858
$client = new \Nats\Connection();
5959
$client->connect();
6060

61-
# Simple Publisher
62-
$client->publish("foo", "foo bar");
61+
// Publish Subscribe
6362

64-
# Simple Subscriber
65-
$callback = function($payload)
66-
{
67-
printf("Data: %s\r\n", $payload);
68-
};
69-
$client->subscribe("foo", $callback);
63+
// Simple Subscriber.
64+
$client->subscribe(
65+
'foo',
66+
function ($message) {
67+
printf("Data: %s\r\n", $message->getBody());
68+
}
69+
);
7070

71-
# Request
72-
$client->request('sayhello', 'Marty McFly', function ($response) {
73-
echo $response->getBody();
74-
});
71+
// Simple Publisher.
72+
$client->publish('foo', 'Marty McFly');
7573

76-
# Responding to requests
77-
$sid = $client->subscribe("sayhello", function ($res) {
78-
$res->reply("Hello, " . $res->getBody() . " !!!");
79-
});
74+
// Wait for 1 message.
75+
$client->wait(1);
8076

77+
// Request Response
78+
79+
// Responding to requests.
80+
$sid = $client->subscribe(
81+
'sayhello',
82+
function ($message) {
83+
$message->reply('Reply: Hello, '.$message->getBody().' !!!');
84+
}
85+
);
86+
87+
// Request.
88+
$client->request(
89+
'sayhello',
90+
'Marty McFly',
91+
function ($message) {
92+
echo $message->getBody();
93+
}
94+
);
95+
```
8196

97+
### Encoded Connections
8298

83-
# Wait for 1 message
99+
```php
100+
$encoder = new \Nats\Encoders\JSONEncoder();
101+
$options = new \Nats\ConnectionOptions();
102+
$client = new \Nats\EncodedConnection($options, $encoder);
103+
$client->connect();
104+
105+
// Publish Subscribe
106+
107+
// Simple Subscriber.
108+
$client->subscribe(
109+
'foo',
110+
function ($payload) {
111+
printf("Data: %s\r\n", $payload->getBody()[1]);
112+
}
113+
);
114+
115+
// Simple Publisher.
116+
$client->publish(
117+
'foo',
118+
[
119+
'Marty',
120+
'McFly',
121+
]
122+
);
123+
124+
// Wait for 1 message.
84125
$client->wait(1);
126+
127+
// Request Response
128+
129+
// Responding to requests.
130+
$sid = $client->subscribe(
131+
'sayhello',
132+
function ($message) {
133+
$message->reply('Reply: Hello, '.$message->getBody()[1].' !!!');
134+
}
135+
);
136+
137+
// Request.
138+
$client->request(
139+
'sayhello',
140+
[
141+
'Marty',
142+
'McFly',
143+
],
144+
function ($message) {
145+
echo $message->getBody();
146+
}
147+
);
85148
```
86149

87150

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.2
1+
0.8.3

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"ircmaxell/random-lib": "^1.1"
99
},
1010
"require-dev": {
11-
"phpunit/phpunit": "4.7.*",
11+
"phpunit/phpunit": "5.*",
1212
"satooshi/php-coveralls": "dev-master",
1313
"squizlabs/php_codesniffer": "~2.0",
1414
"phpspec/phpspec": "~2.0"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__.'/../../vendor/autoload.php';
3+
4+
$encoder = new \Nats\Encoders\JSONEncoder();
5+
$options = new \Nats\ConnectionOptions();
6+
$client = new \Nats\EncodedConnection($options, $encoder);
7+
$client->connect();
8+
9+
// Publish Subscribe.
10+
// Simple Subscriber.
11+
$client->subscribe(
12+
'foo',
13+
function ($payload) {
14+
printf("Data: %s\r\n", $payload->getBody()[1]);
15+
}
16+
);
17+
18+
// Simple Publisher.
19+
$client->publish(
20+
'foo',
21+
[
22+
'Marty',
23+
'McFly',
24+
]
25+
);
26+
27+
// Wait for 1 message.
28+
$client->wait(1);

examples/pubsub/pub.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/pubsub/pubsub.php

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

examples/pubsub/sub.php

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__.'/../../vendor/autoload.php';
3+
4+
$encoder = new \Nats\Encoders\JSONEncoder();
5+
$options = new \Nats\ConnectionOptions();
6+
$client = new \Nats\EncodedConnection($options, $encoder);
7+
$client->connect();
8+
9+
// Request Response.
10+
// Responding to requests.
11+
$sid = $client->subscribe(
12+
'sayhello',
13+
function ($message) {
14+
$message->reply('Reply: Hello, '.$message->getBody()[1].' !!!');
15+
}
16+
);
17+
18+
// Request.
19+
$client->request(
20+
'sayhello',
21+
[
22+
'Marty',
23+
'McFly',
24+
],
25+
function ($message) {
26+
echo $message->getBody();
27+
}
28+
);

examples/reqres/req.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)