Skip to content

Commit

Permalink
KafkaSender utility for å unngå lokale topics (#1352)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolarsen authored Mar 25, 2024
1 parent d6860c3 commit e70699a
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@
public class KafkaSender {

private final Producer<String, String> producer;
private final String topic;
private final String topicName;

public KafkaSender(String topic) {
public KafkaSender(String topicName) {
this.producer = new KafkaProducer<>(KafkaProperties.forProducer());
this.topic = topic;
this.topicName = topicName;
}

public String getTopicName() {
return topicName;
}

public RecordMetadata send(String key, String message) {
if (topic == null) {
if (topicName == null) {
throw kafkaPubliseringException("null", new IllegalArgumentException());
}
return send(key, message, this.topic);
return send(key, message, this.topicName);
}

public RecordMetadata send(String key, String message, String topic) {
Expand Down

0 comments on commit e70699a

Please sign in to comment.