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