public async Task Produce(string topicName, object toposMessage) { _logger.LogInformation($"Sending message topicname: {topicName} and body {JsonConvert.SerializeObject(toposMessage, Formatting.Indented)}"); if (_producer == null) { Init(); } await _producer.Send(topicName, new ToposMessage(toposMessage)); }
static async Task Produce(IToposProducer producer, IEnumerable <string> events, int eventCount) { var stopwatch = Stopwatch.StartNew(); await Task.WhenAll(events.Select(async(evt, index) => await producer.Send(evt, index.ToString()))); var elapsedSeconds = stopwatch.Elapsed.TotalSeconds; Console.WriteLine($"Producing {eventCount} events took {elapsedSeconds:0.0} s - that's {eventCount/elapsedSeconds:0.0} evt/s"); }
public async Task ThuisMustWork() { var receivedEvents = new ConcurrentQueue <string>(); string FormatReceivedEvents() => $@"Received events contains this: {string.Join(Environment.NewLine, receivedEvents.Select(e => $" {e}"))}"; var partitionKey = "test"; // send three mewsages await _producer.Send("HEJ", partitionKey : partitionKey); await _producer.Send("MED", partitionKey : partitionKey); await _producer.Send("DIG", partitionKey : partitionKey); // wait until they're received await ConsumeForSomeTime(receivedEvents, c => c.Count == 3, c => c.Count > 3, FormatReceivedEvents); Assert.That(receivedEvents, Is.EqualTo(new[] { "HEJ", "MED", "DIG" }), FormatReceivedEvents); // now clear the events and send 5 additional events receivedEvents.Clear(); await _producer.Send("HEJ", partitionKey : partitionKey); await _producer.Send("IGEN", partitionKey : partitionKey); await _producer.Send("IGEN", partitionKey : partitionKey); await _producer.Send("OG", partitionKey : partitionKey); await _producer.Send("SÅ IGEN", partitionKey : partitionKey); // ... and then wait for them to arrive await ConsumeForSomeTime(receivedEvents, c => c.Count == 5, c => c.Count > 5, FormatReceivedEvents); Assert.That(receivedEvents.Count, Is.EqualTo(5), FormatReceivedEvents); Assert.That(receivedEvents, Is.EqualTo(new[] { "HEJ", "IGEN", "IGEN", "OG", "SÅ IGEN" }), FormatReceivedEvents); }