public IRegister AddQueue(QueueSetting queueSetting) { if (queueSetting == null) { throw new ArgumentNullException(); } lock (List.SyncRoot) { var queueName = queueSetting.Name; var registration = List.SingleOrDefault(i => queueSetting.Name.Equals(i.QueueName, StringComparison.InvariantCultureIgnoreCase) && i.TopicName == queueSetting.TopicName); if (registration == null) { registration = new Registration() { QueueName = queueSetting.Name, TypeMedium = queueSetting.TypeMedium, AutoStartReading = queueSetting.AutoStartReading, TopicName = queueSetting.TopicName }; List.Add(registration); GlobalConfiguration.Configuration.Logger.Info($"Add queue {List.Count} {registration.QueueName} {registration.TypeMedium} {registration.TopicName} {queueSetting.TypeReader} {registration.AutoStartReading}"); registration.AddSubscriberType(queueSetting.TypeReader); } } return(this); }
public IRegister AddQueue <T>(QueueSetting queueSetting, Action <T> predicate) { if (queueSetting == null || predicate == null) { throw new ArgumentNullException(); } lock (List.SyncRoot) { var registration = List.SingleOrDefault(i => i.QueueName.Equals(queueSetting.Name, StringComparison.InvariantCultureIgnoreCase)); if (registration == null) { registration = new Registration() { QueueName = queueSetting.Name, TypeMedium = queueSetting.TypeMedium, AutoStartReading = queueSetting.AutoStartReading }; List.Add(registration); } var subscriber = new AnonymousMessageSubscriber <T>(predicate); registration.AddSubscriber(subscriber); } return(this); }
public static IRegister AddAzureTopicWriter(this IRegister register, string queueName) { var queueSetting = new QueueSetting() { Name = queueName, TypeMedium = typeof(AzureTopicMedium), }; register.AddQueue(queueSetting); return(register); }
public static IRegister AddAzureQueueReader <T>(this IRegister register, string queueName, Action <T> predicate) { var queueSetting = new QueueSetting() { Name = queueName, TypeMedium = typeof(AzureQueueMedium), }; register.AddQueue(queueSetting, predicate); return(register); }
/// <summary> /// Add memory writer /// </summary> /// <param name="register"></param> /// <param name="queueName"></param> /// <returns></returns> public static IRegister AddMemoryWriter(this IRegister register, string queueName) { if (queueName == null || register == null) { throw new ArgumentNullException(); } var queueSetting = new QueueSetting() { Name = queueName, TypeMedium = typeof(InMemoryMedium), }; register.AddQueue(queueSetting); return(register); }
/// <summary> /// Add anonymous memory reader /// </summary> /// <typeparam name="T"></typeparam> /// <param name="register"></param> /// <param name="queueName"></param> /// <param name="predicate"></param> /// <returns></returns> public static IRegister AddMemoryReader <T>(this IRegister register, string queueName, Action <T> predicate) { if (queueName == null || register == null || predicate == null) { throw new ArgumentNullException(); } var queueSetting = new QueueSetting() { Name = queueName, TypeMedium = typeof(InMemoryMedium), }; register.AddQueue <T>(queueSetting, predicate); return(register); }
public IRegister AddFromConfig(string configFileName = null) { string sectionName = "ariane/serviceBus"; Configuration.ServiceBusConfigurationSection section = null; if (configFileName == null) // Default file configuration { section = System.Configuration.ConfigurationManager.GetSection(sectionName) as Configuration.ServiceBusConfigurationSection; if (section == null) { // Check if ariane.config is present with location of current assembly var path = System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location); configFileName = System.IO.Path.Combine(path.TrimEnd('\\'), "ariane.config"); if (!System.IO.File.Exists(configFileName)) { configFileName = null; } } } if (section == null && configFileName != null) { var map = new ExeConfigurationFileMap(); map.ExeConfigFilename = configFileName; var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); section = config.GetSection(sectionName) as Configuration.ServiceBusConfigurationSection; } else { throw new System.Configuration.ConfigurationErrorsException(string.Format("section {0} does not exists", sectionName)); } foreach (Configuration.ServiceBusQueueReaderConfigurationElement item in section.QueueReaders) { if (!item.Enabled) { continue; } Type reader = null; if (!string.IsNullOrWhiteSpace(item.TypeReader)) { reader = Type.GetType(item.TypeReader); if (reader == null) { GlobalConfiguration.Configuration.Logger.Warn("Type {0} reader for servicebus does not exists", item.TypeReader); continue; } } var medium = Type.GetType(item.TypeMedium); if (medium == null) { if (!string.IsNullOrWhiteSpace(item.TypeMedium)) { GlobalConfiguration.Configuration.Logger.Warn("Type {0} medium for servicebus does not exists", item.TypeMedium); continue; } medium = typeof(InMemoryMedium); } var qs = new QueueSetting() { Name = item.QueueName, TypeReader = reader, TypeMedium = medium, AutoStartReading = item.AutoStartReading }; AddQueue(qs); } return(this); }