@@ -58,28 +58,32 @@ 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
6463# Simple Subscriber
65- $callback = function($payload )
64+ $callback = function($message )
6665{
67- printf("Data: %s\r\n", $payload );
66+ printf("Data: %s\r\n", $message->getBody() );
6867};
6968$client->subscribe("foo", $callback);
7069
71- # Request
72- $client->request('sayhello', 'Marty McFly', function ($response) {
73- echo $response->getBody();
74- });
70+ # Simple Publisher
71+ $client->publish("foo", "foo bar");
72+
73+ # Wait for 1 message
74+ $client->wait(1);
75+
76+ // Request Response
7577
7678# Responding to requests
77- $sid = $client->subscribe("sayhello", function ($res ) {
78- $res ->reply("Hello, " . $res ->getBody() . " !!!");
79+ $sid = $client->subscribe("sayhello", function ($message ) {
80+ $message ->reply("Reply: Hello, " . $message ->getBody() . " !!!");
7981});
8082
81- # Wait for 1 message
82- $client->wait(1);
83+ # Request
84+ $client->request('sayhello', 'Marty McFly', function ($message) {
85+ echo $message->getBody();
86+ });
8387```
8488
8589### Encoded Connections
@@ -90,30 +94,32 @@ $options = new \Nats\ConnectionOptions();
9094$client = new \Nats\EncodedConnection($options, $encoder);
9195$client->connect();
9296
93- # Simple Publisher
94- $client->publish("foo", array("one", "two"));
97+ // Publish Subscribe
9598
9699# Simple Subscriber
97100$callback = function($payload)
98101{
99- printf("Data: %s\r\n", var_dump( $payload) );
102+ printf("Data: %s\r\n", $payload->getBody()[1] );
100103};
101104$client->subscribe("foo", $callback);
102105
103- # Request
104- $client->request('sayhello', ['foo', 'Marty McFly'], function ($response) {
105- echo 'Hello '.$response->getBody()[1].' !!!';
106- });
106+ # Simple Publisher
107+ $client->publish("foo", ["foo", "bar"]);
107108
108- # Responding to requests
109- $sid = $client->subscribe("sayhello", function ($res) {
110- $res->reply("Hello, " . $res->getBody() . " !!!");
111- });
109+ # Wait for 1 message
110+ $client->wait(1);
112111
112+ // Request Response
113113
114+ # Responding to requests
115+ $sid = $client->subscribe("sayhello", function ($message) {
116+ $message->reply("Reply: Hello, " . $message->getBody()[1] . " !!!");
117+ });
114118
115- # Wait for 1 message
116- $client->wait(1);
119+ # Request
120+ $client->request('sayhello', ["foo", "McFly"], function ($message) {
121+ echo $message->getBody();
122+ });
117123```
118124
119125
0 commit comments