diff --git a/BookingQueueSubscriber/BookingQueueSubscriber.UnitTests/packages.lock.json b/BookingQueueSubscriber/BookingQueueSubscriber.UnitTests/packages.lock.json index 2ea76888..339c7dda 100644 --- a/BookingQueueSubscriber/BookingQueueSubscriber.UnitTests/packages.lock.json +++ b/BookingQueueSubscriber/BookingQueueSubscriber.UnitTests/packages.lock.json @@ -136,6 +136,25 @@ "System.Memory.Data": "1.0.2" } }, + "Azure.Storage.Common": { + "type": "Transitive", + "resolved": "12.11.0", + "contentHash": "BPZ1JwYvehHGoTSXhXfAmwtFYejJghE6dkKvpZtPIL0DulzSIJdll9OZI+h5W+3wLYK0yn5hc1r6mvId0q4npA==", + "dependencies": { + "Azure.Core": "1.24.0", + "System.IO.Hashing": "6.0.0" + } + }, + "Azure.Storage.Queues": { + "type": "Transitive", + "resolved": "12.10.0", + "contentHash": "RD+rDy2O763jJXpvaOd03I3NSIrGpjq5YPzVkPydXnhMIzvjrv3X6ogDl+QgZs1ssuRcqjCh0RBvaaW6tt2EYw==", + "dependencies": { + "Azure.Storage.Common": "12.11.0", + "System.Memory.Data": "1.0.2", + "System.Text.Json": "4.7.2" + } + }, "BookingsApi.Client": { "type": "Transitive", "resolved": "2.3.10", @@ -615,6 +634,16 @@ "Microsoft.Extensions.Azure": "1.2.0" } }, + "Microsoft.Azure.WebJobs.Extensions.Storage.Queues": { + "type": "Transitive", + "resolved": "5.0.1", + "contentHash": "NCNMBtMOdKreEriYYLhnL1BpYwn8x1bhYAMbB7qadEvyobFyQ4j0z877TDq6S03l0aZRi3WL9XhkeiubRxneZA==", + "dependencies": { + "Azure.Storage.Queues": "12.10.0", + "Microsoft.Azure.WebJobs": "3.0.32", + "Microsoft.Extensions.Azure": "1.1.1" + } + }, "Microsoft.Azure.WebJobs.Host.Storage": { "type": "Transitive", "resolved": "3.0.14", @@ -1550,6 +1579,11 @@ "System.Runtime": "4.3.0" } }, + "System.IO.Hashing": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "Rfm2jYCaUeGysFEZjDe7j1R4x6Z6BzumS/vUT5a1AA/AWJuGX71PoGB0RmpyX3VmrGqVnAwtfMn39OHR8Y/5+g==" + }, "System.Linq": { "type": "Transitive", "resolved": "4.3.0", @@ -2287,6 +2321,7 @@ "Microsoft.AspNetCore.Hosting": "[2.2.7, )", "Microsoft.Azure.WebJobs": "[3.0.33, )", "Microsoft.Azure.WebJobs.Extensions.ServiceBus": "[5.8.0, )", + "Microsoft.Azure.WebJobs.Extensions.Storage.Queues": "[5.0.1, )", "Microsoft.Extensions.Configuration.Abstractions": "[6.0.0, )", "Microsoft.Extensions.Configuration.KeyPerFile": "[6.0.1, )", "Microsoft.Extensions.Configuration.UserSecrets": "[6.0.1, )", diff --git a/BookingQueueSubscriber/BookingQueueSubscriber/BookingQueueStorage.cs b/BookingQueueSubscriber/BookingQueueSubscriber/BookingQueueStorage.cs new file mode 100644 index 00000000..23edc3f2 --- /dev/null +++ b/BookingQueueSubscriber/BookingQueueSubscriber/BookingQueueStorage.cs @@ -0,0 +1,40 @@ +using System.Threading.Tasks; +using System; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Host; +using Microsoft.Extensions.Logging; + +namespace BookingQueueSubscriber; + +public class BookingQueueStorage +{ + private readonly IMessageHandlerFactory _messageHandlerFactory; + + public BookingQueueStorage(IMessageHandlerFactory messageHandlerFactory) + { + _messageHandlerFactory = messageHandlerFactory; + } + + [FunctionName("BookingQueueStorage")] + public async Task RunAsync([QueueTrigger("%queueName%", Connection = "AzureWebJobsStorage")] string myQueueItem, ILogger logger) + { + // get handler + EventMessage eventMessage; + try + { + eventMessage = MessageSerializer.Deserialise(myQueueItem); + } + catch (Exception e) + { + logger.LogCritical(e, "Unable to deserialize into EventMessage \r\n {BookingQueueItem}", myQueueItem); + throw; + } + + var handler = _messageHandlerFactory.Get(eventMessage.IntegrationEvent); + logger.LogInformation("using handler {Handler}", handler.GetType()); + + await handler.HandleAsync(eventMessage.IntegrationEvent); + logger.LogInformation("Process message {EventMessageId} - {EventMessageIntegrationEvent}", eventMessage.Id, + eventMessage.IntegrationEvent); + } +} \ No newline at end of file diff --git a/BookingQueueSubscriber/BookingQueueSubscriber/BookingQueueSubscriber.csproj b/BookingQueueSubscriber/BookingQueueSubscriber/BookingQueueSubscriber.csproj index 70a8dcaa..1f0a82af 100644 --- a/BookingQueueSubscriber/BookingQueueSubscriber/BookingQueueSubscriber.csproj +++ b/BookingQueueSubscriber/BookingQueueSubscriber/BookingQueueSubscriber.csproj @@ -17,6 +17,7 @@ + diff --git a/BookingQueueSubscriber/BookingQueueSubscriber/packages.lock.json b/BookingQueueSubscriber/BookingQueueSubscriber/packages.lock.json index 68fc2359..a8bf12cb 100644 --- a/BookingQueueSubscriber/BookingQueueSubscriber/packages.lock.json +++ b/BookingQueueSubscriber/BookingQueueSubscriber/packages.lock.json @@ -94,6 +94,17 @@ "Microsoft.Extensions.Azure": "1.2.0" } }, + "Microsoft.Azure.WebJobs.Extensions.Storage.Queues": { + "type": "Direct", + "requested": "[5.0.1, )", + "resolved": "5.0.1", + "contentHash": "NCNMBtMOdKreEriYYLhnL1BpYwn8x1bhYAMbB7qadEvyobFyQ4j0z877TDq6S03l0aZRi3WL9XhkeiubRxneZA==", + "dependencies": { + "Azure.Storage.Queues": "12.10.0", + "Microsoft.Azure.WebJobs": "3.0.32", + "Microsoft.Extensions.Azure": "1.1.1" + } + }, "Microsoft.Extensions.Configuration.Abstractions": { "type": "Direct", "requested": "[6.0.0, )", @@ -282,6 +293,25 @@ "System.Memory.Data": "1.0.2" } }, + "Azure.Storage.Common": { + "type": "Transitive", + "resolved": "12.11.0", + "contentHash": "BPZ1JwYvehHGoTSXhXfAmwtFYejJghE6dkKvpZtPIL0DulzSIJdll9OZI+h5W+3wLYK0yn5hc1r6mvId0q4npA==", + "dependencies": { + "Azure.Core": "1.24.0", + "System.IO.Hashing": "6.0.0" + } + }, + "Azure.Storage.Queues": { + "type": "Transitive", + "resolved": "12.10.0", + "contentHash": "RD+rDy2O763jJXpvaOd03I3NSIrGpjq5YPzVkPydXnhMIzvjrv3X6ogDl+QgZs1ssuRcqjCh0RBvaaW6tt2EYw==", + "dependencies": { + "Azure.Storage.Common": "12.11.0", + "System.Memory.Data": "1.0.2", + "System.Text.Json": "4.7.2" + } + }, "BookingsApi.Common.DotNet6": { "type": "Transitive", "resolved": "2.3.10", @@ -1578,6 +1608,11 @@ "System.Runtime": "4.3.0" } }, + "System.IO.Hashing": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "Rfm2jYCaUeGysFEZjDe7j1R4x6Z6BzumS/vUT5a1AA/AWJuGX71PoGB0RmpyX3VmrGqVnAwtfMn39OHR8Y/5+g==" + }, "System.Linq": { "type": "Transitive", "resolved": "4.3.0",