From 4aa3162f06a863d7a5c3e9eb61d5eab4dc0f39b6 Mon Sep 17 00:00:00 2001 From: "Adam R. Grey" Date: Sat, 19 Jun 2021 04:49:08 -0400 Subject: [PATCH] puttiing this on hold because suddenly I hate kafka I should have just said "cool thing, let me just ctrl+f /.Factory\b/, oh. [delete]" --- Config.cs | 20 ++++++++ Program.cs | 93 +++++++++++++------------------------- appsettings.example.json | 11 ++++- directors-assistant.csproj | 3 ++ 4 files changed, 64 insertions(+), 63 deletions(-) create mode 100644 Config.cs diff --git a/Config.cs b/Config.cs new file mode 100644 index 0000000..de1daf1 --- /dev/null +++ b/Config.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +public class Config +{ + public string name { get; set; } = "guy who didn't configure"; + public string bootstrap_servers { get; set; } = "localhost:9092"; + public string handling_group { get; set; } = null; + public string kafka_location { get; set; } = "/usr/lib/librdkafka.so"; + public Dictionary topics { get; set; } = new Dictionary() { + {"global", "silver_meddlists.global"}, + {"directorial", "silver_meddlists.directorial"} + }; + public class Command + { + public string name { get; set; } + public string shell { get; set; } + } + public List commands { get; set; } = new List() { new Command() { name = "echo", shell = "echo" } }; + public List checks { get; set; } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 7a29d49..50ec975 100644 --- a/Program.cs +++ b/Program.cs @@ -1,74 +1,45 @@ -using Confluent.Kafka; -using Microsoft.Extensions.Configuration; +using franz; +using Newtonsoft.Json; using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Net.Http; using System.Threading; +using System.Threading.Tasks; namespace directors_assistant { class Program { - static void Main(string[] args) - { - - var config = new ConfigurationBuilder() - .AddJsonFile("appsettings.json", true, true) - .Build(); - - Library.Load(config["kafka location"]); - var producerConfig = new ProducerConfig - { - BootstrapServers = config["bootstrap servers"] - }; - var consumerConfig = new ConsumerConfig - { - BootstrapServers = config["bootstrap servers"], - GroupId = config["handling group"], - }; - - using (var producer = new ProducerBuilder(producerConfig).Build()) - { - try + public static Config conf; + public static Telefranz telefranz; + static async Task Main(string[] args) + { + conf = JsonConvert.DeserializeObject(File.ReadAllText("appsettings.json")); + telefranz = new Telefranz(conf.name, conf.bootstrap_servers, conf.kafka_location, + new List(){"proof_of_concept"}); + telefranz.addHandler((silver_messages.directorial.execute_command ec) => { + Console.WriteLine("for FUCK'S sake"); + Console.WriteLine(JsonConvert.SerializeObject(ec)); + if(ec.command == "proof_of_concept") { - producer.Produce(config["topic"], new Message { Value = "" + config["handling group"] }); - } - catch (ProduceException e) - { - Console.WriteLine($"Delivery failed: {e.Error.Reason}"); + Console.WriteLine("it's a POC"); + var content = new StringContent("{\"username\": \"" + conf.name +"\", \"content\": \"hi\"}"); + var client = new HttpClient(); + client.DefaultRequestHeaders.Add("Content-Type", "application/json"); + client.PostAsync("super secret url", + content); + Console.WriteLine("I'm P-O-C, I'm dyn-o-mite"); } + Console.WriteLine("it's not a proof of concept call"); + }); + Console.WriteLine("off we go"); + telefranz.StartListening(); - - - using (var consumer = new ConsumerBuilder(consumerConfig).Build()) - { - consumer.Subscribe(config["topic"]); - - CancellationTokenSource cts = new CancellationTokenSource(); - Console.CancelKeyPress += (_, e) => - { - e.Cancel = true; // prevent the process from terminating. - cts.Cancel(); - }; - try - { - while (true) - { - try - { - var cr = consumer.Consume(cts.Token); - Console.WriteLine($"Consumed message '{cr.Message.Value}' at: '{cr.TopicPartitionOffset}'."); - } - catch (ConsumeException e) - { - Console.WriteLine($"Error occured: {e.Error.Reason}"); - } - } - } - catch (OperationCanceledException) - { - consumer.Close(); - } - } - } + await Task.Delay(20000); + Console.WriteLine("alright fuck it"); } } } diff --git a/appsettings.example.json b/appsettings.example.json index 740cc6c..4ae86df 100644 --- a/appsettings.example.json +++ b/appsettings.example.json @@ -1,7 +1,14 @@ { "name": "guy who didn't configure", "bootstrap servers": "localhost:9092", - "handling group": "foo", + "handling group": "directors_assistant.foo", "kafka location": "/usr/lib/librdkafka.so", - "topic": "SM" + "topics": [ + "silver_meddlists.global", + "silver_meddlists.directorial" + ], + "commands": [ + {"name":"echo", "shell": "echo"} + ], + "checks": [] } \ No newline at end of file diff --git a/directors-assistant.csproj b/directors-assistant.csproj index 814fed8..5d1662c 100644 --- a/directors-assistant.csproj +++ b/directors-assistant.csproj @@ -4,6 +4,7 @@ Exe net5.0 directors_assistant + $(RestoreSources);../pkgs while i procastinate on a feed;https://api.nuget.org/v3/index.json @@ -11,6 +12,8 @@ + +