| 
30 | 30 | // await CreateLinkIndex(new AmazonS3Client());  | 
31 | 31 | 
 
  | 
32 | 32 | #pragma warning disable CS8321 // Local function is declared but never used  | 
33 |  | -static async Task<string> Handler(SQSEvent ev, ILambdaContext context)  | 
 | 33 | +static async Task<SQSBatchResponse> Handler(SQSEvent evnt, ILambdaContext context)  | 
34 | 34 | #pragma warning restore CS8321 // Local function is declared but never used  | 
35 | 35 | {  | 
 | 36 | +	var batchItemFailures = new List<SQSBatchResponse.BatchItemFailure>();  | 
 | 37 | +	foreach(var message in evnt.Records)  | 
 | 38 | +	{  | 
 | 39 | +		try  | 
 | 40 | +		{  | 
 | 41 | +			//process your message  | 
 | 42 | +			await ProcessMessageAsync(message, context);  | 
 | 43 | +		}  | 
 | 44 | +		catch (Exception)  | 
 | 45 | +		{  | 
 | 46 | +			//Add failed message identifier to the batchItemFailures list  | 
 | 47 | +			batchItemFailures.Add(new SQSBatchResponse.BatchItemFailure{ItemIdentifier=message.MessageId});  | 
 | 48 | +		}  | 
 | 49 | +	}  | 
 | 50 | +	return new SQSBatchResponse(batchItemFailures);  | 
36 | 51 | 	// const int maxRetries = 3;  | 
37 | 52 | 	// var retryCount = 0;  | 
38 | 53 | 
 
  | 
39 | 54 | 	// var sw = Stopwatch.StartNew();  | 
40 |  | -	await Task.Delay(100);  | 
41 |  | -	foreach (var record in ev.Records)  | 
42 |  | -	{  | 
43 |  | -		context.Logger.LogInformation($"Received message: {record.Body}");  | 
44 |  | - | 
45 |  | -		// Delete the message from the queue  | 
46 |  | -		var sqsClient = new AmazonSQSClient();  | 
47 |  | -		var deleteMessageRequest = new DeleteMessageRequest(record.EventSourceArn, record.ReceiptHandle);  | 
48 |  | -		_ = await sqsClient.DeleteMessageAsync(deleteMessageRequest);  | 
49 |  | -	}  | 
50 |  | -	return "Done";  | 
 | 55 | +	// await Task.Delay(100);  | 
 | 56 | +	// foreach (var record in ev.Records)  | 
 | 57 | +	// {  | 
 | 58 | +	// 	context.Logger.LogInformation($"Received message: {record.Body}");  | 
 | 59 | +	//  | 
 | 60 | +	// 	// Delete the message from the queue  | 
 | 61 | +	// 	var sqsClient = new AmazonSQSClient();  | 
 | 62 | +	//  | 
 | 63 | +	// }  | 
51 | 64 | 
 
  | 
52 | 65 | 	// while (true)  | 
53 | 66 | 	// {  | 
@@ -102,6 +115,17 @@ static async Task<string> Handler(SQSEvent ev, ILambdaContext context)  | 
102 | 115 | 	// }  | 
103 | 116 | }  | 
104 | 117 | 
 
  | 
 | 118 | +static async Task ProcessMessageAsync(SQSEvent.SQSMessage message, ILambdaContext context)  | 
 | 119 | +{  | 
 | 120 | +	if (string.IsNullOrEmpty(message.Body))  | 
 | 121 | +	{  | 
 | 122 | +		throw new Exception("No Body in SQS Message.");  | 
 | 123 | +	}  | 
 | 124 | +	context.Logger.LogInformation($"Processed message {message.Body}");  | 
 | 125 | +	// TODO: Do interesting work based on the new message  | 
 | 126 | +	await Task.CompletedTask;  | 
 | 127 | +}  | 
 | 128 | + | 
105 | 129 | // static async Task<LinkIndex?> CreateLinkIndex(IAmazonS3 s3Client)  | 
106 | 130 | // {  | 
107 | 131 | // 	var request = new ListObjectsV2Request  | 
 | 
0 commit comments