automated-testing-demo/producer/Producer.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2024-06-14 13:42:51 +00:00
using System;
2024-06-14 14:48:52 +00:00
using System.Text.Json;
2024-06-14 13:42:51 +00:00
using System.Threading.Tasks;
using Confluent.Kafka;
2024-06-14 14:48:52 +00:00
using Serializers;
2024-06-14 13:42:51 +00:00
using Model;
2024-06-14 21:06:24 +00:00
using Publisher;
2024-06-14 13:42:51 +00:00
class Producer
{
public static string TOPIC_NAME = "test-topic";
2024-06-14 13:42:51 +00:00
public static async Task Main (string[] args)
{
2024-06-14 21:06:24 +00:00
string bootstrapServers = "localhost:29092";
var DataPublisher = new DataPublisher(TOPIC_NAME, bootstrapServers);
2024-06-14 13:42:51 +00:00
string introText = "\nType a string of text then press Enter. Type '+' anywhere in the text to quit:\n";
var input = "";
2024-06-14 21:06:24 +00:00
Console.WriteLine(introText);
do
2024-06-14 13:42:51 +00:00
{
2024-06-14 21:06:24 +00:00
input = Console.ReadLine();
try
{
if (input != String.Empty)
2024-06-14 13:42:51 +00:00
{
2024-06-14 21:06:24 +00:00
var data = new DataModel()
2024-06-14 13:42:51 +00:00
{
2024-06-14 21:06:24 +00:00
message = input
};
2024-06-14 13:42:51 +00:00
2024-06-14 21:06:24 +00:00
await DataPublisher.Publish(data);
}
2024-06-14 21:06:24 +00:00
}
catch (OverflowException e)
{
Console.WriteLine("An error has occurred", e.Message, input);
Console.WriteLine(introText);
}
}
while (input != "+");
2024-06-14 13:42:51 +00:00
}
}