Exemple #1
0
<?php

require_once "../../vendor/autoload.php";
const HOST = "localhost";
const PORT = 4222;
$c = new Nats\Connection();
$c->connect();
$callback = function ($payload) {
    printf("Data: %s\r\n", $payload);
};
$sid = $c->subscribe("foo", $callback);
$c->wait(2);
$c->unsubscribe($sid);
Exemple #2
0
<?php

require_once __DIR__ . "/../../vendor/autoload.php";
$connectionOptions = new \Nats\ConnectionOptions();
$connectionOptions->setHost('localhost')->setPort(4222);
$c = new Nats\Connection($connectionOptions);
$c->connect();
$sid = $c->subscribe("sayhello", function ($res) {
    $res->reply("Hello, " . $res->getBody() . " !!!");
});
$c->wait(2);
$c->unsubscribe($sid);