Code Monkey home page Code Monkey logo

gokaf's Introduction

Gokaf

Gokaf is a simple In-memory PubSub Engine to enable near real time data streams

Example

package main

import (
	"github.com/acjzz/gokaf"
	"fmt"
	"github.com/sirupsen/logrus"
	"time"
)

func main(){
	ge := gokaf.NewEngine("MyEngine", logrus.DebugLevel)

	topics := []string { "Topic0", "Topic1" }

	for _, topicName := range topics {
		// Register different Handler per each Topic as well as the Topics themselves
		ge.AddTopic(topicName, func(topic string, obj interface{}) {
			// Printf usage on the handlers is not recommended at all
			// if you pretend to achieve near realtime streams
			// In this example is for demonstration purposes only
			fmt.Printf("Consumed '%v' from topic '%s'\n", obj, topic)
		})
	}

	go func(){
		for i := 1; i <= 1000; i++ {
			// Simulation of High Frequency Data Stream
			e := ge.Publish(topics[0], fmt.Sprintf("High Frequency Message%d", i))
			if e != nil {
				fmt.Printf("publishing to topic %s, err: %v", topics[0], e)
				break
			}
			time.Sleep(time.Millisecond/100)
		}
	}()

	// Simulation of Low Frequency Data Stream
	for i := 1; i <= 35; i++ {
		e := ge.Publish(topics[1], fmt.Sprintf("Low Frequency Message%d", i))
		if e != nil {
			fmt.Printf("publishing to topic %s, err: %v", topics[1], e)
			break
		}
		time.Sleep(time.Millisecond)
	}

	ge.Stop()
}

gokaf's People

Contributors

acjzz avatar hrmnjt avatar

Watchers

 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.