Git Product home page Git Product logo

sockjs-pubsub's Introduction

sockjs-pubsub

Minimalistic Publish/Subscribe for SockJS and sockjs-erlang

Features

  • No history or persistance, for realtime messaging only
  • No manual channel creation, if nobody is subscribed - message just discards

Public API

sps:start().
sps:subscribe(Channel, Conn).
sps:unsubscribe(Channel, Conn).
sps:publish(Channel, Message).
  • Channel - arbitrary binary string
  • Conn and Message - as in SockJS

Internals

  • On each node application starts 24 managers (locally registered gen_servers with predefined names) under 1 supervisor.
  • Binary channels are mapped to respective manager with hash function (zlib:crc2/2).
  • On subscribe/unsubscribe Conn is passed to local manager to be stored in ETS table. Each channel has it's own unnamed table. Table ids are looked up via private ETS master-table.
  • On publish Message is broadcasted to respective manager on each connected erlang node with gen_server:abcast/2. Manager determines table id for channel and spawns short-lived process that will JSON-encode it and broadcast to all connections in channel ETS table. If this process stumbles upon dead connection it removes it.
  • Optional deflate message support (in sps:subscribe/3 specify third argument, Deflate, as true). To decode on client side you need to apply base64:decode followed by zlib inflate.

Alternatives

  • RabbitMQ - separate message passing service with advanced features like clustering, persistance and acknowledgements. Recommended if messages are important and shouldn't be lost.
  • Distributed Pub/Sub - simple publish/subscribe with message history and asynchronous replication between Erlang nodes.
  • sockjs-multiplex - part of sockjs-erlang that can do something similar with predefined channels and customized handlers, only within one Erlang node.

sockjs-pubsub's People

Contributors

blinkov avatar

Stargazers

 avatar  avatar  avatar Andrew Strelets avatar Mathieu M-Gosselin avatar Mikhail Andreev avatar

Watchers

 avatar  avatar Svetlana Kharina avatar  avatar

Forkers

chinnurtb

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.