Skip to content
📨 A fast Message/Event Hub using publish/subscribe pattern with support for topics like* rabbitMQ exchanges for Go applications
Branch: master
Clone or download
leandro-lugaresi Add with (#7)
* added With option

* added tests
Latest commit a3b79e7 May 1, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
.codecov.yml added some initial CI tools Apr 17, 2018
.gitignore added .gitignore Apr 16, 2018
.travis.yml added some initial CI tools Apr 17, 2018 :data: initial commit Apr 11, 2018
LICENSE :data: initial commit Apr 11, 2018
Makefile added throughput test (#3) Apr 24, 2018 add multiple topic subscribers (#5) Apr 28, 2018
hub.go Add with (#7) May 1, 2018
hub_benchmark_test.go Added initial benchmarks (#6) Apr 29, 2018
hub_example_test.go add multiple topic subscribers (#5) Apr 28, 2018
matching_cstrie_test.go add multiple topic subscribers (#5) Apr 28, 2018
message.go Remove message helper functions (#2) Apr 24, 2018
subscriber.go Added initial benchmarks (#6) Apr 29, 2018
utils_test.go add multiple topic subscribers (#5) Apr 28, 2018


📨 A fast enough Event Hub for go applications using publish/subscribe with support patterns on topics like rabbitMQ exchanges.

Release Software License Build Status Coverage Status Go Doc Go Report Card Say Thanks!

Table of Contents


To install this library you can go get it but I encourage you to always vendor your dependencies or use one of the version tags of this project.

go get -u
dep ensure --add



Hub provides subscribers as buffered (cap > 0) and unbuffered (cap = 0) channels but we have two different types of subscribers:

  • Subscriber this is the default subscriber and it's a blocking subscriber so if the channel is full and you try to send another message the send operation will block until the subscriber consumes some message.
  • NonBlockingSubscriber this subscriber will never block on the publish side but if the capacity of the channel is reached the publish operation will be lost and an alert will be trigged. This should be used only if loose data is acceptable. ie: metrics, logs


This library uses the same concept of topic exchanges on rabbiMQ, so the message name is used to find all the subscribers that match the topic, like a route. The topic must be a list of words delimited by dots (.) however, there is one important special case for binding keys: * (star) can substitute for exactly one word.

Examples & Demos

package main

import (

func main() {
	h := hub.New()
	var wg sync.WaitGroup
	// the cap param is used to create one buffered channel with cap = 10
	// If you wan an unbuferred channel use the 0 cap
	sub := h.Subscribe(10, "account.login.*", "account.changepassword.*")
	go func(s hub.Subscription) {
		for msg := range s.Receiver {
			fmt.Printf("receive msg with topic %s and id %d\n", msg.Name, msg.Fields["id"])

		Name:   "account.login.failed",
		Fields: hub.Fields{"id": 123},
		Name:   "account.changepassword.failed",
		Fields: hub.Fields{"id": 456},
		Name:   "account.login.success",
		Fields: hub.Fields{"id": 123},
	// message not routed to this subscriber
		Name:   "",
		Fields: hub.Fields{"id": 789},

	// close all the subscribers
	// wait until finish all the messages on buffer

	// Output:
	// receive msg with topic account.login.failed and id 123
	// receive msg with topic account.changepassword.failed and id 456
	// receive msg with topic account.login.success and id 123

See more here!


To run the benchmarks you can execute:

make bench

Currently, I only have the benchmarks of the CSTrie used internally. I will provide more benchmarks.


The project have one test for throughput, just execute:

make throughput

In a intel(R) core(TM) i5-4460 CPU @ 3.20GHz x4 we got this results:

go test -v -timeout 60s -run ^TestThroughput -args -throughput
=== RUN   TestThroughput
1317530.091292 msg/sec
--- PASS: TestThroughput (3.04s)
ok 3.192s


This project uses internally an awesome Concurrent Subscription Trie done by @tylertreat. If you want to learn more about see this blog post and the code is here

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. We appreciate your contribution. Please refer to our contributing guidelines for further information

You can’t perform that action at this time.