All Projects → opensaasstudio → Plasma

opensaasstudio / Plasma

Licence: mit
universal server push middleware by using gRPC stream and Server Sent Events(SSE)

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Plasma

Thingsboard
Open-source IoT Platform - Device management, data collection, processing and visualization.
Stars: ✭ 10,526 (+6870.86%)
Mutual labels:  grpc, middleware
Yoyogo
🦄🌈 YoyoGo is a simple, light and fast , dependency injection based micro-service framework written in Go. Support Nacos ,Consoul ,Etcd ,Eureka ,kubernetes.
Stars: ✭ 277 (+83.44%)
Mutual labels:  grpc, middleware
Ginrpc
gin auto binding,grpc, and annotated route,gin 注解路由, grpc,自动参数绑定工具
Stars: ✭ 157 (+3.97%)
Mutual labels:  grpc, middleware
Mortar
Mortar is a GO framework/library for building gRPC (and REST) web services.
Stars: ✭ 492 (+225.83%)
Mutual labels:  grpc, middleware
Grpc Tools
A suite of gRPC debugging tools. Like Fiddler/Charles but for gRPC.
Stars: ✭ 881 (+483.44%)
Mutual labels:  grpc, middleware
Centrifugo
Scalable real-time messaging server in a language-agnostic way. Set up once and forever.
Stars: ✭ 5,649 (+3641.06%)
Mutual labels:  grpc, eventsource
Go Grpc Middleware
Golang gRPC Middlewares: interceptor chaining, auth, logging, retries and more.
Stars: ✭ 4,170 (+2661.59%)
Mutual labels:  grpc, middleware
Condor Framework
Framework for building GRPC services in Node JS. Include middleware, and more.
Stars: ✭ 52 (-65.56%)
Mutual labels:  grpc, middleware
Koatty
Koa2 + Typescript = Koatty. Use Typescript's decorator implement IOC and AOP.
Stars: ✭ 67 (-55.63%)
Mutual labels:  grpc, middleware
Grpc Lb
Example for grpc-lb with etcd
Stars: ✭ 140 (-7.28%)
Mutual labels:  grpc
Core
Eru, a simple, stateless, flexible, production-ready orchestrator designed to easily integrate into existing workflows. Can run any virtualization things in long or short time.
Stars: ✭ 147 (-2.65%)
Mutual labels:  grpc
Asgard
Asgarde Framework
Stars: ✭ 138 (-8.61%)
Mutual labels:  grpc
Silicon
A high performance, middleware oriented C++14 http web framework please use matt-42/lithium instead
Stars: ✭ 1,721 (+1039.74%)
Mutual labels:  middleware
Go Micro Boilerplate
The boilerplate of the GoLang application with a clear microservices architecture.
Stars: ✭ 147 (-2.65%)
Mutual labels:  grpc
Hardhat
Help secure .net core apps with various HTTP headers (such as CSP's)
Stars: ✭ 138 (-8.61%)
Mutual labels:  middleware
Zeebe
Distributed Workflow Engine for Microservices Orchestration
Stars: ✭ 2,165 (+1333.77%)
Mutual labels:  grpc
Pure Http
✨ The simple web framework for Node.js with zero dependencies.
Stars: ✭ 139 (-7.95%)
Mutual labels:  middleware
Owaspheaders.core
A .NET Core middleware for injecting the Owasp recommended HTTP Headers for increased security
Stars: ✭ 138 (-8.61%)
Mutual labels:  middleware
Redux Catch
Error catcher middleware for Redux reducers and sync middlewares
Stars: ✭ 150 (-0.66%)
Mutual labels:  middleware
Strapi Middleware Cache
🔌 A cache middleware for https://strapi.io
Stars: ✭ 146 (-3.31%)
Mutual labels:  middleware

plasma

Circle CI Language issues License: MIT imagelayers.io Docker Stars Docker Pulls

Attention: This repository was transfererd from openfresh.

logo

plasma is event push middleware by using gRPC stream.

Description

Plasma is middleware for sending event specialized for a stream. Plasma provides EventSource and gRPC Stream from the same endpoint.

img

Installation

This middleware requires Redis.

From Source

$ git clone git://github.com/openfresh/plasma.git $GOPATH/src/github.com/openfresh/plasma
$ cd  $GOPATH/src/github.com/openfresh/plasma
$ make deps
$ make build

The binary is generated under the bin/ directory.

Using docker

You can also use the Docker image.

$ docker run -p 8080:8080 -p 50051:50051 -p 9999:9999 openfresh/plasma

Using docker-compose

You can use docker-compose for easy use without preparing Redis.

$ git clone git://github.com/openfresh/plasma.git $GOPATH/src/github.com/openfresh/plasma
$ cd  $GOPATH/src/github.com/openfresh/plasma
$ docker-compose up -d

Usage Subscriber

Server Sent Events

Using server-sent events

Your can use SSE if you request with Accept:text-stream header.

You request events that you want to subscribe to this endpoint. You can specify multiple events separated by commas. The query name can be set with the EventQuery environment variable.(default value of EventQuery is eventType ).

Here is a simple example using [Yaffle / EventSource] (https://github.com/Yaffle/EventSource).

    var source = new EventSource('//localhost:8080/?eventType=program🔢views,program🔢poll,program🔢annotation');
    
    source.addEventListener("open", function(e) {
        console.log("open");
    });
    
    source.addEventListener("error", function(e) {
        console.log("error");
    });
    
    source.addEventListener("message", function(e) {
        console.log("message event: ", e.data);
    });

The JSON schema of data returned from Plasma is as follows.

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "/events",
    "properties": {
        "data": {
            "id": "/events/data",
            "type": "string"
        },
        "meta": {
            "id": "/events/meta",
            "properties": {
                "type": {
                    "id": "/events/meta/type",
                    "type": "string"
                }
            },
            "type": "object"
        }
    },
    "type": "object"
}

If the DEBUG environment variable is enabled, you can access the debug endpoint.

GET /debug

You can publish events to Redis from this endpoint. You need to enter valid JSON in EventData form.

gRPC Stream

You can subscribe to events using gRPC Stream.

The ProtocolBuffer file is here .

The following is a simple Go sample.

func main() {
    conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close()

    client := proto.NewStreamServiceClient(conn)
    ctx := context.Background()

    req := proto.Request{
        Events: []*proto.EventType{
            eventType("program🔢poll"),
            eventType("program🔢views"),
        },
    }

    ss, err := client.Events(ctx)
    if err != nil {
        log.Fatal(err)
    }

    // subscribe event
    if err := ss.Send(&req); err != nil {
        log.Fatal(err)
    }

    for {
        resp, err := ss.Recv()
        if err != nil {
            log.Println(err)
            continue
        }
        if resp == nil {
            log.Println("payload is nil")
            continue
        }
        fmt.Printf("Meta: %s\tData: %s\n", resp.EventType.Type, resp.Data)
    }
}

unsubscribe

Events request is stream. If you unsubscribe event, set empty event data.

    req := proto.Request{
        // empty events
        Events: []*proto.EventType{},
    }

    ss, err := client.Events(ctx)
    if err != nil {
        log.Fatal(err)
    }

    // unsubscribe event
    if err := ss.Send(&req); err != nil {
        log.Fatal(err)
    }

Usage Publisher

You publish events to the channel that Plasma subscribes according to the following JSON Schema.

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "/events",
    "properties": {
        "data": {
            "id": "/events/data",
            "type": "string"
        },
        "meta": {
            "id": "/events/meta",
            "properties": {
                "type": {
                    "id": "/events/meta/type",
                    "type": "string"
                }
            },
            "type": "object"
        }
    },
    "type": "object"
}

