private volatile boolean running = true;
private volatile boolean done = false;
- public SimpleProducer(String broker, String topic, String id)
+ public SimpleProducer(String broker, String topic, String clientId)
{
Properties props = new Properties();
props.put("bootstrap.servers", broker);
- props.put("client.id", id); // Nur zur Wiedererkennung
+ props.put("client.id", clientId); // Nur zur Wiedererkennung
props.put("key.serializer", StringSerializer.class.getName());
props.put("value.serializer", StringSerializer.class.getName());
producer = new KafkaProducer<>(props);
this.topic = topic;
- this.id = id;
+ this.id = clientId;
}
public void run()
broker = args[0];
}
- SimpleProducer producer = new SimpleProducer(broker, topic, clientId);
+ SimpleProducer instance = new SimpleProducer(broker, topic, clientId);
Runtime.getRuntime().addShutdownHook(new Thread(() ->
{
- producer.running = false;
- while (!producer.done)
+ instance.running = false;
+ while (!instance.done)
{
- log.info("Waiting for producer...");
+ log.info("Waiting for main-thread...");
try
{
Thread.sleep(1000);
}));
log.info(
- "Running simple producer: broker={}, topic={}, client-id={}",
+ "Running SimpleProducer: broker={}, topic={}, client-id={}",
broker,
topic,
clientId);
- producer.run();
+ instance.run();
}
}