Beispiel #1
0
/*
Parse a gilmour *Message and for subscribers of this topic do the following:
	* If subscriber is one shot, unsubscribe the subscriber to prevent subscribers from re-execution.
	* If subscriber belongs to a group, try acquiring a lock via backend to ensure group exclusivity.
	* If all conditions suffice spin up a new goroutine for each subscription.
*/
func (g *Gilmour) processMessage(msg *proto.Packet) {
	subs, ok := g.getSubscribers(msg.GetPattern())
	if !ok || len(subs) == 0 {
		ui.Warn("*Message cannot be processed. No subs found for key %v", msg.GetPattern())
		return
	}

	m, err := parseMessage(msg.GetData())
	if err != nil {
		ui.Alert(err.Error())
		return
	}

	for _, s := range subs {

		opts := s.GetOpts()
		if opts != nil && opts.isOneShot() {
			ui.Message("Unsubscribing one shot response topic %v", msg.GetTopic())
			go g.UnsubscribeReply(msg.GetPattern(), s)
		}

		if opts.GetGroup() != "" && opts.shouldSendResponse() {
			if !g.backend.AcquireGroupLock(opts.GetGroup(), m.GetSender()) {
				ui.Warn(
					"Unable to acquire Lock. Topic %v Group %v Sender %v",
					msg.GetTopic(), opts.GetGroup(), m.GetSender(),
				)
				continue
			}
		}

		go g.handleRequest(s, msg.GetTopic(), m)
	}
}
Beispiel #2
0
func (g *Gilmour) reportError(e *proto.GilmourError) {
	ui.Warn(
		"Reporting Error. Code %v Sender %v Topic %v",
		e.GetCode(), e.GetSender(), e.GetTopic(),
	)

	err := g.backend.ReportError(g.GetErrorPolicy(), e)
	if err != nil {
		panic(err)
	}
}