openfresh/plasma-go is a library that wraps publish an event to Redis.

HealthCheck

GET /hc

You can do a health check. Check the status of Redis. If there is a problem it returns 500, and if there is no problem it returns 200.

Metrics

GET /metrics/go

You can get golang metrics from this endpoint.

The following golang metrics can be taken.

name type desc
go_version string version of go
go_os string os
go_arch string arch
cpu_num int number of cpus
goroutine_num int number of goroutines
gomaxprocs int number of operating system threads
cgo_call_num int64 number of cgo calls
memory_alloc uint64 bytes of allocated heap objects
memory_total_alloc uint64 cumulative bytes allocated for heap objects
memory_sys uint64 total bytes of memory
memory_lookups uint64 number of pointer
memory_mallocs uint64 cumulative count of heap objects allocated
memory_frees uint64 cumulative count of heap objects freed
memory_stack uint64 bytes in stack spans
heap_alloc uint64 bytes of allocated heap objects
heap_sys uint64 bytes of heap memory obtained
heap_idle uint64 bytes in idle spans
heap_inuse uint64 bytes in in-use spans
heap_released uint64 bytes of physical memory returned to the OS
heap_objects uint64 number of allocated heap objects
gc_next uint64 target heap size of the next GC cycle
gc_last uint64 time the last garbage collection finished, as, nanoseconds since 1970
gc_num uint32 number of completed GC cycles
gc_per_second float64 GC per second
gc_pause_per_second float64 GC pause per second
gc_pause []float64 GC pause

