Skip to content

EventBus is an simple messaging system in javascript-style.

License

Notifications You must be signed in to change notification settings

aristofanio/eventbus

Repository files navigation

EventBus

EventBus is an simple messaging system in listener-notifier style.

Progress

Build Status

Use

Download source code

$ go get -u github.com/aristofanio/eventbus

Example of use

Start server in host=localhost and port=9090:

package main

import "github.com/aristofanio/eventbus"

func main() {
	//configuring server
	bus, err := eventbus.NewEventBus("localhost", 9090)
	if err != nil {
		println(err.Error())
	}
    //start service
	bus.Start()
}

An listener:

package main

import (
	"github.com/aristofanio/eventbus"
	"io/ioutil"
	"log"
	"os"
)

func main() {
	//start listener
	l, err := eventbus.NewListener("localhost", 9090, "ln-019101")
	if err != nil {
		println(err.Error())
	}
	//registry (non-blocking)
	l.On(eventbus.EventType{"onTest"}, func(e *eventbus.Event, err error) {
		log.Printf("---> result: [type: %s, data: %s]", e.Type, string(e.Data))
	})
	//for avoid inexpected end
	ioutil.ReadAll(os.Stdin)
}

An Notifier:

package main

import "github.com/aristofanio/eventbus"

func main() {
	//
	e := eventbus.Event{
		Type:   eventbus.EventType{"onTest"},
		Origin: "nt-000001",
		Data:   []byte(`{"name": "teste"}`),
	}
	//
	notifier := eventbus.NewNotifier("localhost", 9090)
	err := notifier.Notify(e)
	if err != nil {
		println(err.Error())
	}
}

Evolution

  • add tests
  • add doc for frame (motivation)
  • add doc about concurrency
  • create option to transport data in json or protobuf format
  • refactory logger (use reference)

This tasks were based in this discussion. Reference

About

EventBus is an simple messaging system in javascript-style.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages