react / stomp
STOMP bindings for React.
Installs: 86 966
Dependents: 1
Suggesters: 1
Security: 0
Stars: 115
Watchers: 20
Forks: 42
Open Issues: 14
Requires
- php: >=5.4
- evenement/evenement: ~2.0
- react/promise: ~1.0
- react/socket: 0.4.*
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is auto-updated.
Last update: 2024-10-25 14:09:34 UTC
README
STOMP bindings for React.
STOMP is a messaging protocol. It is supported by most message queue brokers, such as RabbitMQ, Apollo and many others.
A message queue is used for asynchronous inter-process communication. This can be useful for workers, general long-running tasks, or communication between long-running daemons.
Install
The recommended way to install react/stomp is through composer.
{ "require": { "react/stomp": "0.1.*" } }
Example
You can interact with a STOMP server by using the React\Stomp\Client
.
<?php $loop = React\EventLoop\Factory::create(); $factory = new React\Stomp\Factory($loop); $client = $factory->createClient(array('vhost' => '/', 'login' => 'guest', 'passcode' => 'guest')); $client ->connect() ->then(function ($client) use ($loop) { $client->subscribe('/topic/foo', function ($frame) { echo "Message received: {$frame->body}\n"; }); $loop->addPeriodicTimer(1, function () use ($client) { $client->send('/topic/foo', 'le message'); }); }); $loop->run();
Options
host
: Host to connect to, defaults to127.0.0.1
.port
: Port to connect to, defaults to61613
(rabbitmq's stomp plugin).vhost
: Virtual host, defaults to/
.login
: Login user name, defaults toguest
.passcode
: Login passcode, defaults toguest
.
Acknowledgement
When subscribing with the subscribe
method, messages are considered
acknowledged as soon as they are sent by the server (ack header is set to
'auto').
You can subscribe with a manual acknowledgement by using subscribeWithAck
(see SUBSCRIBE
in the STOMP spec for available ack mode values).
You will get a React\Stomp\AckResolver
as second argument of the callback to
acknowledge or not the message :
$client->subscribeWithAck('/topic/foo', 'client', function ($frame, $ackResolver) { if ($problem) { $ackResolver->nack(); } else { $ackResolver->ack(); } });
Todo
- Support nul bytes in frame body
- Heart-beating
- Consuming ACKs
- Transactions
- Streaming frame bodies (using stream API)
Tests
To run the test suite, you need PHPUnit.
$ phpunit
License
MIT, see LICENSE.