Coder Social home page Coder Social logo

linkage's Introduction

Linkage

Linkage is a job stream service based on server streaming gRPC. One incoming stream and multiple outcome stream.

Install

go get github.com/Natata/linkage

How to use

  1. Define yourself engine Define an engine which implement engine interface. Engine interface defined in engine.go, look like below:
type Engine interface {
    // Start starts the engine, jobs would send to the engine throught the inbound channel
    Start(inbound <-chan *Job) error
    // Register register an output destination, results generated by engine would send to the outbound channel
    // the signal is used to notify down stream or service is closing
    Register(sig chan Signal) (<-chan *Job, error)
}
  1. Initial linkage service Iniital linkage with
  • address: listen incoming message
  • engine: engine implement
  • grpc server options: if this service need credentials or other grpc server supported options
  • codeAssert: except credential, you can use codeAssert to tell client if it the right service connected
  • dial info: infomation of remote service this service will connect. Leave nil if this service not connect to any service.
  • waiting function: the waiting mechanism to retry to ask job frmo remote service.
    addr := ":8081"
    engine := &MyEngine{}
    codeAssert := func(code linkage.Code) bool {
        return true
    }   

    di := &linkage.DialInfo{
        ConnCode:   "yo",
        Addr:       ":8080",
        Opts:       []grpc.DialOption{grpc.WithInsecure()},
        MaxAttempt: 2,
    }   

    srv, err := linkage.InitLinkage(addr, engine, []grpc.ServerOption{}, codeAssert, di, nil)
  1. Run it
err := srv.Run()

example/ have full examples.

run go run example/rome/main.go and go run example/road/main.go in order to see what happened :)

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.