messagebus

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2019 License: MIT Imports: 4 Imported by: 35

README

Vardius - message-bus

Build Status Go Report Card codecov license

Go simple async message bus.

ABOUT

Contributors:

Want to contribute ? Feel free to send pull requests!

Have problems, bugs, feature ideas? We are using the github issue tracker to manage them.

HOW TO USE

  1. GoDoc

Benchmark

CPU: 3,3 GHz Intel Core i7

RAM: 16 GB 2133 MHz LPDDR3

➜  message-bus git:(master) ✗ go test -bench=. -cpu=4 -benchmem
goos: darwin
goarch: amd64
BenchmarkBusNumCPU-4              500000              2565 ns/op              48 B/op          2 allocs/op
BenchmarkBusNumCPUParallel-4     1000000              1682 ns/op              48 B/op          2 allocs/op
BenchmarkBus-4                   1000000              1105 ns/op              48 B/op          2 allocs/op
BenchmarkBusParallel-4           2000000               955 ns/op              48 B/op          2 allocs/op
BenchmarkBus100-4                 100000             18328 ns/op              48 B/op          2 allocs/op
BenchmarkBus100Parallel-4         100000             18369 ns/op              48 B/op          2 allocs/op
PASS
ok      message-bus    11.148s

Basic example

package main

import (
    "fmt"
    "runtime"

    "github.com/vardius/message-bus"
)

func main() {
    bus := messagebus.New(runtime.NumCPU())

    var wg sync.WaitGroup
    wg.Add(2)

    bus.Subscribe("topic", func(v bool) {
        defer wg.Done()
        fmt.Println(v)
    })

    bus.Subscribe("topic", func(v bool) {
        defer wg.Done()
        fmt.Println(v)
    })

    bus.Publish("topic", true)
    wg.Wait()
}

License

This package is released under the MIT license. See the complete license in the package:

LICENSE

Documentation

Overview

Package messagebus provides simple async message publisher

Example
bus := messagebus.New(runtime.NumCPU())

var wg sync.WaitGroup
wg.Add(2)

bus.Subscribe("topic", func(v bool) {
	defer wg.Done()
	fmt.Println("s1", v)
})

bus.Subscribe("topic", func(v bool) {
	defer wg.Done()
	fmt.Println("s2", v)
})

bus.Publish("topic", true)
wg.Wait()
Output:

s1 true
s2 true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageBus

type MessageBus interface {
	Publish(topic string, args ...interface{})
	Close(topic string)
	Subscribe(topic string, fn interface{}) error
	Unsubscribe(topic string, fn interface{}) error
}

MessageBus implements publish/subscribe messaging paradigm

func New

func New(maxConcurrentCalls int) MessageBus

New creates new MessageBus maxConcurrentCalls limits concurrency by using a buffered channel semaphore

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL