public async IAsyncEnumerable <byte[]> ConsumeAsync(string streamName, ConsumerOptions options) { streamName?.ThrowIfNull(nameof(streamName)); var consumerOptions = new ConsumerOptions.Builder().Build(); if (options != null) { consumerOptions = options; } _currentOffset = consumerOptions.StartOffset; var keepConsuming = true; while (keepConsuming) { var result = await _log.RetrieveEntryAsync(streamName, _currentOffset); if (result != null) { yield return(result); _currentOffset++; } else if (consumerOptions.StopConsumingAtEOF) { keepConsuming = false; } } }
public static async Task <T> RetrieveEntry <T>(this IDistributedLog distributedLog, string streamName, int offset) { var bytes = await distributedLog.RetrieveEntryAsync(streamName, offset); var payload = Encoding.UTF8.GetString(bytes); return(JsonConvert.DeserializeObject <T>(payload)); }
public async Task Should_be_able_to_append_to_a_stream_and_retrieve_entry() { await _log.AppendAsync(StreamName, Encoding.UTF8.GetBytes("some stuff")); byte[] entry = await _log.RetrieveEntryAsync(StreamName, 0); Assert.That(Encoding.UTF8.GetString(entry), Is.EqualTo("some stuff")); }