public void should_set_qos() { const string ProducerConfig = @"<endpoints> <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" lifecycleHandler=""ProducerHandler""> <qos prefetchCount=""8"" /> </endpoint> </endpoints>"; Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>(); var busConfigurator = new BusConfiguration(); busConfigurator.UseRabbitMq(); var section = new XmlEndpointsSection(ProducerConfig); var sut = new AppConfigConfigurator(section, dependencyResoverMock.Object); var result = sut.Configure("producer", busConfigurator); RabbitReceiverOptions rabbitReceiverOptions = ((BusConfiguration)result).ReceiverDefaults as RabbitReceiverOptions; Assert.IsNotNull(rabbitReceiverOptions, "Долны быть установлены настройки получателя."); Maybe <QoSParams> qosMaybe = rabbitReceiverOptions.GetQoS(); Assert.IsTrue(qosMaybe.HasValue, "QoS должен быть установлен."); Assert.AreEqual(8, qosMaybe.Value.PrefetchCount, "Должно быть установлено количество потоков."); }
public WatcherService(AppConfigConfigurator configurator, EventQueue eventQueue) { _configurator = configurator; _eventQueue = eventQueue; _configurator.UpdatedSettingsAvailable += HandleUpdatedSettingsAvailable; InitializeFileWatcher(configurator); }
static void Main() { var configurator = new AppConfigConfigurator(); configurator.Initialize(new ActiveAttributesConfiguration()); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var threadingForm = ObjectFactory.Create <MainForm>(); Application.Run(threadingForm); }
public void should_route_any() { const string ProducerConfig = @"<endpoints> <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" > <dynamic outgoing=""true"" /> </endpoint> </endpoints>"; Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>(); var section = new XmlEndpointsSection(ProducerConfig); var sut = new AppConfigConfigurator(section, dependencyResoverMock.Object); using (var bus = new BusFactory().Create(cfg => sut.Configure("producer", cfg), false)) { Assert.IsTrue(bus.CanRoute(MessageLabel.Any), "Должна быть включена динамическая маршрутизация."); } }
private void InitializeFileWatcher(AppConfigConfigurator configurator) { if (_fileSystemWatcher != null) { _fileSystemWatcher.EnableRaisingEvents = false; _fileSystemWatcher.Dispose(); _fileSystemWatcher = null; } _fileSystemWatcher = new FileSystemWatcher(configurator.PathToWatch, configurator.TestPattern) { IncludeSubdirectories = configurator.IncludeSubdirectories }; _fileSystemWatcher.Changed += HandleFileChanged; _fileSystemWatcher.Created += HandleFileChanged; _fileSystemWatcher.Renamed += HandleFileRenamed; }
public void should_not_be_set_by_default() { const string ProducerConfig = @"<endpoints> <endpoint name=""producer"" connectionString=""amqp://localhost/integration""> </endpoint> </endpoints>"; Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>(); var busConfigurator = new BusConfiguration(); var section = new XmlEndpointsSection(ProducerConfig); var sut = new AppConfigConfigurator(section, dependencyResoverMock.Object); var result = sut.Configure("producer", busConfigurator); ReceiverOptions receiverOptions = ((BusConfiguration)result).ReceiverDefaults; Assert.IsFalse(receiverOptions.GetFaultQueueTtl().HasValue, "Не должно быть установлено время хранения сообщений."); }
public void ShoudUseFaultQueueLimitDefaultIfNotSpecified() { string producerConfig = string.Format( @"<endpoints> <endpoint name=""producer"" connectionString=""{0}""> </endpoint> </endpoints>", this.Url + this.VhostName); var section = new XmlEndpointsSection(producerConfig); var sut = new AppConfigConfigurator(section, (name, type) => null); IBus bus = this.CreateBus(() => new BusFactory().Create(cfg => sut.Configure("producer", cfg), true)); bus.WhenReady.WaitOne(); Testing.Plumbing.Queue queue = this.Broker.GetQueues(this.VhostName).First(q => q.Name == "producer.Fault"); CollectionAssert.IsNotEmpty(queue.Arguments, "У очереди producer.Fault должны быть выставлены свойства."); Assert.IsFalse(queue.Arguments.ContainsKey("x-max-length"), "У очереди producer.Fault не должно быть установлено ограничение на количество сообщений в очереди."); }
public void should_set_queue_ttl() { const string ProducerConfig = @"<endpoints> <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" faultQueueTtl=""10:10:00""> </endpoint> </endpoints>"; Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>(); var busConfigurator = new BusConfiguration(); var section = new XmlEndpointsSection(ProducerConfig); var sut = new AppConfigConfigurator(section, dependencyResoverMock.Object); var result = sut.Configure("producer", busConfigurator); ReceiverOptions receiverOptions = ((BusConfiguration)result).ReceiverDefaults; Assert.IsTrue(receiverOptions.GetFaultQueueTtl().HasValue, "Должно быть установлено время хранения сообщений."); Assert.AreEqual(TimeSpan.Parse("10:10:00"), receiverOptions.GetFaultQueueTtl().Value, "Должно быть устрановлено корректное время хранения."); }
/// <summary> /// The main. /// </summary> /// <param name="args"> /// The args. /// </param> private static void Main(string[] args) { LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(); // super bad resolver DependencyResolverFunc dependencyResolver = (name, type) => new SomeHandler(); var configurator = new AppConfigConfigurator(dependencyResolver); var busFactory = new BusFactory(); IBus consumer = busFactory.Create(cfg => configurator.Configure("Consumer", cfg)); IBus producer = busFactory.Create(cfg => configurator.Configure("Producer", cfg)); using (new Timer(_ => producer.Emit(":msg", new { }), null, 0, 1000)) { Console.ReadKey(false); } producer.Dispose(); consumer.Dispose(); }
public void ShoudUseFaultQueueTtlDefaultIfNotSpecified() { string producerConfig = string.Format( @"<endpoints> <endpoint name=""producer"" connectionString=""{0}""> </endpoint> </endpoints>", this.Url + this.VhostName); var section = new XmlEndpointsSection(producerConfig); var sut = new AppConfigConfigurator(section, (name, type) => null); IBus bus = this.CreateBus(() => new BusFactory().Create(cfg => sut.Configure("producer", cfg), true)); bus.WhenReady.WaitOne(); Testing.Plumbing.Queue queue = this.Broker.GetQueues(this.VhostName).First(q => q.Name == "producer.Fault"); CollectionAssert.IsNotEmpty(queue.Arguments, "У очереди producer.Fault должны быть выставлены свойства."); Assert.IsTrue(queue.Arguments.ContainsKey("x-message-ttl"), "У очереди producer.Fault должно быть установлено время жизни."); Assert.AreEqual((21 * 24 * 60 * 60 * 1000).ToString(), queue.Arguments["x-message-ttl"], "Должно быть установлено время жизни по умолчанию."); }
public void should_be_default() { const string ProducerConfig = @"<endpoints> <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" lifecycleHandler=""ProducerHandler""> </endpoint> </endpoints>"; Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>(); var section = new XmlEndpointsSection(ProducerConfig); var sut = new AppConfigConfigurator(section, dependencyResoverMock.Object); using (var bus = new BusFactory().Create(cfg => sut.Configure("producer", cfg), false)) { RabbitReceiverOptions rabbitReceiverOptions = ((BusConfiguration)bus.Configuration).ReceiverDefaults as RabbitReceiverOptions; Assert.IsNotNull(rabbitReceiverOptions, "Долны быть установлены настройки получателя."); Maybe <QoSParams> qosMaybe = rabbitReceiverOptions.GetQoS(); Assert.IsTrue(qosMaybe.HasValue, "QoS должен быть установлен."); Assert.AreEqual(50, qosMaybe.Value.PrefetchCount, "Должно быть установлено количество потоков."); } }
public void should_set_queue_limit() { const int queueLimit = 100; string producerConfig = string.Format( @"<endpoints> <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" faultQueueLimit=""{0}""> </endpoint> </endpoints>", queueLimit); Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>(); var busConfigurator = new BusConfiguration(); var section = new XmlEndpointsSection(producerConfig); var sut = new AppConfigConfigurator(section, dependencyResoverMock.Object); var result = sut.Configure("producer", busConfigurator); ReceiverOptions receiverOptions = ((BusConfiguration)result).ReceiverDefaults; Assert.IsTrue(receiverOptions.GetFaultQueueLimit().HasValue, "Должно быть установлено максимальное количество сообщений."); Assert.AreEqual(queueLimit, receiverOptions.GetFaultQueueLimit().Value, "Должно быть устрановлено корректное максимальное количество сообщений."); }
public void should_set_parallelismLevel() { const string ProducerConfig = @"<endpoints> <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" parallelismLevel=""8""> <qos prefetchCount=""8"" /> </endpoint> </endpoints>"; Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>(); var busConfigurator = new BusConfiguration(); busConfigurator.UseRabbitMq(); var section = new XmlEndpointsSection(ProducerConfig); var sut = new AppConfigConfigurator(section, dependencyResoverMock.Object); var result = sut.Configure("producer", busConfigurator); ReceiverOptions receiverOptions = ((BusConfiguration)result).ReceiverDefaults; Assert.IsTrue(receiverOptions.GetParallelismLevel().HasValue, "Должно быть установлено количество обработчиков."); Assert.AreEqual(8, receiverOptions.GetParallelismLevel().Value, "Должно быть установлено количество обработчиков."); }
private static void Main() { try { FileLogWriter logWriter = null; IConfigManager config = new AppConfigConfigurator(); bool interactiveConsole = config.GetSettingAsInt("interactive_console", 0) == 1; if (config.GetSettingAsInt("log_to_console", 0) == 0) { if (config.GetSettingAsInt("overwrite_log_file", 0) == 1) { logWriter = new FileLogWriter( Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "logs"), "TrackCycle.log") { LogWithTimestamp = true }; } else { logWriter = new FileLogWriter( Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "logs"), DateTime.UtcNow.ToString("yyyyMMdd_HHmmss") + "_Startup.log") { LogWithTimestamp = true }; } } try { trackCycler = new TrackCyclePlugin(); AcServerPluginManager pluginManager = new AcServerPluginManager(logWriter, config); pluginManager.LoadInfoFromServerConfig(); pluginManager.AddPlugin(trackCycler); pluginManager.LoadPluginsFromAppConfig(); if (!MonoHelper.IsLinux) { // Some boilerplate to react to close window event, CTRL-C, kill, etc _handler += new EventHandler(Handler); SetConsoleCtrlHandler(_handler, true); } trackCycler.StartServer(); Console.Out.WriteLine("Server running..."); if (interactiveConsole) { Console.Out.WriteLine("Write 'next_track' to cycle to the next track."); Console.Out.WriteLine("Write 'exit' to shut the server down."); } while (true) { if (interactiveConsole) { string line = Console.ReadLine(); if (line.ToLower() == "exit") { break; } else if (line.ToLower() == "next_track") { trackCycler.NextTrackAsync(true); } else { pluginManager.BroadcastChatMessage(line); } } else { Thread.Sleep(500); } } trackCycler.StopServer(); } catch (Exception ex) { if (logWriter != null) { logWriter.Log(ex); } else { throw; } } if (logWriter != null) { logWriter.StopLoggingToFile(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { if (args.Length < 1) { ShowUsage(); return; } try { var exchange_letters = string.Empty; var configurator = new AppConfigConfigurator(); var bus = new BusFactory().Create( cfg => { configurator.Configure("Letters.Sender", cfg); exchange_letters = configurator.GetEvent("Letters.Sender", "letter.send"); }); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); var girls = ConfigurationManager.AppSettings["lady-user-ids"].Split(','); IList <long> girlUserIds = new List <long>(); foreach (var girl in girls) { girlUserIds.Add(Convert.ToInt64(girl)); } if (args.Length > 1) { for (int i = 1; i < args.Length; i++) { girlUserIds.Add(Convert.ToInt64(args[i])); } } int total_letter_count = girlUserIds.Count * (Convert.ToInt32(ConfigurationManager.AppSettings["letter-count-each-lady"].ToString())); log.Debug(m => m($"Пытаемся отправить [{total_letter_count.ToString()}] писем")); for (int i = 0; i < Convert.ToInt32(ConfigurationManager.AppSettings["letter-count-each-lady"].ToString()); i++) { foreach (var girl in girlUserIds) { var letter_request = new SendLetterRequest() { FromId = girl, ToId = Convert.ToInt64(args[0]), Type = i == 0 ? "FirstReply" : "Common", Body = $"Hi there. this is a [{(i == 0 ? "FirstReply" : "Common")}] letter that you should see in a digest notification if all goes well.... " + Environment.NewLine + Regex.Replace(Guid.NewGuid().ToString(), @"\d+", "") }; log.Info(m => m($"Сгенерирован запрос на отправку письма: [{letter_request.ToString()}]")); try { bus.Request <SendLetterRequest, SendLetterResponse>( exchange_letters, letter_request, letter_response => { log.Info(m => m($"Ответ на команду отправки письма: [Status: [{letter_response.Status}], ErrorMessage: [{letter_response.ErrorMessage}]]")); }); } catch (Exception e) { log.Error(m => m(e.ToString())); } } } bus.Dispose(); } catch (Exception e) { log.Error(m => m(e.ToString())); } }