func (mq *MessageQueue) Consumer(t MessageType, s Subscriber) {
	mq.rm.RLock()
	defer mq.rm.RUnlock()
	if mq.queue[t] == nil {
		mq.queue[t] = make(chan *Message, mq.size)
	}
	s.Subscribe(0, mq.queue[t])
}
Register a consumer to the MessageType queue
package gossip
import (
	"sync"
	"github.com/bbva/qed/log"
)
type Subscriber interface {
	Subscribe(id int, ch <-chan *Message)
}
type Producer interface {
	Produce(ch chan<- *Message)
}
type Subscribers []chan *Message
type MessageBus struct {
	pool [MAXMESSAGEID]Subscribers
	log  log.Logger
	rm   sync.RWMutex
}
func (eb *MessageBus) Publish(msg *Message) error {
	eb.rm.RLock()
	defer eb.rm.RUnlock()
	if chans := eb.pool[msg.Kind]; len(chans) > 0 {
		eb.log.Debugf("Agent message bus publising message to %d subscribers", len(chans))
		channels := append(chans[:0:0], chans...)
		go func(msg *Message, subscribers Subscribers) {
			for _, s := range subscribers {
				s <- msg
			}
		}(msg, channels)
		return nil
	}
	eb.log.Debugf("Agent message bus publising message: no subscribers for message kind %d ", msg.Kind)
	return NoSubscribersFound
}
func (eb *MessageBus) Subscribe(t MessageType, s Subscriber, size int) {
	eb.rm.Lock()
	defer eb.rm.Unlock()
	ch := make(chan *Message, size)
	if eb.pool[t] != nil {
		eb.pool[t] = append(eb.pool[t], ch)
	} else {
		eb.pool[t] = append(Subscribers{}, ch)
	}
	s.Subscribe(len(eb.pool[t]), ch)
}
func (eb *MessageBus) Unsubscribe(t MessageType, id int) {
	eb.rm.Lock()
	eb.pool[t] = append(eb.pool[t][:id], eb.pool[t][id+1:]...)
	eb.rm.Unlock()
}
type MessageQueue struct {
	size  int
	queue [MAXMESSAGEID]chan *Message
	rm    sync.RWMutex
}
func (mq *MessageQueue) Producer(t MessageType, p Producer) {
	mq.rm.RLock()
	defer mq.rm.RUnlock()
	if mq.queue[t] == nil {
		mq.queue[t] = make(chan *Message, mq.size)
	}
	p.Produce(mq.queue[t])
}