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"));
        }
        public async Task Should_be_able_to_append_logs_to_a_stream_and_consume()
        {
            var payloads = new[] { "abc", "def", "ghi" };

            await _log.AppendAsync("my-stream", Encoding.UTF8.GetBytes(payloads[0]));

            await _log.AppendAsync("my-stream", Encoding.UTF8.GetBytes(payloads[1]));

            await _log.AppendAsync("my-stream", Encoding.UTF8.GetBytes(payloads[2]));

            var options = new ConsumerOptions.Builder()
                          .StopConsumingAtEOF()
                          .Build();

            var expectedPayloadIndex = 0;

            await foreach (var logEntry in _consumer.ConsumeAsync("my-stream", options))
            {
                var payload = logEntry != null?Encoding.UTF8.GetString(logEntry) : null;

                Assert.That(payload, Is.EqualTo(payloads[expectedPayloadIndex]));
                expectedPayloadIndex++;
            }
        }
Example #3
0
        public static Task AppendAsync <T>(this IDistributedLog distributedLog, string streamName, T payload)
        {
            var bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload));

            return(distributedLog.AppendAsync(streamName, bytes));
        }
Example #4
0
        public async Task Add(int num)
        {
            _logger.LogInformation("Adding number...");

            await _distributedLog.AppendAsync(_namingConvention.GetTopicName <NumberAdded>(), new NumberAdded { Num = num });
        }