public QueueProcessor( ConnectionFactory queueConnectionFactory, ILogger <IQueueProcessor> logger, IRiverFlowProcessor riverFlowProcessor, IMetrics metrics, IOptions <QueueConfig> queueOptions) { this.queueConnectionFactory = queueConnectionFactory; this.queueConnectionFactory.DispatchConsumersAsync = true; this.logger = logger; this.riverFlowProcessor = riverFlowProcessor; this.metrics = metrics; this.queueConfig = queueOptions.Value.Validate(); this.queueProcessTimer = new TimerOptions { Name = "Queue Processing Timer", MeasurementUnit = App.Metrics.Unit.Calls, DurationUnit = TimeUnit.Seconds, RateUnit = TimeUnit.Minutes }; this.failureCounter = new CounterOptions { Name = "Queue Processing Failures", MeasurementUnit = App.Metrics.Unit.Errors, ReportItemPercentages = true }; }
public void SimpleTest() { QueueConfig config = new QueueConfig() { QueueDirectory = @"d:\workspace\data\test-queue", DataConverter = new ObjectConverter(), QueueName = "test01" }; TestObject t1 = new TestObject() { Str = "t1-str", Num = 123, Flo = 1.3234f, To = new TestObject() { Str = "t2-str", Num = 35654, Flo = 4935.2394f, } }; IFileQueue <TestObject> fq = FileQueue <TestObject> .Create(config); fq.Enqueue(t1); TestObject t2 = fq.Dequeue(); Assert.AreEqual(t1.Str, t2.Str); Assert.AreEqual(t1.Num, t2.Num); Assert.AreEqual(t1.Flo, t2.Flo); Assert.AreEqual(t1.To.Str, t2.To.Str); Assert.AreEqual(t1.To.Num, t2.To.Num); Assert.AreEqual(t1.To.Flo, t2.To.Flo); }
private IMessageQueue CreateQueue(string exchangeType, QueueConfig queueConfig, string routingKey, IDictionary <string, object> routingHeaders) { if (queueConfig == null) { throw new ArgumentNullException("queueConfig"); } // В момент создания очереди точка обмена уже должна существовать. Если ее нет, то возможны два варианта - менее вероятный и наиболее // вероятный. Менее вероятный вариант, когда пытаются создать очередь, не создав предварительно точку обмена. Наиболее вероятный вариант, // когда перед созданием очереди сервер RabbitMq был перезапущен, а точка обмена была создана только на время работы сервера RabbitMq. // Код ниже проверяет существование точки обмена и, если ее нет, создает точку обмена, которая по типу обмена и времени жизни совпадает // с типом обмена и временем жизни создаваемой очереди. Подобное волевое решение основано на высокой вероятности того, что время жизни // очереди совпадает с временем жизни точки обмена. Таким образом, обеспечивается высокая устойчивость к перезапускам сервера RabbitMq. try { ExecuteAnotherChannel(channel => channel.ExchangeDeclarePassive(queueConfig.ExchangeName)); } catch { ExecuteAnotherChannel(channel => channel.ExchangeDeclare(queueConfig.ExchangeName, exchangeType, queueConfig.QueueDurable, false, null)); } _channel.BasicQos((uint)queueConfig.QueuePrefetchSize, (ushort)queueConfig.QueuePrefetchCount, false); _channel.QueueDeclare(queueConfig.QueueName, queueConfig.QueueDurable, false, false, null); _channel.QueueBind(queueConfig.QueueName, queueConfig.ExchangeName, routingKey ?? string.Empty, routingHeaders); var consumer = new QueueingBasicConsumer(_channel); _channel.BasicConsume(queueConfig.QueueName, false, queueConfig.QueueConsumerId ?? string.Empty, consumer); return(new RabbitMqQueue(_channel, consumer.Queue, _messageConverter)); }
static void Main(string[] args) { DirectRabbitMQTest.test(); return; var config = new QueueConfig(); //config.UseRabbitMQ("127.0.0.1", "guest", "guest"); //config.UseRedis("[email protected]:6389"); config.UseMongoDb("mongodb://*****:*****@127.0.0.1:27017/test"); var client = new Publisher(config); client.Publish("timeTest", DateTime.Now); var subService = new SubscribeService(config); //注册方式订阅 //subService.Register(System.Reflection.Assembly.GetAssembly(typeof(SubscribeTest))); //subService.StartSubscribe(); //手动指定订阅 subService.StartSubscribe <List <DateTime> >(new SubscribeAttribute("timeTest"), b => { Console.WriteLine(b); }); label1: client.Publish("timeTest", DateTime.Now); client.Publish("intTest", DateTime.Now.Second); var n = client.GetQueueLength("timeTest"); Console.WriteLine("send ok " + n); Console.ReadLine(); goto label1; }
public void DequeueTimeoutTest() { int timeout = 5000; QueueConfig config = new QueueConfig() { QueueDirectory = @"d:\workspace\data\test-queue", DataConverter = new ObjectConverter(), QueueName = "test04", DequeueTimeoutMilliseconds = timeout }; IFileQueue <string> fq = FileQueue <string> .Create(config); DateTime s = DateTime.Now; try { fq.Dequeue(); Assert.Fail(); } catch (DequeueTimeoutException e) { if (DateTime.Now - s < TimeSpan.FromMilliseconds(timeout)) { Assert.Fail(); } else { Assert.IsFalse(e.IsBroken); } } }
static void Main(string[] args) { Console.WriteLine($"Startup state is {Caffe.InitCaptcha("./deploy.prototxt", ConfigurationManager.AppSettings["Caffemodel"], "./label-map.txt", -1, 32)}"); // Bind unity container UnityConfig.Configure(); FillUnityContainer(); // Bind message source MessageSourceConfig.Configure(LocalDiscernService, LzRemoteDiscernService, RkRemoteDiscernService); //MessageSourceConfig.Configure(LocalReportMessageService, LzReportMessageService, RkReportMessageService); // Bind receive messsages callback method QueueConfig.StartupMessageReceive(MultiQueue.Captcha, ReceiveMessageService.OnMessage); // Bind report error messsages callback method //QueueConfig.StartupMessageReceive(MultiQueue.Report, ReportMessageService.OnMessage); #region print some messages Console.WriteLine("Please enter \"exit\" to exit the system safely."); var cmdLine = string.Empty; do { cmdLine = Console.ReadLine(); } while (cmdLine != "exit"); QueueConfig.Close(); #endregion }
public CustomerCreatedSubscription(QueueConfig config, Func <IShoppingCartService> service, Func <IShoppingCartRepository> repo) : base(config, "customercreated", "customercreatedsubscription") { this.serviceFunc = service; this.repoFunc = repo; RegisterForMessages(Handle); }
public static void Main(string[] args) { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); var rabbitSettings = configuration.GetSection("rabbitmq-settings"); var config = new QueueConfig { HostName = rabbitSettings["hostName"], UserName = rabbitSettings["userName"], Password = rabbitSettings["password"], QueueName = rabbitSettings["sendQueue"] }; DisplayRabbitSettings(config); Console.WriteLine("Starting Employee Service Queue Processor...."); Console.WriteLine(); var processor = new QueueProcessor(config); processor.Start(); }
public void ArrangeConsumer() { _correlationId = Guid.NewGuid(); _queueName = Guid.NewGuid().ToString(); _handler = _fixture.Freeze <IMessageHandler>(); _handler .Expect(f => f.Handle(Arg <BasicDeliverEventArgs> .Matches(a => a.BasicProperties.CorrelationId == _correlationId.ToString()))) .Repeat .Once(); var queue = new QueueConfig(_queueName, new RoutingConfig(string.Empty), ExchangeConfig.Default, false, true, true, null); using (var channel = _modelFactory.CreateModel()) { channel.DeclareAndBindQueue(queue); } _sut = new WhiteRabbitConsumer(_handler, _modelFactory, _queueName, (_, __) => { }); Task.Run(() => _sut.Start(true)); Task.Delay(TimeSpan.FromSeconds(2)).Wait(); }
public void StartDispatcher(QueueConfig queueConfig) { var channel = _channelProvider.CreateChannel(queueConfig); var incomingMsg = new MessageReceiver(channel, queueConfig.QueueName); var subscription = incomingMsg.SubscribeOn(NewThreadScheduler.Default).Retry().Subscribe(DispatchMessage, OnError); _msgSubscriptions.Add(subscription); }
public void ShouldSetName() { // When var target = new QueueConfig(ExchangeName, QueueName); // Then Assert.AreEqual(ExchangeName, target.ExchangeName); Assert.AreEqual(QueueName, target.QueueName); }
public QueuePublisher( ConnectionFactory queueConnectionFactory, ILogger <IQueuePublisher> logger, IOptions <QueueConfig> queueOptions) { this.queueConnectionFactory = queueConnectionFactory; this.logger = logger; this.queueConfig = queueOptions.Value.Validate(); }
/// <summary> /// AddQueue adds a given queue config to the general bucket notification config /// </summary> /// <param name="queueConfig"></param> public void AddQueue(QueueConfig queueConfig) { var isQueueFound = QueueConfigs.Exists(t => t.Equals(queueConfig)); if (!isQueueFound) { QueueConfigs.Add(queueConfig); } }
public void TestQueueConfigEquality() { QueueConfig config1 = new QueueConfig("somerandomarnstring"); QueueConfig config2 = new QueueConfig("somerandomarnstring"); QueueConfig config3 = new QueueConfig("blah"); Assert.IsFalse(new QueueConfig().Equals(null)); Assert.IsTrue(config1.Equals(config2)); Assert.IsFalse(config1.Equals(config3)); }
internal MessageQueue(QueueConfig config) { if (config != null) { _enabled = config.Enabled; _itemsPerDequeue = config.ItemsPerDequeue; _maxCount = config.MaxCount; } }
internal MessageQueue(QueueConfig config) { if (config != null) { _enabled = config.Enabled; _itemsPerDequeue = config.ItemsPerDequeue; _maxCount = config.MaxCount; } }
public void TestQueueConfigEqualsOverride() { QueueConfig config1 = new QueueConfig("somerandomarnstring"); QueueConfig config2 = new QueueConfig("somerandomarnstring"); QueueConfig config3 = new QueueConfig("blah"); List<QueueConfig> qConfigs = new List<QueueConfig> { config1, config2 }; Assert.IsTrue(qConfigs.Exists(t => t.Equals(config1))); Assert.IsFalse(qConfigs.Exists(t => t.Equals(config3))); }
private static void DisplayRabbitSettings(QueueConfig config) { Console.WriteLine("*********************"); Console.WriteLine("Host: {0}", config.HostName); Console.WriteLine("Username: {0}", config.UserName); Console.WriteLine("QueueName: {0}", config.QueueName); Console.WriteLine("*********************"); Console.WriteLine(); }
public MongoDb(QueueConfig queueConfig) { _queueConfig = queueConfig; var ConnStr = queueConfig.ConnString; var lastIndex = ConnStr.LastIndexOf("/"); var DatabaseName = ConnStr.Substring(lastIndex + 1);//like mongodb://localhost:27017/db1 var client = new MongoClient(ConnStr); database = client.GetDatabase(DatabaseName); }
internal void ReloadConfig(QueueConfig config) { if (config != null) { _itemsPerDequeue = config.ItemsPerDequeue; _maxCount = config.MaxCount; _enabled = config.Enabled; //do this last so if it's switching on for the first time //the settings will be in place when it starts up } }
internal void ReloadConfig(QueueConfig config) { if (config != null) { _itemsPerDequeue = config.ItemsPerDequeue; _maxCount = config.MaxCount; _enabled = config.Enabled; //do this last so if it's switching on for the first time //the settings will be in place when it starts up } }
public void TestQueueConfigRemoveElement() { QueueConfig config1 = new QueueConfig("somerandomarnstring"); QueueConfig config2 = new QueueConfig("somerandomarnstring"); QueueConfig config3 = new QueueConfig("blah"); List<QueueConfig> qConfigs = new List<QueueConfig> { config1, config2, config3 }; var numRemoved = qConfigs.RemoveAll(t => t.Equals(config3)); Assert.IsTrue(numRemoved == 1); numRemoved = qConfigs.RemoveAll(t => t.Equals(new QueueConfig("notpresentinlist"))); Assert.IsTrue(numRemoved == 0); }
/// <summary> /// 获得一个通道 /// </summary> /// <param name="connection">连接对象</param> /// <param name="queueConfig">队列配置</param> /// <returns></returns> public virtual IModel GetChannel(IConnection connection, QueueConfig queueConfig) { IModel channel = connection.CreateModel(); if (queueConfig.Durable) { IBasicProperties properties = channel.CreateBasicProperties(); properties.Persistent = true; } return(channel); }
public Startup(IConfiguration configuration, IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", true, true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true) .AddEnvironmentVariables(); Configuration = builder.Build(); this.qConfig = new QueueConfig(); Configuration.Bind("Queue", qConfig); }
/// <summary> /// Создает очередь для приема сообщений /// </summary> /// <param name="queueConfig">Параметры создания очереди</param> /// <returns>True, если очередь была создана, false если возвращена уже существующая очередь</returns> public IInputQueue GetOrAddInputQueue(QueueConfig queueConfig) { if (!this.InputQueues.TryGetValue(queueConfig.Name, out var inputQueue)) { inputQueue = new InputQueue(); inputQueue.Init(this, queueConfig); this.inputQueues.Add(queueConfig.Name, inputQueue); } return(inputQueue); }
public void ShouldSetDurable() { // Given var target = new QueueConfig(ExchangeName, QueueName); var config = (IQueueConfig)target; // When config.Durable(); // Then Assert.IsTrue(target.QueueDurable); }
/// <summary> /// Создает очередь для отправки сообщений /// </summary> /// <param name="queueConfig">Параметры создания очереди</param> /// <returns>True, если очередь была создана, false если возвращена уже существующая очередь</returns> public IOutputQueue GetOrAddOutputQueue(QueueConfig queueConfig) { if (!this.OutputQueues.TryGetValue(queueConfig.Name, out var outputQueue)) { outputQueue = new OutputQueue(); outputQueue.Init(this, queueConfig); this.outputQueues.Add(queueConfig.Name, outputQueue); } return(outputQueue); }
private void InitConfig(ChannelConfig?channelConfig) { _channelConfig = channelConfig ?? new ChannelConfig { AutoAck = false, PrefetchSize = 0, PrefetchCount = 1 }; _defaultQueueConfig = new QueueConfig { Durable = false }; }
private static QueueConfig GetQueueConfig() { var result = new QueueConfig("Exchange1", "Queue1"); IQueueConfig config = result; config.ConsumerId("Consumer1") .PrefetchCount(10) .WorkerThreadCount(2) .MinListenTime(60000); return(result); }
/// <summary> /// Выполняет инициализацию очереди /// </summary> /// <param name="connection">Соединение, которому принадлежит очередь</param> /// <param name="initialConfig">Конфигурация очереди</param> public override void Init(IRabbitMqConnection connection, QueueConfig initialConfig) { base.Init(connection, initialConfig); this.DeclareQueue(); this.consumer = new AsyncEventingBasicConsumer(this.Connection.Channel); this.consumer.Received += this.RabbitEventHandlerAsync; lock (this.Connection) { this.Connection.Channel.BasicConsume(this.InitialConfig.Name, false, this.consumer); } }
public void ShouldSetPrefetchCount() { // Given var target = new QueueConfig(ExchangeName, QueueName); var config = (IQueueConfig)target; const int value = 12345; // When config.PrefetchCount(value); // Then Assert.AreEqual(value, target.QueuePrefetchCount); }
public void ShouldSetConsumerError() { // Given var target = new QueueConfig(ExchangeName, QueueName); var config = (IQueueConfig)target; Action <Exception> value = error => { }; // When config.ConsumerError(value); // Then Assert.AreEqual(value, target.QueueConsumerError); }