private async Task <bool> ProcessReceiptsAsync(AutoPublisher apub, ulong count) { await Task.Yield(); var buffer = apub.GetReceiptBufferReader(); var receiptCount = 0ul; var error = false; var sw = Stopwatch.StartNew(); while (receiptCount < count) { if (buffer.TryRead(out var receipt)) { receiptCount++; if (receipt.IsError) { error = true; break; } } } sw.Stop(); output.WriteLine($"Finished getting receipts.\r\nReceiptCount: {receiptCount} in {sw.ElapsedMilliseconds} ms.\r\nErrorStatus: {error}"); return(error); }
public async Task InitializeAsync(string passphrase, string salt) { await _serviceLock.WaitAsync().ConfigureAwait(false); try { if (!Initialized) { _hashKey = await ArgonHash .GetHashKeyAsync(passphrase, salt, Constants.EncryptionKeySize) .ConfigureAwait(false); await ChannelPool .InitializeAsync() .ConfigureAwait(false); await AutoPublisher .StartAsync(_hashKey) .ConfigureAwait(false); await FinishSettingUpConsumersAsync().ConfigureAwait(false); Initialized = true; } } finally { _serviceLock.Release(); } }
/// <summary> /// Builds out a RabbitService with instantiated dependencies based on config settings. /// </summary> /// <param name="config"></param> /// <param name="loggerFactory"></param> public RabbitService(Config config, ILoggerFactory loggerFactory = null) { LogHelper.LoggerFactory = loggerFactory; Config = config; ChannelPool = new ChannelPool(Config); AutoPublisher = new AutoPublisher(ChannelPool); Topologer = new Topologer(ChannelPool); BuildConsumers(); }
public AutoPublisherConsumerTests(ITestOutputHelper output) { this.output = output; config = ConfigReader.ConfigFileReadAsync("Config.json").GetAwaiter().GetResult(); var channelPool = new ChannelPool(config); topologer = new Topologer(channelPool); topologer.InitializeAsync().GetAwaiter().GetResult(); autoPublisher = new AutoPublisher(channelPool); consumer = new Consumer(channelPool, "ConsumerFromConfig"); }
private async Task PublishLettersAsync(AutoPublisher apub, ulong count) { var sw = Stopwatch.StartNew(); for (ulong i = 0; i < count; i++) { var letter = CreateSimpleRandomLetter("TestAutoPublisherConsumerQueue"); letter.LetterId = i; await apub.QueueLetterAsync(letter).ConfigureAwait(false); } sw.Stop(); output.WriteLine($"Finished queueing all letters in {sw.ElapsedMilliseconds} ms."); }
/// <summary> /// Reads config from a provided file name path. Builds out a RabbitService with instantiated dependencies based on config settings. /// </summary> /// <param name="fileNamePath"></param> /// <param name="loggerFactory"></param> public RabbitService(string fileNamePath, ILoggerFactory loggerFactory = null) { LogHelper.LoggerFactory = loggerFactory; Config = ConfigReader .ConfigFileReadAsync(fileNamePath) .GetAwaiter() .GetResult(); ChannelPool = new ChannelPool(Config); AutoPublisher = new AutoPublisher(ChannelPool); Topologer = new Topologer(ChannelPool); BuildConsumers(); }
public async ValueTask ShutdownAsync(bool immediately) { await _serviceLock.WaitAsync().ConfigureAwait(false); try { await AutoPublisher .StopAsync(immediately) .ConfigureAwait(false); await StopAllConsumers(immediately) .ConfigureAwait(false); await ChannelPool .ShutdownAsync() .ConfigureAwait(false); } finally { _serviceLock.Release(); } }
public async Task InitializeAsync() { await _serviceLock.WaitAsync().ConfigureAwait(false); try { if (!Initialized) { await ChannelPool .InitializeAsync() .ConfigureAwait(false); await AutoPublisher .StartAsync() .ConfigureAwait(false); await FinishSettingUpConsumersAsync().ConfigureAwait(false); Initialized = true; } } finally { _serviceLock.Release(); } }