static void Main(string[] args) { var queueClientFactory = new QueueClientFactory("ServiceBusConnectionString"); var server = new AzureMessageService(queueClientFactory); var settings = new MessageHandlerSettings { NoOfThreads = 2, NoOfRetries = 3, IntervalBetweenRetries = TimeSpan.FromSeconds(2), DuplicateIntervalWithEachRetry = true }; server.RegisterHandler <GreetSampleMessage>(x => { var greet = x.GetBody(); Console.WriteLine("Message from client: " + greet.Text); return(null); }, settings); server.Start(); Console.WriteLine("Server started and waiting for messages from clients. To stop server press enter key."); Console.ReadLine(); server.Dispose(); }
static void Main(string[] args) { var queueClientFactory = new QueueClientFactory("ServiceBusConnectionString"); var server = new AzureMessageService(queueClientFactory); var settings = new MessageHandlerSettings { NoOfThreads = 2, NoOfRetries = 3, IntervalBetweenRetries = TimeSpan.FromSeconds(2), DuplicateIntervalWithEachRetry = true }; server.RegisterHandler<GreetSampleMessage>(x => { var greet = x.GetBody(); Console.WriteLine("Message from client: " + greet.Text); return null; }, settings); server.Start(); Console.WriteLine("Server started and waiting for messages from clients. To stop server press enter key."); Console.ReadLine(); server.Dispose(); }
static void Main(string[] args) { var queueClientFactory = new QueueClientFactory("ServiceBusConnectionString"); var clientFactory = new AzureMessageClientFactory(queueClientFactory); var client = clientFactory.CreateMessageQueueClient(); string lineText; Console.WriteLine("Client started. To stop client press escape key."); Console.Write("Send message to server: "); while (TryReadLine(out lineText)) { Console.WriteLine(); Console.Write("Send message to server: "); client.Publish(new GreetSampleMessage { Text = lineText }); } }
public void Should_Delay_Message_Processing() { var queueClientFactory = new QueueClientFactory(ConnectionStringName); var server = new AzureMessageService(queueClientFactory); var client = server.MessageFactory.CreateMessageQueueClient(); var callCount = 0; var settings = new MessageHandlerSettings { NoOfThreads = 1, NoOfRetries = 1, IntervalBetweenRetries = TimeSpan.FromSeconds(40), //Actual interval may be different if client and Azure Service Bus times are not synchronized. DuplicateIntervalWithEachRetry = false }; server.RegisterHandler <DelayTestMessage>(x => { callCount++; Trace.Write("GreetWorldDelayTestMessage: " + x.GetBody().Name + " " + callCount + " " + DateTime.Now.ToLongTimeString()); if (callCount == 1) { Trace.WriteLine(" (simulated fail)"); throw new Exception("Test Exception"); } Trace.WriteLine(" (succeed)"); return(null); }, settings); server.Start(); client.Publish(new DelayTestMessage { Name = "Delayed message" }); Thread.Sleep((int)TimeSpan.FromSeconds(45).TotalMilliseconds); Assert.That(server.GetStats().TotalMessagesProcessed, Is.EqualTo(2)); Assert.That(callCount, Is.EqualTo(2)); server.Dispose(); }
public void Does_Process_All_Published_Messages() { var queueClientFactory = new QueueClientFactory(ConnectionStringName); var server = new AzureMessageService(queueClientFactory); var client = server.MessageFactory.CreateMessageQueueClient(); var handlerCallCount = 0; var settings = new MessageHandlerSettings { NoOfThreads = 1, NoOfRetries = 1, IntervalBetweenRetries = TimeSpan.FromSeconds(10), DuplicateIntervalWithEachRetry = true }; server.RegisterHandler <GreetTestMessage>(x => { handlerCallCount++; Trace.WriteLine("GreetTestMessage: " + x.GetBody().Name); return(null); }, settings); server.Start(); client.Publish(new GreetTestMessage { Name = "1" }); client.Publish(new GreetTestMessage { Name = "2" }); client.Publish(new GreetTestMessage { Name = "3" }); client.Publish(new GreetTestMessage { Name = "4" }); Thread.Sleep(3000); Assert.That(server.GetStats().TotalMessagesProcessed, Is.EqualTo(4)); Assert.That(handlerCallCount, Is.EqualTo(4)); server.Dispose(); }
public void Should_Delay_Message_Processing() { var queueClientFactory = new QueueClientFactory(ConnectionStringName); var server = new AzureMessageService(queueClientFactory); var client = server.MessageFactory.CreateMessageQueueClient(); var callCount = 0; var settings = new MessageHandlerSettings { NoOfThreads = 1, NoOfRetries = 1, IntervalBetweenRetries = TimeSpan.FromSeconds(40), //Actual interval may be different if client and Azure Service Bus times are not synchronized. DuplicateIntervalWithEachRetry = false }; server.RegisterHandler<DelayTestMessage>(x => { callCount++; Trace.Write("GreetWorldDelayTestMessage: " + x.GetBody().Name + " " + callCount + " " + DateTime.Now.ToLongTimeString()); if (callCount == 1) { Trace.WriteLine(" (simulated fail)"); throw new Exception("Test Exception"); } Trace.WriteLine(" (succeed)"); return null; }, settings); server.Start(); client.Publish(new DelayTestMessage { Name = "Delayed message" }); Thread.Sleep((int)TimeSpan.FromSeconds(45).TotalMilliseconds); Assert.That(server.GetStats().TotalMessagesProcessed, Is.EqualTo(2)); Assert.That(callCount, Is.EqualTo(2)); server.Dispose(); }
static async Task Main(string[] args) { var configurationManager = new ConfigurationManager(args); var configuration = ConfigurationValues.GetFromConfigurationManager(configurationManager); IQueueClient queueClient = QueueClientFactory.GetQueueClientFromConnectionString(configuration.Queue.ConnectionString); KubeClient kubeClient; if (String.IsNullOrWhiteSpace(configuration.Kubernetes.KubeConfig)) { kubeClient = new KubeClient(); } else { kubeClient = new KubeClient(configuration.Kubernetes.KubeConfig); } IScalingRule scalingRule = new IncrementRule(new TimeSpan(0, 1, 0)); await CheckQueue(queueClient, kubeClient, scalingRule, configuration, configurationManager); }
public void Should_Check_Dead_Letter_Queue() { var queueClientFactory = new QueueClientFactory(ConnectionStringName); var server = new AzureMessageService(queueClientFactory); var settings = new MessageHandlerSettings { NoOfThreads = 1, NoOfRetries = 1, IntervalBetweenRetries = TimeSpan.FromSeconds(0), DuplicateIntervalWithEachRetry = false }; server.RegisterHandler <DeadLetterTestMessage>(x => { throw new Exception("Simulated fail"); }, settings); server.Start(); var client = server.MessageFactory.CreateMessageQueueClient(); client.Publish(new DeadLetterTestMessage { Name = "test" }); Thread.Sleep(1000); var deadMessages = AzureMessageService.GetDeadLetteredMessages <DeadLetterTestMessage>(ConnectionStringName, deleteAfterReceiving: false); Assert.That(deadMessages.Count, Is.GreaterThan(0)); var deadMessages2 = AzureMessageService.GetDeadLetteredMessages <DeadLetterTestMessage>(ConnectionStringName); Assert.That(deadMessages2.Count, Is.EqualTo(deadMessages.Count)); server.Dispose(); }
public void Does_Process_All_Published_Messages() { var queueClientFactory = new QueueClientFactory(ConnectionStringName); var server = new AzureMessageService(queueClientFactory); var client = server.MessageFactory.CreateMessageQueueClient(); var handlerCallCount = 0; var settings = new MessageHandlerSettings { NoOfThreads = 1, NoOfRetries = 1, IntervalBetweenRetries = TimeSpan.FromSeconds(10), DuplicateIntervalWithEachRetry = true }; server.RegisterHandler<GreetTestMessage>(x => { handlerCallCount++; Trace.WriteLine("GreetTestMessage: " + x.GetBody().Name); return null; }, settings); server.Start(); client.Publish(new GreetTestMessage { Name = "1" }); client.Publish(new GreetTestMessage { Name = "2" }); client.Publish(new GreetTestMessage { Name = "3" }); client.Publish(new GreetTestMessage { Name = "4" }); Thread.Sleep(3000); Assert.That(server.GetStats().TotalMessagesProcessed, Is.EqualTo(4)); Assert.That(handlerCallCount, Is.EqualTo(4)); server.Dispose(); }
public void Should_Check_Dead_Letter_Queue() { var queueClientFactory = new QueueClientFactory(ConnectionStringName); var server = new AzureMessageService(queueClientFactory); var settings = new MessageHandlerSettings { NoOfThreads = 1, NoOfRetries = 1, IntervalBetweenRetries = TimeSpan.FromSeconds(0), DuplicateIntervalWithEachRetry = false }; server.RegisterHandler<DeadLetterTestMessage>(x => { throw new Exception("Simulated fail"); }, settings); server.Start(); var client = server.MessageFactory.CreateMessageQueueClient(); client.Publish(new DeadLetterTestMessage { Name = "test" }); Thread.Sleep(1000); var deadMessages = AzureMessageService.GetDeadLetteredMessages<DeadLetterTestMessage>(ConnectionStringName, deleteAfterReceiving: false); Assert.That(deadMessages.Count, Is.GreaterThan(0)); var deadMessages2 = AzureMessageService.GetDeadLetteredMessages<DeadLetterTestMessage>(ConnectionStringName); Assert.That(deadMessages2.Count, Is.EqualTo(deadMessages.Count)); server.Dispose(); }