Git Product home page Git Product logo

boost's Introduction

boostd

simple stream processor

The main components are: input stream/source, the transformation stage and the output.

Extract -> Transform -> Load/store

By default, it reads from STDIN and outputs to STDOUT.

A tranform function callback can do the following operations:

  • reject an object based on a value.
  • add a key value pair on an object
  • remove a key from an object
  • prefix a key with a string

How it works

Usage

CLI

clone repo or use go get github.com/rpip/boost

$ git clone [email protected]:rpip/boost
$ cd boost && make deps && make
$ ./boostd -h
Usage of boostd:
  -n int
        Max number of concurrent OUT streamers (default 4)
  -r duration
        burst rate (default 100ms)
  -v    Enable Verbose logging (default true)


$ ./boostd -r 10ms < boost/testdata/ordered_driver_positions.json_dump
# OR
$ ./boostd < boost/testdata/ordered_driver_positions.json_dump
{"created_at":"2016-12-14 08:18:39","id":183,"lat":48.877550211971496,"lng":2.386344728436552}
{"created_at":"2016-12-14 08:18:43","id":846,"lat":48.95799309422942,"lng":2.5436685974891184}
{"created_at":"2016-12-14 08:18:47","id":10912,"lat":49.00975592361513,"lng":2.400408684983234}
{"created_at":"2016-12-14 08:18:52","id":10331,"lat":48.64559215187843,"lng":2.342777276025095}
{"created_at":"2016-12-14 08:18:54","id":1778,"lat":50.809599227526014,"lng":2.584064846519136}

As a library

Transformers are callback functions that consume and perform state transformations upon delivery of these emitted messages. It can clean data, apply business rules or validation, filter etc.

A transformer takes in an object from the input stream and returns a tuple of the transformed item and an error if any. If there's an error in the returned tuple, we assume the object should be rejected.

type Transformer func(Item) (*Result, error)
func main() {
	ctx := context.Background()
	transformers := []boost.Transformer{reject, clean, prefix, decorate}
	pipe := boost.NewPipeline(ctx, os.Stdin, os.Stdout, transformers, time.Second/10,4, false)
	pipe.Run()
}

// transformers

// reject an object based on a value
func reject(res *boost.Result) (*boost.Result, error) {
	if res.Item["id"].(float64) == 557 {
		return res, errors.New("")
	}
	return res, nil
}

// add a key value pair on an object
func decorate(res *boost.Result) (*boost.Result, error) {
	res.Item["foo"] = "bar"
	return res, nil
}

Docker

$ make docker
$ cat boost/testdata/ordered_driver_positions.json_dump | docker run -i rpip/boost -r 10ms
{"created_at":"2016-12-14 08:18:39","id":183,"lat":48.877550211971496,"lng":2.386344728436552}
{"created_at":"2016-12-14 08:18:43","id":846,"lat":48.95799309422942,"lng":2.5436685974891184}
{"created_at":"2016-12-14 08:18:47","id":10912,"lat":49.00975592361513,"lng":2.400408684983234}
{"created_at":"2016-12-14 08:18:52","id":10331,"lat":48.64559215187843,"lng":2.342777276025095}
{"created_at":"2016-12-14 08:18:54","id":1778,"lat":50.809599227526014,"lng":2.584064846519136}
{"created_at":"2016-12-14 08:18:57","id":1874,"lat":48.95911833908978,"lng":2.240932341443888}
{"created_at":"2017-01-14 08:19:00","id":1295,"lat":48.9071900873022,"lng":2.4638371736867906}

$ # OR
$ docker run -i rpip/boost -r 10ms < boost/testdata/ordered_driver_positions.json_dump

future improvements

some ideas i'll hack on when i get some time:

  • more performant data structures
  • configurable input and output sources via CLI
  • support different types of input and outputs: HTTP(s), Kafka, File, MQTT, Redis, S3, Elasticsearch etc
  • multiple sources
  • configurable OUT push strategy
  • distributed maybe?

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.