Optimize queue usage

This commit is contained in:
2025-10-03 16:38:10 +08:00
parent 5bf58f0194
commit 30fd912281
4 changed files with 12 additions and 2260 deletions

View File

@@ -1,7 +1,6 @@
using System.Text.Json;
using DysonNetwork.Shared.Proto;
using NATS.Client.Core;
using NATS.Net;
namespace DysonNetwork.Ring.Services;
@@ -21,15 +20,14 @@ public class QueueService(INatsConnection nats)
})
};
var rawMessage = GrpcTypeHelper.ConvertObjectToByteString(message).ToByteArray();
var js = nats.CreateJetStreamContext();
await js.PublishAsync(QueueBackgroundService.QueueName, rawMessage);
await nats.PublishAsync(QueueBackgroundService.QueueName, rawMessage);
}
public async Task EnqueuePushNotification(Shared.Models.SnNotification notification, Guid userId, bool isSavable = false)
{
// Update the account ID in case it wasn't set
notification.AccountId = userId;
var message = new QueueMessage
{
Type = QueueMessageType.PushNotification,
@@ -37,8 +35,7 @@ public class QueueService(INatsConnection nats)
Data = JsonSerializer.Serialize(notification)
};
var rawMessage = GrpcTypeHelper.ConvertObjectToByteString(message).ToByteArray();
var js = nats.CreateJetStreamContext();
await js.PublishAsync(QueueBackgroundService.QueueName, rawMessage);
await nats.PublishAsync(QueueBackgroundService.QueueName, rawMessage);
}
}
@@ -61,4 +58,4 @@ public class EmailMessage
public string ToAddress { get; set; } = string.Empty;
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
}
}