GET /metrics/plasma

You can get plasma metrics from this endpoint.

The following golang metrics can be taken.

name type desc
connections int64 number of connected all clients
connections_sse int64 number of connected SSE sclients
connections_grpc int64 number of connected gRPC sclients

Config

name type desc default note
PLASMA_PORT string http(https) port number 8080
PLASMA_GRPC_PORT string gRPC port number 50051
PLASMA_METRICS_PORT string metrics port number 9999
PLASMA_PPROF_HOST string pprof host 0.0.0.0
PLASMA_PPROF_PORT string pprof port number 6060
PLASMA_DEBUG bool debug mode false
PLASMA_ORIGIN string set to Access-Controll-Allow-Origin
PLASMA_SSE_RETRY int reconnect to the source milliseconds after each connection is closed 2000
PLASMA_SSE_EVENTQUERY string use as a querystring in SSE eventType ex) /?eventType=program🔢views
PLASMA_SUBSCRIBER_TYPE string subscriber type mock support "mock" and "redis"
PLASMA_SUBSCRIBER_REDIS_ADDR string Redis address including port number localhost:6379
PLASMA_SUBSCRIBER_REDIS_PASSWORD string Redis password
PLASMA_SUBSCRIBER_REDIS_DB int Redis DB 0
PLASMA_SUBSCRIBER_REDIS_CHANNELS string channels of Redis to subscribe (multiple specifications possible)
PLASMA_SUBSCRIBER_REDIS_OVER_MAX_RETRY_BEHAVIOR string Behavior of plasma when the number of retries connecting to Redis exceeds the maximum "die" or "alive"
PLASMA_SUBSCRIBER_REDIS_TIMEOUT time.Duration timeout for receive message from Redis 1s
PLASMA_SUBSCRIBER_REDIS_RETRY_INTERVAL time.Duration interval for retry to receive message from Redis 5s
PLASMA_ERROR_LOG_OUT string log file path stdout, stderr, filepath
PLASMA_ERROR_LOG_LEVEL string log output level panic,fatal,error,warn,info,debug
PLASMA_ACCESS_LOG_OUT string log file path stdout, stderr, filepath
PLASMA_ACCESS_LOG_LEVEL string log output level panic,fatal,error,warn,info,debug
PLASMA_TLS_CERT_FILE string cert file path TLS is enabled only when you set both PLASMA_TLS_CERT_FILE and PLASMA_TLS_KEY_FILE
PLASMA_TLS_KEY_FILE string key file path
PLASMA_METRICS_TYPE string metrics type support "log" or "syslog". if this value is empty, metrics will be disabled
PLASMA_METRICS_INTERVAL time.Duration interval for update metrics 10s
PLASMA_METRICS_LOG_OUT string log file path stdout
PLASMA_METRICS_LOG_PREFIX string log prefix metrics
PLASMA_METRICS_LOG_FLAG int define which text to prefix to each log entry generated by the Logger log.Lmicroseconds https://golang.org/pkg/log/#pkg-constants
PLASMA_METRICS_LOG_INTERVAL time.Duration interval for send to logger 1m
PLASMA_METRICS_SYSLOG_TAG string tag for syslog plasma
PLASMA_METRICS_SYSLOG_INTERVAL time.Duration interval for send to syslog 1m
PLASMA_METRICS_SYSLOG_SEVERITY int syslog serverity 0 https://golang.org/pkg/log/syslog/#Priority
PLASMA_METRICS_SYSLOG_FACILITY int syslog facility 0 https://golang.org/pkg/log/syslog/#Priority
PLASMA_METRICS_SYSLOG_NETWORDK string network for syslog
PLASMA_METRICS_SYSLOG_ADDR string address for syslog

License

See LICENSE.

Copyright © CyberAgent, Inc. All Rights Reserved.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].