public ActionResult <IEnumerable <string> > Get() { Kafka kafka = new Kafka(); kafka.TestAsync(); return(new string[] { "value1", "value2" }); }
public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int m = int.Parse(Console.ReadLine()); Kafka kafka = new Kafka(m); for (int i = 0; i < n; i++) { string[] commands = Console.ReadLine().Split(" "); try { switch (commands[0]) { case "activate": kafka.Activate(); Console.WriteLine("Kafka is activated"); break; case "deactivate": kafka.Deactivate(); Console.WriteLine("Kafka is deactivated"); break; case "new_user": string username = commands[1]; var user = new User(username); users[username] = user; Console.WriteLine($"User {username} is created"); break; case "subscribe": kafka.Subscribe(users[commands[1]]); Console.WriteLine($"User {commands[1]} subscribed"); break; case "unsubscribe": kafka.Unsubscribe(users[commands[1]]); Console.WriteLine($"User {commands[1]} unsubscribed"); break; case "push": kafka.Push(new Message(commands[1], commands[2])); Console.WriteLine($"Message from {commands[2]} {commands[1]} pushed"); break; case "pop": var messages = kafka.PopMessages(users[commands[1]], int.Parse(commands[2])).ToArray(); Console.WriteLine($"User {commands[1]} poped {commands[2]} messages"); Array.ForEach(messages, Console.WriteLine); break; } } catch (KafkaException e) { Console.WriteLine(e.Message); } } }
public ProducerService(IOptions <Conventions.SConfig> config) { var kconfig = new ConsumerConfig { BootstrapServers = config.Value.Kafka.ServerUrl, BrokerAddressFamily = BrokerAddressFamily.V4, }; this.kafkaSettings = config.Value.Kafka; this.producer = new ProducerBuilder <Null, string>(kconfig).Build(); }
static void Main(string[] args) { Kafka kafka = new Kafka(); Task.Run(() => kafka.Consumer()); Mongo mongo = new Mongo(); AssetExpensesManagerImpl expensesManager = new AssetExpensesManagerImpl(mongo, kafka); Console.ReadLine(); }
internal async Task DisableAsync() { Cts.Cancel(); await Task; Task.Dispose(); var stillDisabledEvent = new StillDisabledEvent(Id); Kafka.ProduceEventAsJson(nameof(StillDisabledEvent), stillDisabledEvent); }
internal void Run() { Cts = new CancellationTokenSource(); var stillStartedEvent = new StillStartedEvent(Id); Kafka.ProduceEventAsJson(nameof(StillStartedEvent), stillStartedEvent); Task = Task.Run <Task>( function: ProduceRandomSensorData, cancellationToken: Cts.Token); }
private static void DetectPolice() { Task.Run(async() => { var r = new Random(); while (true) { var randomNumber = r.Next(); if (randomNumber % 10 == 0) { Kafka.ProduceEventAsJson(nameof(PoliceDetectedEvent), new PoliceDetectedEvent(Guid.NewGuid())); } await Task.Delay(500); } }); }
private async Task ProduceRandomSensorData() { int iterationsToRefill = 10; while (!Cts.Token.IsCancellationRequested) { if (!GasTankIsEmpty) { gasCapacity -= 1; } Kafka.ProduceEventAsJson(nameof(StillPingEvent), new StillPingEvent(Id)); var r = new Random(); var randomMashTemperature = Temperatures.TemperaturesValues[r.Next(0, Temperatures.TemperaturesValues.Length)]; var randomDistillateTemperature = Temperatures.TemperaturesValues[r.Next(0, Temperatures.TemperaturesValues.Length)]; Kafka.ProduceEventAsJson(topicName: nameof(StillSensorReadEvent), ev: new StillSensorReadEvent(Id, randomMashTemperature, randomDistillateTemperature, gasCapacity)); await Task.Delay(1000); if (GasTankIsEmpty) { iterationsToRefill -= 1; if (iterationsToRefill <= 0) { gasCapacity = 100; iterationsToRefill = 10; } } } }
private static void ReadSensorData() { Console.WriteLine($"----------BIMBROWNIA AI----------{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}"); Console.WriteLine("Sensor readings:"); if (sensorDataDictionary.IsEmpty) { Console.WriteLine("No stills running"); } else { foreach (var sensorData in sensorDataDictionary.Values.Where(v => !v.Disabled)) { Console.WriteLine($"Still with id: {sensorData.StillId}. Avg. mash temp: {sensorData.AverageMashTemperatureReading} C°. Avg. distillate temp: {sensorData.AverageDistillateTemperatureReading} C°. Gas cpty.: {sensorData.LastGasCapacityPercentage}%"); Console.WriteLine("----------"); if (sensorData.HasRealiableReadings) { if (sensorData.AverageDistillateTemperatureReading > 95) { Kafka.ProduceEventAsJson(topicName: nameof(DangerousDistillateAvgTemperatureEvent), ev: new DangerousDistillateAvgTemperatureEvent(sensorData.StillId, sensorData.AverageDistillateTemperatureReading)); } if (sensorData.AverageMashTemperatureReading > 95) { Kafka.ProduceEventAsJson(topicName: nameof(DangerousMashAvgTemperatureEvent), ev: new DangerousMashAvgTemperatureEvent(sensorData.StillId, sensorData.AverageMashTemperatureReading)); } if (sensorData.LastGasCapacityPercentage <= 0) { Kafka.ProduceEventAsJson(topicName: nameof(GasTankIsEmptyEvent), ev: new GasTankIsEmptyEvent(sensorData.StillId)); } } } } }
public ConsumerService(IOptions <Conventions.SConfig> conf) { this.KafkaConfig = conf.Value.Kafka; }
static void Main(string[] args) { Console.WriteLine("Dispatcher Started"); Kafka.Consumer(); }
public void SendToKafka() => Kafka.SendMessages(messages);
static void Main(string[] args) { Kafka k = new Kafka(); k.ConsumerData(); }