From 6fcf078a06858875538593dede2309494821b84f Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Mon, 11 Jul 2022 12:13:59 -0300 Subject: [PATCH 1/2] Initial empty signature for DeleteMessage --- .../Messaging/GXQueue/SimpleMessageQueue.cs | 42 ++----------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/SimpleMessageQueue.cs b/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/SimpleMessageQueue.cs index c432357c0..32fcdf3dd 100644 --- a/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/SimpleMessageQueue.cs +++ b/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/SimpleMessageQueue.cs @@ -71,8 +71,9 @@ public int GetQueueLength(out GXBaseCollection errorMessage return queueLength; } - public GxUserType DeleteMessage(string messageHandleId, out GXBaseCollection errorMessages, out bool success) + public GxUserType DeleteMessage(GxUserType msg, out GXBaseCollection errorMessages, out bool success) { + throw new NotImplementedException();/* MessageQueueResult messageQueueResult = new MessageQueueResult(); GxUserType messageResult = new GxUserType(); errorMessages = new GXBaseCollection(); @@ -99,44 +100,7 @@ public GxUserType DeleteMessage(string messageHandleId, out GXBaseCollection DeleteMessages(List messageHandleId, out GXBaseCollection errorMessages, out bool success) - { - IList messageQueueResults = new List(); - errorMessages = new GXBaseCollection(); - IList messageResults = new List(); - success = false; - try - { - try - { - ValidQueue(); - messageQueueResults = queue.DeleteMessages(messageHandleId, out success); - LoadAssemblyIfRequired(); - foreach (MessageQueueResult messageResult in messageQueueResults) - { - if (TransformMessageQueueResult(messageResult) is GxUserType result) - messageResults.Add(result); - } - success = true; - } - catch (Exception ex) - { - GXLogging.Error(logger, ex); - QueueErrorMessagesSetup(ex, out errorMessages); - success = false; - } - } - catch (Exception ex) - { - GXLogging.Error(logger, ex); - success = false; - throw ex; - } - - return messageResults; + return TransformMessageQueueResult(messageQueueResult);*/ } public IList DeleteMessages(IList simpleQueueMessages, out GXBaseCollection errorMessages, out bool success) From 2575041ff4edf031ca6cd8d8dde4ecc60a884910 Mon Sep 17 00:00:00 2001 From: sjuarezgx Date: Thu, 21 Jul 2022 17:05:38 -0300 Subject: [PATCH 2/2] Delete message method changes signature. Update Azure Queue SDK --- .../Messaging/GXAmazonSQS/AWSQueue.cs | 244 +++++++++--------- .../GXAzureQueue/AzureMessageQueueProvider.cs | 3 +- .../Messaging/GXAzureQueue/AzureQueue.cs | 58 ++--- .../GXAzureQueue/GXAzureQueue.csproj | 2 +- .../Providers/Messaging/GXQueue/Queue.cs | 3 +- .../Messaging/GXQueue/SimpleMessageQueue.cs | 16 +- 6 files changed, 150 insertions(+), 176 deletions(-) diff --git a/dotnet/src/dotnetcore/Providers/Messaging/GXAmazonSQS/AWSQueue.cs b/dotnet/src/dotnetcore/Providers/Messaging/GXAmazonSQS/AWSQueue.cs index 5fd3829c3..f0ed5882d 100644 --- a/dotnet/src/dotnetcore/Providers/Messaging/GXAmazonSQS/AWSQueue.cs +++ b/dotnet/src/dotnetcore/Providers/Messaging/GXAmazonSQS/AWSQueue.cs @@ -66,6 +66,27 @@ private void Initialize(GXService providerService) _isFIFO = _queueURL.EndsWith(".fifo"); } + + public override string GetName() + { + return Name; + } + public bool GetMessageFromException(Exception ex, SdtMessages_Message msg) + { + try + { + AmazonSQSException sqs_ex = (AmazonSQSException)ex; + msg.gxTpr_Id = sqs_ex.ErrorCode; + msg.gxTpr_Description = sqs_ex.Message; + return true; + } + catch (Exception) + { + return false; + } + } + + #region API methods public void Clear(out bool success) { try @@ -81,134 +102,32 @@ public void Clear(out bool success) } } - public MessageQueueResult DeleteMessage(string messageHandleId, out bool success) + public MessageQueueResult DeleteMessage(SimpleQueueMessage simpleQueueMessage, out bool success) { success = false; MessageQueueResult messageQueueResult = new MessageQueueResult(); - - List messageHandleIdToDelete = new List { messageHandleId }; - IList messageQueueResults = RemoveMessages(messageHandleIdToDelete, out bool operationOK); - if ((operationOK) && (messageQueueResults != null)) - { - messageQueueResult = messageQueueResults[0]; + Task task = Task.Run(async () => await DeleteQueueMessageAsync(simpleQueueMessage.MessageHandleId)); + DeleteMessageResponse deleteMessageResponse = task.Result; + if ((deleteMessageResponse != null) && ((deleteMessageResponse.HttpStatusCode == System.Net.HttpStatusCode.Accepted) || (deleteMessageResponse.HttpStatusCode == System.Net.HttpStatusCode.Created) || (deleteMessageResponse.HttpStatusCode == System.Net.HttpStatusCode.OK))) + { success = true; - } - return messageQueueResult; - } + SetupMessageQueueResult(simpleQueueMessage, MessageQueueResultStatus.Deleted); - public IList DeleteMessages(List messageHandleId, out bool success) - { - return RemoveMessages(messageHandleId, out success); - } - private IList RemoveMessages(List messageHandleId, out bool success) - { - IList messageQueueResults = new List(); - success = false; - try - { - Task task = Task.Run(async () => await DeleteQueueMessageBatchAsync(messageHandleId)); - - DeleteMessageBatchResponse deleteMessageBatchResponse = task.Result; - if (deleteMessageBatchResponse != null) - success = (deleteMessageBatchResponse.Failed.Count == 0); - - foreach (BatchResultErrorEntry entry in deleteMessageBatchResponse.Failed) - { - MessageQueueResult messageQueueResult = SetupMessageQueueResult(entry); - messageQueueResults.Add(messageQueueResult); - } - - foreach (DeleteMessageBatchResultEntry entry in deleteMessageBatchResponse.Successful) - { - MessageQueueResult messageQueueResult = SetupMessageQueueResult(entry); - messageQueueResults.Add(messageQueueResult); - } - - } - catch (AggregateException ae) - { - throw ae; } - return messageQueueResults; + return messageQueueResult; } public IList DeleteMessages(IList simpleQueueMessages, out bool success) { return RemoveMessages(simpleQueueMessages, out success); } - private IList RemoveMessages(IList simpleQueueMessages, out bool success) - { - IList messageQueueResults = new List(); - List messageHandleIds = new List(); - success = false; - try - { - foreach (SimpleQueueMessage simpleQueueMessage in simpleQueueMessages) - { - messageHandleIds.Add(simpleQueueMessage.MessageHandleId); - } - Task task = Task.Run(async () => await DeleteQueueMessageBatchAsync(messageHandleIds)); - - DeleteMessageBatchResponse deleteMessageBatchResponse = task.Result; - if (deleteMessageBatchResponse != null) - success = (deleteMessageBatchResponse.Failed.Count == 0); - - foreach (BatchResultErrorEntry entry in deleteMessageBatchResponse.Failed) - { - MessageQueueResult messageQueueResult = SetupMessageQueueResult(entry); - messageQueueResults.Add(messageQueueResult); - } - - foreach (DeleteMessageBatchResultEntry entry in deleteMessageBatchResponse.Successful) - { - MessageQueueResult messageQueueResult = SetupMessageQueueResult(entry); - messageQueueResults.Add(messageQueueResult); - } - - } - catch (AggregateException ae) - { - throw ae; - } - return messageQueueResults; - } - public IList GetMessages(out bool success) { return RetrieveMessages(success : out success); } - public IList GetMessages(MessageQueueOptions messageQueueOptions, out bool success) { return RetrieveMessages(out success, messageQueueOptions); } - private IList RetrieveMessages(out bool success, MessageQueueOptions messageQueueOptions = null) - { - success = false; - IList simpleQueueMessages = new List(); - try - { - Task task = Task.Run(async () => await GetMessageAsync(messageQueueOptions)); - - ReceiveMessageResponse response = task.Result; - success = response != null; - if (success) - { - List messagesList = response.Messages; - - foreach (Message message in messagesList) - { - SimpleQueueMessage simpleQueueMessage = SetupSimpleQueueMessage(message); - simpleQueueMessages.Add(simpleQueueMessage); - } - } - } - catch (AggregateException ae) - { - throw ae; - } - return simpleQueueMessages; - } - public int GetQueueLength(out bool success) { int approxNumberMessages = 0; @@ -231,7 +150,6 @@ public int GetQueueLength(out bool success) } return approxNumberMessages; } - public MessageQueueResult SendMessage(SimpleQueueMessage simpleQueueMessage, out bool success) { success = false; @@ -261,7 +179,6 @@ public MessageQueueResult SendMessage(SimpleQueueMessage simpleQueueMessage, out } return messageQueueResult; } - protected MessageQueueResult SendMessage(SimpleQueueMessage simpleQueueMessage, MessageQueueOptions messageQueueOptions, out bool success) { success = false; @@ -291,7 +208,6 @@ protected MessageQueueResult SendMessage(SimpleQueueMessage simpleQueueMessage, } return messageQueueResult; } - public IList SendMessages(IList simpleQueueMessages, MessageQueueOptions messageQueueOptions, out bool success) { success = false; @@ -322,26 +238,74 @@ public IList SendMessages(IList simpleQu } return messageQueueResults; } - - public override string GetName() + + private IList RemoveMessages(IList simpleQueueMessages, out bool success) { - return Name; + IList messageQueueResults = new List(); + List messageHandleIds = new List(); + success = false; + try + { + foreach (SimpleQueueMessage simpleQueueMessage in simpleQueueMessages) + { + messageHandleIds.Add(simpleQueueMessage.MessageHandleId); + } + Task task = Task.Run(async () => await DeleteQueueMessageBatchAsync(messageHandleIds)); + + DeleteMessageBatchResponse deleteMessageBatchResponse = task.Result; + if (deleteMessageBatchResponse != null) + success = (deleteMessageBatchResponse.Failed.Count == 0); + + foreach (BatchResultErrorEntry entry in deleteMessageBatchResponse.Failed) + { + MessageQueueResult messageQueueResult = SetupMessageQueueResult(entry); + messageQueueResults.Add(messageQueueResult); + } + + foreach (DeleteMessageBatchResultEntry entry in deleteMessageBatchResponse.Successful) + { + MessageQueueResult messageQueueResult = SetupMessageQueueResult(entry); + messageQueueResults.Add(messageQueueResult); + } + + } + catch (AggregateException ae) + { + throw ae; + } + return messageQueueResults; } - public bool GetMessageFromException(Exception ex, SdtMessages_Message msg) + private IList RetrieveMessages(out bool success, MessageQueueOptions messageQueueOptions = null) { + success = false; + IList simpleQueueMessages = new List(); try { - AmazonSQSException sqs_ex = (AmazonSQSException)ex; - msg.gxTpr_Id = sqs_ex.ErrorCode; - msg.gxTpr_Description = sqs_ex.Message; - return true; + Task task = Task.Run(async () => await GetMessageAsync(messageQueueOptions)); + + ReceiveMessageResponse response = task.Result; + success = response != null; + if (success) + { + List messagesList = response.Messages; + + foreach (Message message in messagesList) + { + SimpleQueueMessage simpleQueueMessage = SetupSimpleQueueMessage(message); + simpleQueueMessages.Add(simpleQueueMessage); + } + } } - catch (Exception) + catch (AggregateException ae) { - return false; + throw ae; } + return simpleQueueMessages; } + #endregion + + #region Transformation methods private MessageQueueResult SetupMessageQueueResult(SendMessageResponse response) { @@ -433,6 +397,19 @@ private SimpleQueueMessage SetupSimpleQueueMessage(Message response) return simpleQueueMessage; } + private MessageQueueResult SetupMessageQueueResult(SimpleQueueMessage simpleQueueMessage, string messageStatus) + { + MessageQueueResult messageQueueResult = new MessageQueueResult(); + messageQueueResult.MessageId = simpleQueueMessage.MessageId; + messageQueueResult.MessageStatus = messageStatus; + messageQueueResult.ServerMessageId = simpleQueueMessage.MessageId; + messageQueueResult.MessageHandleId = simpleQueueMessage.MessageHandleId; + return messageQueueResult; + } + + #endregion + + #region Async methods private async Task SendMessageAsync(SimpleQueueMessage simpleQueueMessage, MessageQueueOptions messageQueueOptions = null) { SendMessageResponse sendMessageResponse = new SendMessageResponse(); @@ -499,7 +476,11 @@ private async Task SendMessageBatchAsync(IList DeleteQueueMessageBatchAsync(List return deleteMessageBatchResponse; } + private async Task DeleteQueueMessageAsync(string messageHandleId) + { + DeleteMessageResponse deleteMessageResponse = new DeleteMessageResponse(); + try + { + + deleteMessageResponse = await _sqsClient.DeleteMessageAsync(_queueURL, messageHandleId).ConfigureAwait(false); + } + catch (Exception ex) + { + throw (ex); + } + return deleteMessageResponse; + } + private async Task PurgeQueueAsync() { PurgeQueueResponse purgeQueueResponse = new PurgeQueueResponse(); @@ -627,6 +623,8 @@ private async Task GetQueueAttributeAsync(List errorMessages, out bool success) - - { + { MessageQueueProvider messageQueueProvider = new MessageQueueProvider(); GXProperties properties = new GXProperties(); properties.Add("QUEUE_AZUREQUEUE_QUEUENAME", queueName); diff --git a/dotnet/src/dotnetcore/Providers/Messaging/GXAzureQueue/AzureQueue.cs b/dotnet/src/dotnetcore/Providers/Messaging/GXAzureQueue/AzureQueue.cs index e18c42e7d..6953c8080 100644 --- a/dotnet/src/dotnetcore/Providers/Messaging/GXAzureQueue/AzureQueue.cs +++ b/dotnet/src/dotnetcore/Providers/Messaging/GXAzureQueue/AzureQueue.cs @@ -83,7 +83,7 @@ public bool GetMessageFromException(Exception ex, SdtMessages_Message msg) /// Get the approximate number of messages in the queue /// /// - /// + /// int public int GetQueueLength(out bool success) { int cachedMessagesCount = 0; @@ -112,59 +112,38 @@ public void Clear(out bool success) } } - public MessageQueueResult DeleteMessage(string messageHandleId, out bool success) + /// + /// Delete a message. + /// + /// + /// + /// MessageQueueResult + public MessageQueueResult DeleteMessage(SimpleQueueMessage simpleQueueMessage, out bool success) { - //This method should receive messageHandleId + popReceipt success = false; MessageQueueResult messageQueueResult = new MessageQueueResult(); if (_queueClient is QueueClient && _queueClient.Exists()) { - Azure.Response receivedMessage = _queueClient.ReceiveMessage(); - - if ((receivedMessage != null) && (!receivedMessage.GetRawResponse().IsError) && (receivedMessage.Value != null) && (receivedMessage.Value.MessageId == messageHandleId)) + Azure.Response deleteResult = _queueClient.DeleteMessage(simpleQueueMessage?.MessageId, simpleQueueMessage?.MessageHandleId); + if (deleteResult != null) { - Azure.Response deleteResult = _queueClient.DeleteMessage(receivedMessage.Value.MessageId, receivedMessage.Value.PopReceipt); - - success = !deleteResult.IsError; - if (success) + if (!deleteResult.IsError) { - return (AzQueueMessageToMessageQueueResult(receivedMessage.Value, MessageQueueResultStatus.Deleted)); + messageQueueResult = SimpleQueueMessageToMessageQueueResult(simpleQueueMessage, MessageQueueResultStatus.Deleted); + success = true; } - } - } - return messageQueueResult; - } - - /// - /// Deletes permanently the messages given on the list. - /// - - public IList DeleteMessages(List messageHandleId, out bool success) - { - success = false; - IList messageQueueResults = new List(); - if (_queueClient is QueueClient && _queueClient.Exists()) - { - QueueMessage[] receivedMessages = _queueClient.ReceiveMessages(); - Azure.Response deleteResult; - foreach (QueueMessage message in receivedMessages) - { - if (messageHandleId.Contains(message.MessageId)) + else { - deleteResult = _queueClient.DeleteMessage(message?.MessageId, message?.PopReceipt); - if ((deleteResult != null) && (!deleteResult.IsError) && message is QueueMessage) - messageQueueResults.Add(AzQueueMessageToMessageQueueResult(queueMessage: message, status: MessageQueueResultStatus.Deleted)); + messageQueueResult = SimpleQueueMessageToMessageQueueResult(simpleQueueMessage, MessageQueueResultStatus.Failed); } } - success = true; } - return messageQueueResults; + return messageQueueResult; } /// /// Deletes permanently the messages given on the list. /// - public IList DeleteMessages(IList simpleQueueMessages, out bool success) { success = false; @@ -308,12 +287,11 @@ public MessageQueueResult SendMessage(SimpleQueueMessage simpleQueueMessage, out if ((sendReceipt != null) && (sendReceipt.Value != null)) { MessageQueueResult result = new MessageQueueResult() - { - MessageId = simpleQueueMessage.MessageId, + { + MessageId = sendReceipt.Value.MessageId, ServerMessageId = sendReceipt.Value.MessageId, MessageStatus = MessageQueueResultStatus.Sent, MessageAttributes = new GXProperties() - }; Type t = sendReceipt.Value.GetType(); PropertyInfo[] props = t.GetProperties(); diff --git a/dotnet/src/dotnetcore/Providers/Messaging/GXAzureQueue/GXAzureQueue.csproj b/dotnet/src/dotnetcore/Providers/Messaging/GXAzureQueue/GXAzureQueue.csproj index 30e505229..946bcc46f 100644 --- a/dotnet/src/dotnetcore/Providers/Messaging/GXAzureQueue/GXAzureQueue.csproj +++ b/dotnet/src/dotnetcore/Providers/Messaging/GXAzureQueue/GXAzureQueue.csproj @@ -5,7 +5,7 @@ - + diff --git a/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/Queue.cs b/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/Queue.cs index c63399590..a3e118b3a 100644 --- a/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/Queue.cs +++ b/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/Queue.cs @@ -17,8 +17,7 @@ public interface IQueue IList SendMessages(IList simpleQueueMessages, MessageQueueOptions messageQueueOptions, out bool success); IList GetMessages(out bool success); IList GetMessages(MessageQueueOptions messageQueueOptions, out bool success); - MessageQueueResult DeleteMessage(string messageHandleId, out bool success); - IList DeleteMessages(List messageHandleId, out bool success); + MessageQueueResult DeleteMessage(SimpleQueueMessage simpleQueueMessage, out bool success); IList DeleteMessages(IList simpleQueueMessages, out bool success); void Clear(out bool success); bool GetMessageFromException(Exception ex, SdtMessages_Message msg); diff --git a/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/SimpleMessageQueue.cs b/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/SimpleMessageQueue.cs index 32fcdf3dd..6876482d9 100644 --- a/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/SimpleMessageQueue.cs +++ b/dotnet/src/dotnetcore/Providers/Messaging/GXQueue/SimpleMessageQueue.cs @@ -71,26 +71,27 @@ public int GetQueueLength(out GXBaseCollection errorMessage return queueLength; } - public GxUserType DeleteMessage(GxUserType msg, out GXBaseCollection errorMessages, out bool success) + public GxUserType DeleteMessage(GxUserType simpleQueueMessage, out GXBaseCollection errorMessages, out bool success) { - throw new NotImplementedException();/* + success = false; MessageQueueResult messageQueueResult = new MessageQueueResult(); - GxUserType messageResult = new GxUserType(); errorMessages = new GXBaseCollection(); try { - ValidQueue(); - messageQueueResult = queue.DeleteMessage(messageHandleId, out success); + ValidQueue(); + messageQueueResult = queue.DeleteMessage(TransformGXUserTypeToSimpleQueueMessage(simpleQueueMessage), out success); LoadAssemblyIfRequired(); try { if (messageQueueResult != null && TransformMessageQueueResult(messageQueueResult) is GxUserType result) + { + success = true; return result; + } } catch (Exception ex) { GXLogging.Error(logger, ex); - success = false; throw ex; } } @@ -98,9 +99,8 @@ public GxUserType DeleteMessage(GxUserType msg, out GXBaseCollection DeleteMessages(IList simpleQueueMessages, out GXBaseCollection errorMessages, out bool success)