public RabbitMQBus(string busId = null, string host = null, int port = 0, string exchange = null, bool exactlyOnce = false, MessageFormat messageFormat = MessageFormat.Text, XmlDictionaryReaderQuotas readerQuotas = null, bool mandatory = false) : base(busId) { RabbitMQBusConfigSectionHandler section = ConfigurationManager.GetSection(RabbitMQBusConfigSectionHandler.SectionName) as RabbitMQBusConfigSectionHandler; _host = GetPropertyValue(host, "localhost", section, s => s.BrokerHost); _port = GetPropertyValue(port, 5672, section, s => s.Port); _exchange = GetPropertyValue(exchange, "amq.headers", section, s => s.Exchange); readerQuotas = GetPropertyValue(readerQuotas, null, section, s => new XmlDictionaryReaderQuotas { MaxArrayLength = s.ReaderQuotas.MaxArrayLength, MaxBytesPerRead = s.ReaderQuotas.MaxBytesPerRead, MaxDepth = s.ReaderQuotas.MaxDepth, MaxNameTableCharCount = s.ReaderQuotas.MaxNameTableCharCount, MaxStringContentLength = s.ReaderQuotas.MaxStringContentLength }); _binding = new RabbitMQBinding { ApplicationId = busId, OneWayOnly = true, ExactlyOnce = exactlyOnce, PersistentDelivery = false, HeaderNamespace = MessagingConstants.Namespace.MessageBus, MessageFormat = messageFormat, ReaderQuotas = readerQuotas, Mandatory = mandatory }; }
protected T GetPropertyValue <T>(T value, T defaultValue, RabbitMQBusConfigSectionHandler section, Func <RabbitMQBusConfigSectionHandler, T> selector) { if (!Equals(value, default(T))) { return(value); } if (section == null) { return(defaultValue); } return(selector(section)); }