diff --git a/src/Raven.Server/Documents/ETL/Providers/Queue/AmazonSqs/AmazonSqsEtl.cs b/src/Raven.Server/Documents/ETL/Providers/Queue/AmazonSqs/AmazonSqsEtl.cs index 94d189a465bb..fd7b416bbc18 100644 --- a/src/Raven.Server/Documents/ETL/Providers/Queue/AmazonSqs/AmazonSqsEtl.cs +++ b/src/Raven.Server/Documents/ETL/Providers/Queue/AmazonSqs/AmazonSqsEtl.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using System.Text.Json; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Amazon.SQS; using Amazon.SQS.Model; @@ -13,6 +15,7 @@ using Raven.Server.NotificationCenter.Notifications.Details; using Raven.Server.ServerWide; using Raven.Server.ServerWide.Context; +using Sparrow; namespace Raven.Server.Documents.ETL.Providers.Queue.AmazonSqs; @@ -82,7 +85,7 @@ protected override int PublishMessages(List> items var sendMessageEntry = new SendMessageBatchRequestEntry { - Id = messageId, + Id = CreateAmazonBatchMessageId(queueItem.DocumentId), MessageBody = message }; @@ -234,6 +237,20 @@ private string SerializeCloudEvent(AmazonSqsItem queueItem, out string messageId messageGroupId = cloudEvent.Type; return JsonSerializer.Serialize(cloudEvent, JsonSerializerOptions); } + + private static string CreateAmazonBatchMessageId(string documentId) + { + string formattedString = Regex.Replace(documentId, "[^a-zA-Z0-9]", "-"); + + if (formattedString.Length > 80) + { + formattedString = formattedString.Substring(0, 70) + "-" + + $"{(Hashing.XXHash64.Calculate(formattedString, Encoding.UTF8) % 1_000_000_000)}"; + + } + + return formattedString; + } protected override void OnProcessStopped() { diff --git a/src/Raven.Server/Documents/ETL/Providers/Queue/Handlers/Processors/QueueEtlHandlerProcessorForTestAmazonSqsConnection.cs b/src/Raven.Server/Documents/ETL/Providers/Queue/Handlers/Processors/QueueEtlHandlerProcessorForTestAmazonSqsConnection.cs index 1bd6f37ebaf0..6d6c531c907e 100644 --- a/src/Raven.Server/Documents/ETL/Providers/Queue/Handlers/Processors/QueueEtlHandlerProcessorForTestAmazonSqsConnection.cs +++ b/src/Raven.Server/Documents/ETL/Providers/Queue/Handlers/Processors/QueueEtlHandlerProcessorForTestAmazonSqsConnection.cs @@ -46,7 +46,7 @@ public override async ValueTask ExecuteAsync() context.Write(writer, result); } } - catch (AmazonSQSException ex) when (ex.ErrorCode == "QueueDoesNotExist") + catch (AmazonSQSException ex) when (ex.ErrorCode == "AWS.SimpleQueueService.NonExistentQueue") { // In this case, it means the connection is valid but the queue is not accessible DynamicJsonValue result = new() { [nameof(NodeConnectionTestResult.Success)] = true };