Git Product home page Git Product logo

ssehub's Introduction

SSEHub (Server-Sent Events streaming server)

High performance SSE-server implementation written in C++.

Features

  • Supports multiple channels both staticly and dynamically-on-the-fly configured.
  • Configurable history cache that can be requested by clients upon reconnect using lastEventId.
  • Configurable "keep-alive" pings.
  • CORS support.
  • RabbitMQ input source.
  • HTTP POST support to publish event.
  • Access control for publishers.
  • Polyfill client support.
  • Multiple storage adapters for cache.
  • Statistics endpoint (/stats).

Building and running

# Install dependencies (using apt in this example):
apt-get install g++ make libgoogle-glog-dev libboost-dev libboost-system-dev \
libboost-thread-dev libboost-program-options-dev librabbitmq-dev libleveldb-dev

# Checkout sourcecode:
git clone [email protected]:vgno/ssehub.git

# Compile:
cd ssehub && make

# Run:
./ssehub --config path/to/config.json (will use ./conf/config.json as default).

Building docker image

There is also a Dockerfile you can use to build a docker image.
To build issue the following command within the project root directory:

docker build -t ssehub .

Offical docker image

docker pull quay.io/vgno/ssehub
docker run -v ./config/:/ssehub/conf/ -p 8080:8080 quay.io/vgno/ssehub

Docker Repository on Quay

Example configuration

{
  "server": {
    "port": 8080,
    "bind-ip": "0.0.0.0",
    "logdir": "./",
    "pingInterval": 5,
    "pingEvent": false,
    "threadsPerChannel": 2,
    "allowUndefinedChannels": true
  },
  "amqp": {
    "enabled": false,
    "host": "127.0.0.1",
    "port": 5672,
    "user": "guest",
    "password": "guest",
    "exchange": "amq.fanout"
  },
  "redis": {
    "host": "127.0.0.1",
    "port": 6379,
    "prefix": "ssehub"
  },
  "leveldb": {
    "storageDir": "/tmp"
  },
  "default": {
    "cacheAdapter": "leveldb",
    "cacheLength": 500,
    "allowedOrigins":  "*",
    "restrictPublish": [
      "127.0.0.1"
    ]
  },
  "channels": [
    {
        "path": "test",
        "allowedOrigins": ["https://some.host"],
        "cacheLength": 5
    },
    {
        "path": "test2",
        "cacheAdapter": "memory",
        "restrictPublish": [
         "10.0.0.0/8"
        ]
    }
  ]
}

Event format

Currently we support POST and RabbitMQ fanout queue as input source. For POST you can restrict access on ip/subnet basis with the restrictPublish configuration directive. You can do this both globally in the default section of the config or per channel basis.

Events should be sent in the following format:

{
    "id": 1,
    "path": "test",
    "event": "message",
    "data": "My event data."
}

The id and event fields is optional, but only events with a defined id will be cached.

When using POST for publishing events the path element in the event is ignored and replaced with the channel/endpoint you are posting to. If you are using AMQP then you must set path to the channel you want to publish to.

Example using POST

Publish event to channel test with curl:

curl -v -X POST http://127.0.0.1:8080/test \
-d '{ "id": 1, "event": "message", "data": "Test message" }'

Dynamic creation of channels

If allowUndefinedChannels is set to true in the config the channel will be created when the first event is sent to the channel.

Cache adapters

To request all events since a certain ID use the query parameter lastEventId=<id> or header Last-Event-ID: <id>. You can also request the entire cache for a channel by using query parameter getcache=1.

Memory

Stores events in memory, but is not persistent. Events will only be persisted througout the liftetime of the process.

LevelDB

Stores events in memory for fast access and also persists them to disk.

Redis

Stores events in Redis which also makes this store distributed and usable by multiple instances of ssehub.

License

SSEHub is licensed under MIT. See LICENSE.

ssehub's People

Contributors

olesku avatar rexxars avatar sgulseth avatar talkrz avatar voldern avatar

Watchers

 avatar  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.