aksalj/rsocket

RSocket PHP SDK based on ReactPHP and RxPHP

0.1.1 2020-02-22 00:00 UTC

This package is not auto-updated.

Last update: 2024-11-08 19:52:12 UTC


README

Composer

RSocket PHP SDK based on ReactPHP and RxPHP.

Requirements

  • PHP 7.4.x

Examples

RSocket Client

Scheduler::setDefaultFactory(function () use ($loop) {
    return new Scheduler\EventLoopScheduler($loop);
});

$rsocketPromise = RSocketConnector::create($loop)->connect("tcp://127.0.0.1:42252");

$rsocketPromise->then(function (RSocket $rsocket) {
    $observablePayload = $rsocket->requestResponse(Payload::fromText("text/plain", "Ping"));
    $observablePayload->subscribe(
        function (Payload $x) {
            echo 'Result: ' . $x->getDataUtf8();
        }
    );
});

RSocket Server

Scheduler::setDefaultFactory(function () use ($loop) {
    return new Scheduler\EventLoopScheduler($loop);
});

$listenUri = "tcp://127.0.0.1:42252";
$socketAcceptor = CallableSocketAcceptor::handle(function ($setupPayload, $sendingRSocket) {
    return AbstractRSocket::requestResponseHandler(function ($payload) {
        return Observable::of(Payload::fromText("metadata", "PONG"));
    });
});
$server = RSocketServer::create($loop, $socketAcceptor)->bind($listenUri);
print("RSocket Server started on ${listenUri}");

RSocket Service stub and routing

Please check https://github.com/aksalj/rsocket-php/tree/master/tests/route

RSocket

  • Operations
    • REQUEST_FNF
    • REQUEST_RESPONSE
    • REQUEST_STREAM
    • REQUEST_CHANNEL
    • METADATA_PUSH
  • More Operations
    • Error
    • Cancel
    • Keepalive
  • QoS
    • RequestN
    • Lease
  • Transport
    • TCP
    • Websocket
  • High Level APIs
    • Client
    • Server
  • Misc
    • RxPHP

References