async Task LaunchNewSendTask( IClusterClient cluster, int durationInSec, ConcurrentQueue <int> sentQueue, Func <int> generateMessage) { var shouldStop = new ManualResetEvent(false); var timeout = Task.Delay(TimeSpan.FromSeconds(durationInSec)); var task = Task.Run( () => { while (!shouldStop.WaitOne(0)) { var msg = generateMessage(); cluster.Produce(topic, Encoding.ASCII.GetBytes(msg.ToString())); sentQueue.Enqueue(msg); Thread.Sleep(5); } }); await timeout; shouldStop.Set(); await task; }
public bool Produce(TKey key, TValue data, int partition) { return(!_disposed && _clusterClient.Produce(_topic, key, data, partition)); }
public bool Produce(TKey key, TValue data, ICollection <KafkaRecordHeader> headers, int partition, DateTime timestamp) { return(!_disposed && _clusterClient.Produce(_topic, key, data, headers, partition, timestamp)); }