messagebus

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: MIT Imports: 3 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

goos: darwin
goarch: amd64
pkg: github.com/vardius/message-bus
BenchmarkWorker100-4                           3         352169727 ns/op
BenchmarkWorkerNumCPU-4                        5         301247338 ns/op
BenchmarkWorker-4                             10         182287824 ns/op
BenchmarkWorker100Parallel-4                  10         117857721 ns/op
BenchmarkWorkerNumCPUParallel-4               10         113668659 ns/op
BenchmarkWorkerParallel-4                     10         105661820 ns/op
PASS
ok      github.com/vardius/message-bus  15.889s

Basic example

package main

import (
    "fmt"

    "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{})
	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