private IDisposable CreateSubscription( TestScheduler scheduler, Func <IConfluentClient, ConsumerInstance, string, Task <ConfluentResponse <List <AvroMessage <string, LogMessage> > > > > getPayload, Action <LogMessage> onSuccess, Action <Exception> onException) { var consumer = new RxConsumer <String, LogMessage>(new Mock <IConfluentClient>().Object, new ConsumerInstance(), "testStream"); var observable = consumer.GetRecordStream( getPayload, TimeSpan.FromTicks(TestSchedulerTickInterval), scheduler, () => { }); var subscription = observable.Subscribe( successResult => { Console.WriteLine("Success: " + successResult.IsSuccess); if (successResult.IsSuccess) { Console.WriteLine(successResult.Value.Key + "=" + successResult.Value.Value.Message); onSuccess(successResult.Value.Value); } else { Console.WriteLine("ERROR: " + successResult.Exception.Message); onException(successResult.Exception); } }); return(subscription); }
/// <summary> /// At the moment this just listens to the stream /// </summary> //[Test] //[Category("Integration")] public void KafkaObservable_Should_Provide_An_Observable_Stream() { // Arrange String instanceId = "0"; string consumerGroupName = "rxtestgroup"; string topic = "rxtest"; ConsumerInstance consumerInstance = null; using (var client = Setup.CreateConfluentClient("http://199.204.211.42:8082")) //using (var client = Setup.CreateConfluentClient("http://192.168.79.137:8082")) { try { // in production this should be written without blocking. consumerInstance = Setup.ConsumerInstance(client, instanceId, consumerGroupName); var consumer = new RxConsumer<String, RxConsumerTests.LogMessage>(client, consumerInstance, topic); // Act var observable = consumer.GetRecordStream( TimeSpan.FromSeconds(5), ThreadPoolScheduler.Instance) .Take(10) .Subscribe(successResult => { Console.WriteLine("Success: " + successResult.IsSuccess); if (successResult.IsSuccess) { Console.WriteLine(successResult.Value.Key + "=" + successResult.Value.Value.Message); } else { Console.WriteLine("ERROR: " + successResult.Exception.Message); } }, () => Console.WriteLine("COMPLETED.") // not sure how to cancel this... ); Thread.Sleep(15000); Console.WriteLine("Disposing observer"); observable.Dispose(); } finally { if (consumerInstance != null) { Console.WriteLine("Destroying instance"); client.DeleteConsumerAsync(consumerInstance); } } } // Assert //Assert.Fail("Not Implemented Yet"); }
/// <summary> /// At the moment this just listens to the stream /// </summary> //[Test] //[Category("Integration")] public void KafkaObservable_Should_Provide_An_Observable_Stream() { // Arrange String instanceId = "0"; string consumerGroupName = "rxtestgroup"; string topic = "rxtest"; ConsumerInstance consumerInstance = null; using (var client = Setup.CreateConfluentClient("http://199.204.211.42:8082")) //using (var client = Setup.CreateConfluentClient("http://192.168.79.137:8082")) { try { // in production this should be written without blocking. consumerInstance = Setup.ConsumerInstance(client, instanceId, consumerGroupName); var consumer = new RxConsumer <String, RxConsumerTests.LogMessage>(client, consumerInstance, topic); // Act var observable = consumer.GetRecordStream( TimeSpan.FromSeconds(5), ThreadPoolScheduler.Instance) .Take(10) .Subscribe(successResult => { Console.WriteLine("Success: " + successResult.IsSuccess); if (successResult.IsSuccess) { Console.WriteLine(successResult.Value.Key + "=" + successResult.Value.Value.Message); } else { Console.WriteLine("ERROR: " + successResult.Exception.Message); } }, () => Console.WriteLine("COMPLETED.") // not sure how to cancel this... ); Thread.Sleep(15000); Console.WriteLine("Disposing observer"); observable.Dispose(); } finally { if (consumerInstance != null) { Console.WriteLine("Destroying instance"); client.DeleteConsumerAsync(consumerInstance); } } } // Assert //Assert.Fail("Not Implemented Yet"); }
private IDisposable CreateSubscription( TestScheduler scheduler, Func<IConfluentClient, ConsumerInstance, string, Task<ConfluentResponse<List<AvroMessage<string, LogMessage>>>>> getPayload, Action<LogMessage> onSuccess, Action<Exception> onException) { var consumer = new RxConsumer<String, LogMessage>(new Mock<IConfluentClient>().Object, new ConsumerInstance(), "testStream"); var observable = consumer.GetRecordStream( getPayload, TimeSpan.FromTicks(TestSchedulerTickInterval), scheduler, () => { }); var subscription = observable.Subscribe( successResult => { Console.WriteLine("Success: " + successResult.IsSuccess); if (successResult.IsSuccess) { Console.WriteLine(successResult.Value.Key + "=" + successResult.Value.Value.Message); onSuccess(successResult.Value.Value); } else { Console.WriteLine("ERROR: " + successResult.Exception.Message); onException(successResult.Exception); } }); return subscription; }
private static void Listen(Options options) { // Arrange String instanceId = options.InstanceId; string consumerGroupName = options.ConsumerGroup; string topic = options.Topic; ConsumerInstance consumerInstance = null; Log("Registering group/id: " + options.ConsumerGroup + "/" + options.InstanceId+"\r\n"); Log("Listening to topic: " + topic + "\r\n"); Log("Query interval: " + options.Sleep + "ms" + "\r\n"); using (var client = Setup.CreateConfluentClient(options.BaseUrl)) { try { // in production this should be written without blocking. consumerInstance = Setup.ConsumerInstance(client, instanceId, consumerGroupName); var consumer = new RxConsumer<String, LogMessage>(client, consumerInstance, topic); // Act var observable = consumer.GetRecordStream( TimeSpan.FromMilliseconds(options.Sleep), ThreadPoolScheduler.Instance, beforeCallAction: () => Log(".")) .Subscribe( // OnSuccess successResult => { Log("Success: " + successResult.IsSuccess + "\r\n"); if (successResult.IsSuccess) { System.Console.WriteLine(successResult.Value.Key + "=" + successResult.Value.Value.Message); } else { System.Console.WriteLine("ERROR: " + successResult.Exception.Message); } }, // OnCompleted () => System.Console.WriteLine("COMPLETED.") // not sure how to cancel this... ); System.Console.ReadLine(); System.Console.WriteLine("Disposing observer"); observable.Dispose(); } catch (Exception ex) { System.Console.WriteLine(ex.Message); if (ex.InnerException != null) { System.Console.WriteLine(ex.InnerException.Message); } } finally { if (consumerInstance != null) { Log("Destroying Consumer Instance\r\n"); client.DeleteConsumerAsync(consumerInstance); Log("Iterations: " + _iterations); } } } }
private static void Listen(Options options) { // Arrange String instanceId = options.InstanceId; string consumerGroupName = options.ConsumerGroup; string topic = options.Topic; ConsumerInstance consumerInstance = null; Log("Registering group/id: " + options.ConsumerGroup + "/" + options.InstanceId + "\r\n"); Log("Listening to topic: " + topic + "\r\n"); Log("Query interval: " + options.Sleep + "ms" + "\r\n"); using (var client = Setup.CreateConfluentClient(options.BaseUrl)) { try { // in production this should be written without blocking. consumerInstance = Setup.ConsumerInstance(client, instanceId, consumerGroupName); var consumer = new RxConsumer <String, LogMessage>(client, consumerInstance, topic); // Act var observable = consumer.GetRecordStream( TimeSpan.FromMilliseconds(options.Sleep), ThreadPoolScheduler.Instance, beforeCallAction: () => Log(".")) .Subscribe( // OnSuccess successResult => { Log("Success: " + successResult.IsSuccess + "\r\n"); if (successResult.IsSuccess) { System.Console.WriteLine(successResult.Value.Key + "=" + successResult.Value.Value.Message); } else { System.Console.WriteLine("ERROR: " + successResult.Exception.Message); } }, // OnCompleted () => System.Console.WriteLine("COMPLETED.") // not sure how to cancel this... ); System.Console.ReadLine(); System.Console.WriteLine("Disposing observer"); observable.Dispose(); } catch (Exception ex) { System.Console.WriteLine(ex.Message); if (ex.InnerException != null) { System.Console.WriteLine(ex.InnerException.Message); } } finally { if (consumerInstance != null) { Log("Destroying Consumer Instance\r\n"); client.DeleteConsumerAsync(consumerInstance); Log("Iterations: " + _iterations); } } } }