mirror of
https://github.com/bitwarden/server.git
synced 2025-06-21 19:28:46 -05:00

* [PM-17562] Add Azure Service Bus support for event integration retries * Cleanup AzureServiceBusIntegrationListenerService.cs; add nullable * Removed IntegrationHandlerBase* since it is no longer used (We removed the subclasses previously) * Changed strategy to assume ApplyRetry always gives us a non-null DelayUntilDate; Added test to confirm as well
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using Azure.Messaging.ServiceBus;
|
|
using Bit.Core.AdminConsole.Models.Data.Integrations;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Settings;
|
|
|
|
namespace Bit.Core.Services;
|
|
|
|
public class AzureServiceBusIntegrationPublisher : IIntegrationPublisher, IAsyncDisposable
|
|
{
|
|
private readonly ServiceBusClient _client;
|
|
private readonly ServiceBusSender _sender;
|
|
|
|
public AzureServiceBusIntegrationPublisher(GlobalSettings globalSettings)
|
|
{
|
|
_client = new ServiceBusClient(globalSettings.EventLogging.AzureServiceBus.ConnectionString);
|
|
_sender = _client.CreateSender(globalSettings.EventLogging.AzureServiceBus.IntegrationTopicName);
|
|
}
|
|
|
|
public async Task PublishAsync(IIntegrationMessage message)
|
|
{
|
|
var json = message.ToJson();
|
|
|
|
var serviceBusMessage = new ServiceBusMessage(json)
|
|
{
|
|
Subject = message.IntegrationType.ToRoutingKey(),
|
|
};
|
|
|
|
await _sender.SendMessageAsync(serviceBusMessage);
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
await _sender.DisposeAsync();
|
|
await _client.DisposeAsync();
|
|
}
|
|
}
|