Exemple #1
0
// sender pops messages from a queue and sends them.
func (b *broker) sender(sender electron.Sender) {
	q := b.queues.Get(sender.Source())
	for {
		m, ok := <-q
		if !ok { // Queue closed
			return
		}
		if err := sender.SendForget(m); err == nil {
			util.Debugf("%s send: %s", sender, util.FormatMessage(m))
		} else {
			util.Debugf("%s error: %s", sender, err)
			q <- m // Put it back on the queue.
			return
		}
	}
}
Exemple #2
0
// sender pops messages from a queue and sends them.
func (c *connection) sender(sender electron.Sender) {
	q := c.broker.queues.Get(sender.Source())
	for {
		if sender.Error() != nil {
			util.Debugf("%v closed: %v", sender, sender.Error())
			return
		}
		select {

		case m := <-q:
			util.Debugf("%v: sent %v", sender, util.FormatMessage(m))
			sm := sentMessage{m, q}
			c.broker.sent <- sm                    // Record sent message
			sender.SendAsync(m, c.broker.acks, sm) // Receive outcome on c.broker.acks with Value sm

		case <-sender.Done(): // break if sender is closed
			break
		}
	}
}