1
0
Fork 0

Hub info function

This commit is contained in:
Gregory Eremin 2014-09-11 23:08:12 +04:00
parent d811f366a9
commit 3d98c84548
1 changed files with 24 additions and 0 deletions

View File

@ -57,6 +57,30 @@ func (h *Hub) Sub(s *Subscription) {
h.subscribers = append(h.subscribers, s)
}
func (h *Hub) Info() map[string]map[string]uint {
info := make(map[string]map[string]uint)
for queue, size := range h.storage.Info() {
info[queue] = map[string]uint{
"messages": size,
"subscriptions": 0,
}
}
for _, sub := range h.subscribers {
for _, queue := range sub.Queues {
if _, ok := info[queue]; !ok {
info[queue] = map[string]uint{"messages": 0}
}
if _, ok := info[queue]["subscriptions"]; !ok {
info[queue]["subscriptions"] = 0
}
info[queue]["subscriptions"] += 1
}
}
return info
}
func (h *Hub) cleanupEverySecond() {
t := time.NewTicker(1 * time.Second)