Building a network of publishers and subscribers with Golang, Ruby, ZMQ (with some Git and Redis in the mix). Presented at London Ruby User Group in March 2014.
Blog post: http://new-bamboo.co.uk/blog/2013/09/17/micro-network-daemons-in-go
29. Git backups
pub/sub
doneChan := make(chan string)
bufferChan := make(chan int, 20)
stores := make(map[string]*ThemeStore)
for {
select {
case event := <-writer.Notifier:
account := event.Get("account")
store := stores[account]
// Register store and start delayed writing
// if not already registered
if store == nil {
store = NewThemeStore(account)
stores[account] = store
go store.DelayedWrite(bufferChan, doneChan)
}
case account := <-doneChan:
// A store is done writing.
// Un-register it so it can be registered again.
delete(stores, account)
}
}
github.com/bootic/bootic_themes_backup