2017-12-04 09:58:07 -05:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-01-10 08:33:13 -05:00
|
|
|
|
using Azure.Storage.Queues;
|
2017-12-04 09:58:07 -05:00
|
|
|
|
using Newtonsoft.Json;
|
2017-12-08 14:03:07 -05:00
|
|
|
|
using Bit.Core.Models.Data;
|
2021-02-22 15:35:16 -06:00
|
|
|
|
using Bit.Core.Settings;
|
2017-12-04 09:58:07 -05:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Services
|
|
|
|
|
|
{
|
|
|
|
|
|
public class AzureQueueEventWriteService : IEventWriteService
|
|
|
|
|
|
{
|
2020-01-10 08:33:13 -05:00
|
|
|
|
private readonly QueueClient _queueClient;
|
2017-12-04 09:58:07 -05:00
|
|
|
|
|
|
|
|
|
|
private JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
|
|
|
|
|
|
{
|
|
|
|
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public AzureQueueEventWriteService(
|
|
|
|
|
|
GlobalSettings globalSettings)
|
|
|
|
|
|
{
|
2020-01-10 08:33:13 -05:00
|
|
|
|
_queueClient = new QueueClient(globalSettings.Events.ConnectionString, "event");
|
2017-12-04 09:58:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 23:09:50 -05:00
|
|
|
|
public async Task CreateAsync(IEvent e)
|
2017-12-04 09:58:07 -05:00
|
|
|
|
{
|
2017-12-08 23:09:50 -05:00
|
|
|
|
var json = JsonConvert.SerializeObject(e, _jsonSettings);
|
2020-01-10 08:33:13 -05:00
|
|
|
|
await _queueClient.SendMessageAsync(json);
|
2017-12-04 09:58:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 23:09:50 -05:00
|
|
|
|
public async Task CreateManyAsync(IList<IEvent> e)
|
2017-12-04 09:58:07 -05:00
|
|
|
|
{
|
2017-12-08 23:09:50 -05:00
|
|
|
|
var json = JsonConvert.SerializeObject(e, _jsonSettings);
|
2020-01-10 08:33:13 -05:00
|
|
|
|
await _queueClient.SendMessageAsync(json);
|
2017-12-04 09:58:07 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|