Skip to content

Commit

Permalink
RavenDB-29492 Fix issue for message batch id and test connection
Browse files Browse the repository at this point in the history
  • Loading branch information
djordjedjukic committed Dec 23, 2024
1 parent 75b89b1 commit e2703b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -82,7 +85,7 @@ protected override int PublishMessages(List<QueueWithItems<AmazonSqsItem>> items

var sendMessageEntry = new SendMessageBatchRequestEntry
{
Id = messageId,
Id = CreateAmazonBatchMessageId(queueItem.DocumentId),
MessageBody = message
};

Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit e2703b3

Please sign in to comment.