Giter VIP home page Giter VIP logo

stomp's Introduction

React/STOMP

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.

Build Status

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 to 127.0.0.1.
  • port: Port to connect to, defaults to 61613 (rabbitmq's stomp plugin).
  • vhost: Virtual host, defaults to /.
  • login: Login user name, defaults to guest.
  • passcode: Login passcode, defaults to guest.

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.

Resources

stomp's People

Contributors

igorw avatar romainneutron avatar easen avatar cboden avatar fabpot avatar jakubkulhan avatar

Watchers

matthew xie avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.