-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrsocket-client.php
More file actions
33 lines (25 loc) · 864 Bytes
/
Copy pathrsocket-client.php
File metadata and controls
33 lines (25 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require 'vendor/autoload.php';
use React\EventLoop\Loop;
use RSocket\Payload;
use RSocket\RSocket;
use RSocket\RSocketConnector;
use Rx\Observable;
use Rx\Scheduler;
/** @noinspection PhpUnhandledExceptionInspection */
Scheduler::setDefaultFactory(function () {
return new Scheduler\EventLoopScheduler(Loop::get());
});
$rsocketCall = function (RSocket $rsocket) {
$observablePayload = $rsocket->requestResponse(Payload::fromText("text/plain", "Ping"));
$observablePayload->subscribe(
function (Payload $payload) {
echo 'Result: ' . $payload->getDataUtf8() . PHP_EOL;
}
);
};
$rsocketPromise = RSocketConnector::create()->connect("tcp://127.0.0.1:42252");
$rsocketPromise->then($rsocketCall);
$target = Observable::fromPromise($rsocketPromise);
$target->map($rsocketCall)->subscribe();
Loop::get()->run();