franz/topiclister/Program.cs

52 lines
1.7 KiB
C#
Raw Normal View History

2022-11-30 18:29:44 -05:00
using franz;
using System;
using System.Threading.Tasks;
2022-11-30 18:29:44 -05:00
using System.Linq;
using Confluent.Kafka;
using Confluent.Kafka.Admin;
2022-11-30 18:29:44 -05:00
namespace topiclister
{
class Program
{
static async Task Main(string[] args)
2022-11-30 18:29:44 -05:00
{
try{
var ignoreme = Telefranz.Instance ;
}
catch(NotInitializedException)
{
//gulp, mmm
}
2022-11-30 18:29:44 -05:00
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())
2022-11-30 18:29:44 -05:00
{
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}");
}
}
2022-11-30 18:29:44 -05:00
}
}
else
{
Console.WriteLine(":(");
}
2022-11-30 18:29:44 -05:00
}
}
}