rx / thruway-client
RxPHP WAMP client
Installs: 17 351
Dependents: 3
Suggesters: 0
Security: 0
Stars: 6
Watchers: 5
Forks: 4
Open Issues: 5
Requires
- php: >=7.1
- reactivex/rxphp: ^2.0.4
- rx/websocket: ^2.1.7
- voryx/thruway-common: ^1.0.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-01 16:34:02 UTC
README
This project is a WAMP v2 client written in PHP that uses RxPHP Observables instead of promises and event emitters.
If you don't know what WAMP is, you should read up on it.
If you don't know what RxPHP or ReactiveExtensions is, you're missing out...
Installation
composer require rx/thruway-client
Usage
use Rx\Observable; use Rx\Thruway\Client; require __DIR__ . '/vendor/autoload.php'; $wamp = new Client('ws://127.0.0.1:9090', 'realm1');
Call
$wamp->call('add.rpc', [1, 2]) ->map(function (Thruway\Message\ResultMessage $r) { return $r->getArguments()[0]; }) ->subscribe(function ($r) { echo $r; });
Register
$wamp->register('add.rpc', function ($a, $b) { return $a + $b; })->subscribe();
If the Registration Handler throws an exception,
thruway.error.invocation_exception
is returned to the caller. If you would like to allow more specific error messages, you must throw aWampErrorException
or, if using observable sequences that are returned from the RPC, you canonError
aWampErrorException
.
Publish to topic
$wamp->publish('example.topic', 'some value'); $wamp->publish('example.topic', Observable::interval(1000)); // you can also publish an observable
Subscribe to topic
$wamp->topic('example.topic') ->map(function(Thruway\Message\EventMessage $m) { return $m->getArguments()[0]; }) ->subscribe(function ($v) { echo $v; });