public void AddHandler_GetHandlersByMessage() { var subject = new HandlerRepository(); subject.AddHandler(typeof(MessageFake), typeof(FakeHandler)); var handlers = subject.GetHandlersByMessage(typeof(MessageFake)); Assert.IsTrue(handlers.Count(x => x == typeof(FakeHandler)) == 1); }
/// <summary> /// Messages the received. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The args.</param> protected virtual void MessageReceived(object sender, OutputGatewayEventHandlerArgs <TMessage, MessageHeader> args) { InvokeOnMessageReceived(); if (args.Header.CallContext != null && args.Header.CallContext.ContainsKey("DEBUG_MESSAGE")) { Logger.Warn(string.Format("Ha llegado el Mensaje:{0}", args.SerializedMessage)); Logger.Warn(string.Format("Tipo del Mensaje:{0}", args.Header.BodyType)); } Session currentSession = SessionFactory.Create(); if (args.Header.Type == MessageBusType.Reply) { CallerContext requester = args.Header.CallStack.Pop(); if (requester.Identification.Equals(Identification)) { currentSession = requester.Session; } else { Logger.Debug("Reply Message not mine"); return; } } var listTask = new List <Thread>(); //Buscar en los handlers para procesar el mensaje foreach (Type type in HandlerRepository.GetHandlersByMessage(args.Message.GetType())) { Type typeClosure = type; var th = new Thread(() => ExecuteHandler(args, typeClosure, currentSession)); th.Start(); listTask.Add(th); } foreach (var thread in listTask) { thread.Join(TimeSpan.FromMinutes(3)); } }