public void StartDlqMonitor([FromBody] StartDlqMonitorModel model) { lock (LOCK_OBJECT) { var function = this.LambdaOptions.LoadLambdaFuntion(model.ConfigFile, model.Function); StopDlqMonitor(); GlobalDlqMonitor = new DlqMonitor(this.LambdaOptions.LambdaRuntime, function, model.Profile, model.Region, model.QueueUrl); GlobalDlqMonitor.Start(); } }
public async Task DlqIntegTest() { const int WAIT_TIME = 5000; var queueName = "local-dlq-list-queue-test-" + DateTime.Now.Ticks; using (var client = new AmazonSQSClient(TestUtils.GetAWSCredentials(), TestUtils.TestRegion)) { var createResponse = await client.CreateQueueAsync(new CreateQueueRequest { QueueName = queueName }); await TestUtils.WaitTillQueueIsCreatedAsync(client, createResponse.QueueUrl); try { var configFile = Path.GetFullPath(@"../../../../LambdaFunctions/ToUpperFunc/aws-lambda-tools-defaults.json"); var buildPath = Path.GetFullPath(@"../../../../LambdaFunctions/ToUpperFunc/bin/debug/netcoreapp2.1"); var configInfo = LambdaDefaultsConfigFileParser.LoadFromFile(configFile); var runtime = LocalLambdaRuntime.Initialize(buildPath); var function = runtime.LoadLambdaFunctions(configInfo.FunctionInfos)[0]; var monitor = new DlqMonitor(runtime, function, TestUtils.TestProfile, TestUtils.TestRegion.SystemName, createResponse.QueueUrl); monitor.Start(); await client.SendMessageAsync(new SendMessageRequest { QueueUrl = createResponse.QueueUrl, MessageBody = "\"testing dlq\"" }); Thread.Sleep(WAIT_TIME); var logs = monitor.FetchNewLogs(); Assert.Single(logs); Assert.Contains("testing dlq", logs[0].Logs); Assert.NotNull(logs[0].ReceiptHandle); Assert.NotEqual(DateTime.MinValue, logs[0].ProcessTime); logs = monitor.FetchNewLogs(); Assert.Equal(0, logs.Count); await client.SendMessageAsync(new SendMessageRequest { QueueUrl = createResponse.QueueUrl, MessageBody = "\"testing dlq1\"" }); await client.SendMessageAsync(new SendMessageRequest { QueueUrl = createResponse.QueueUrl, MessageBody = "\"testing dlq2\"" }); Thread.Sleep(WAIT_TIME); logs = monitor.FetchNewLogs(); Assert.Equal(2, logs.Count); monitor.Stop(); Thread.Sleep(WAIT_TIME); await client.SendMessageAsync(new SendMessageRequest { QueueUrl = createResponse.QueueUrl, MessageBody = "\"testing dlq3\"" }); Thread.Sleep(WAIT_TIME); logs = monitor.FetchNewLogs(); Assert.Equal(0, logs.Count); } finally { await client.DeleteQueueAsync(createResponse.QueueUrl); } } }