예제 #1
0
    public async Task ThisIsHowWeParty()
    {
        await _producer.SendMany(_topic, Enumerable.Range(0, 10).Select(n => new ToposMessage($"THIS IS MESSAGE {n}")), partitionKey : "whatever");

        using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));

        using var consumer = _consumerBuilder.Build();

        consumer.Subscribe(_topic);

        try
        {
            while (true)
            {
                var result  = consumer.Consume(cancellationTokenSource.Token);
                var message = result.Message;

                var body = Encoding.UTF8.GetString(message.Value);
                Console.WriteLine($"Got message: {body}");
            }
        }
        catch (OperationCanceledException) when(cancellationTokenSource.IsCancellationRequested)
        {
        }
    }
예제 #2
0
    static async Task Produce(IToposProducer producer, IEnumerable <string> events, int eventCount, string topic)
    {
        var stopwatch = Stopwatch.StartNew();

        await producer.SendMany(topic, events.Select((evt, index) => new ToposMessage(evt)));

        //await Task.WhenAll(events.Select(async (evt, index) => await producer.Send(topic, new ToposMessage(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");
    }