public string[] GetTopics(Type messageType) { string originalTopic = _messageTypeToTopicProvider.GetTopic(messageType); if (messageType.GetInterfaces().Contains(typeof(IMessageWithRouteIndex))) { return(new[] { originalTopic, string.Format("{0}_1", originalTopic), string.Format("{0}_2", originalTopic), }); } else { return(new[] { originalTopic }); } }
private string GetTopic <T>() { return(_messageTypeToTopicProvider.GetTopic(typeof(T))); }
/// <summary> /// Add message handlers from the specified list of <paramref name="handlerTypes"/>. /// Uses defaults specified in the <see cref="BusConfiguration"/> constructor. /// </summary> /// <param name="handlerTypes">The message handler types to add. Throws if a type is an invalid message handler.</param> private void AddMessageHandlers(IEnumerable <Type> handlerTypes) { if (handlerTypes == null) { throw new ArgumentNullException("handlerTypes"); } foreach (var handlerType in handlerTypes) { List <Type> handlerMessageTypes = null; PopulateHandlerMessagesTypes(handlerType, ref handlerMessageTypes); if (handlerMessageTypes != null && handlerMessageTypes.Count != 0) { if (handlerMessageTypes.Count > 1) { var handlerMessageTypesStrings = handlerMessageTypes.Select(p => string.Format("IHandleMessages<{0}>", p.Name)).ToArray(); var handlesMessageTypes = string.Join(", ", handlerMessageTypesStrings); var errorMessage = string.Format( "Handler '{0}' implements multiple handlers: {1}. Register the IHandleMessages<T> interfaces " + "themselves as handlers and register them with your DI container to resolve to the concrete " + "handler type. This is to prevent the same channel name from unintentionally applying to " + "multiple topics.", handlerType, handlesMessageTypes ); throw new HandlerConfigurationException(errorMessage); } Type messageType = handlerMessageTypes[0]; List <string> topics; if (_messageTopicRouter == null) { string topic; try { topic = _messageTypeToTopicProvider.GetTopic(messageType); } catch (Exception ex) { throw new Exception(string.Format( "Topic for message type '{0}' not registered.", messageType.FullName), ex); } topics = new List <string>(); topics.Add(topic); } else { topics = new List <string>(_messageTopicRouter.GetTopics(messageType)); } string channel; try { channel = _handlerTypeToChannelProvider.GetChannel(handlerType); } catch (Exception ex) { throw new Exception(string.Format( "Channel for handler type '{0}' not registered.", handlerType.FullName), ex); } foreach (var topic in topics) { AddMessageHandler(handlerType, messageType, topic, channel); } } else { throw new Exception(string.Format("Type '{0}' is not a valid message handler", handlerType.FullName)); } } }