franz/topiclister/Program.cs
Adam R Grey 240606336b
Some checks failed
greyn/franz/pipeline/head There was a failure building this commit
gitea/franz/pipeline/head There was a failure building this commit
default run is to list topics
because for some reason auto create is not a thing
2023-05-21 19:02:53 -04:00

52 lines
1.7 KiB
C#

using franz;
using System;
using System.Threading.Tasks;
using System.Linq;
using Confluent.Kafka;
using Confluent.Kafka.Admin;
namespace topiclister
{
class Program
{
static async Task Main(string[] args)
{
try{
var ignoreme = Telefranz.Instance ;
}
catch(NotInitializedException)
{
//gulp, mmm
}
var listOfBs = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(domainAssembly => domainAssembly.GetTypes())
.Where(type => type.IsSubclassOf(typeof(gray_messages.message)) && !type.IsAbstract)
.ToList();
if (listOfBs != null && listOfBs.Any())
{
using (var adminClient = new AdminClientBuilder(new AdminClientConfig { BootstrapServers = "alloces.lan:9092" }).Build())
{
foreach (var b in listOfBs)
{
Console.WriteLine(b.ToString());
try
{
await adminClient.CreateTopicsAsync(new TopicSpecification[] {
new TopicSpecification { Name = b.ToString(), ReplicationFactor = 1, NumPartitions = 1, } });
}
catch (CreateTopicsException e)
{
Console.WriteLine($"An error occured creating topic {e.Results[0].Topic}: {e.Results[0].Error.Reason}");
}
}
}
}
else
{
Console.WriteLine(":(");
}
}
}
}