func (stream *Route) routeMessage(msg core.Message) { for i := 0; i < len(stream.routes); i++ { target := stream.routes[i] // Stream might require late binding if target.stream == nil { if core.StreamRegistry.WildcardProducersExist() { target.stream = core.StreamRegistry.GetStreamOrFallback(target.id) } else if target.stream = core.StreamRegistry.GetStream(target.id); target.stream == nil { // Remove without preserving order allows us to continue iterating lastIdx := len(stream.routes) - 1 stream.routes[i] = stream.routes[lastIdx] stream.routes = stream.routes[:lastIdx] i-- continue // ### continue, no route ### } } if target.id == stream.GetBoundStreamID() { stream.StreamBase.Route(msg, stream.GetBoundStreamID()) } else { msg := msg // copy to allow streamId changes and multiple routes msg.StreamID = target.id target.stream.Enqueue(msg) } } }
func (cons *LoopBack) route(msg core.Message) { if streams, routeExists := cons.routes[msg.StreamID]; routeExists { for targetID, targetStream := range streams { msg.StreamID = targetID targetStream.Enqueue(msg) } } else { // Extend the cache targetStream := cons.addRoute(msg.StreamID, msg.StreamID) targetStream.Enqueue(msg) } }