-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Siarhei_Kakichau
committed
Jul 5, 2024
1 parent
f6e4754
commit 563e803
Showing
14 changed files
with
141 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
artifact-processor/src/main/java/org/student/api/MessageProducer.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
artifact-processor/src/main/java/org/student/api/ProcessMessageFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.student.api; | ||
|
||
@FunctionalInterface | ||
public interface ProcessMessageFunction<F, S, T>{ | ||
|
||
void accept(F f, S s, T topic); | ||
|
||
} |
8 changes: 0 additions & 8 deletions
8
artifact-processor/src/main/java/org/student/api/VoidBiFunction.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
artifact-processor/src/main/java/org/student/api/managers/KafkaSendFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.student.api.managers; | ||
|
||
import org.student.messaging.models.BaseArtifactMessage; | ||
|
||
public interface KafkaSendFacade { | ||
<T extends BaseArtifactMessage> void send(String topic, String key, Class<T> messageType, T message); | ||
} |
30 changes: 30 additions & 0 deletions
30
artifact-processor/src/main/java/org/student/api/managers/KafkaSendFacadeImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.student.api.managers; | ||
|
||
import org.student.api.producers.MessageProducer; | ||
import org.student.api.producers.MessageProducerImpl; | ||
import org.student.messaging.models.BaseArtifactMessage; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class KafkaSendFacadeImpl implements KafkaSendFacade { | ||
|
||
private final Map<String, MessageProducer> producers = new ConcurrentHashMap<>(); | ||
private final String bootstrapServer; | ||
|
||
|
||
public KafkaSendFacadeImpl(String bootstrapServer) { | ||
this.bootstrapServer = bootstrapServer; | ||
} | ||
|
||
@Override | ||
public <T extends BaseArtifactMessage> void send(String topic, String key, Class<T> messageType, T message) { | ||
@SuppressWarnings("unchecked") | ||
MessageProducer<T> producer = (MessageProducer<T>) producers.computeIfAbsent(topic, t -> createProducer(messageType, topic)); | ||
producer.send(key, message); | ||
} | ||
|
||
private <T extends BaseArtifactMessage> MessageProducer<T> createProducer(Class<T> messageType, String topic) { | ||
return new MessageProducerImpl<>(bootstrapServer, topic, messageType); | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
artifact-processor/src/main/java/org/student/api/managers/ProducersManager.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
artifact-processor/src/main/java/org/student/api/producers/MessageProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.student.api.producers; | ||
|
||
|
||
import org.student.messaging.models.BaseArtifactMessage; | ||
|
||
public interface MessageProducer<T extends BaseArtifactMessage> { | ||
void send(String key, T message); | ||
} |
42 changes: 42 additions & 0 deletions
42
artifact-processor/src/main/java/org/student/api/producers/MessageProducerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.student.api.producers; | ||
|
||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.ProducerConfig; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.apache.kafka.common.serialization.StringSerializer; | ||
import org.student.messaging.models.BaseArtifactMessage; | ||
import org.student.messaging.models.serializers.JsonSerializer; | ||
|
||
import java.util.Properties; | ||
|
||
public class MessageProducerImpl<T extends BaseArtifactMessage> implements MessageProducer<T> { | ||
|
||
private final KafkaProducer<String, T> producer; | ||
private final String topic; | ||
|
||
public MessageProducerImpl(String bootstrapServers, String topic, Class<T> messageType) { | ||
Properties properties = new Properties(); | ||
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); | ||
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); | ||
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class); | ||
properties.put("value.serializer.type", messageType); | ||
this.producer = new KafkaProducer<>(properties); | ||
this.topic = topic; | ||
} | ||
|
||
@Override | ||
public void send(String key, T message) { | ||
producer.send(new ProducerRecord<>(topic, 1, key, message)); | ||
} | ||
|
||
// public MessageProducerImpl(String bootstrapServers, String topic) { | ||
// Properties properties = new Properties(); | ||
// properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); | ||
// properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); | ||
// properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class); | ||
//// props.put("value.deserializer.type", MyObject.class); | ||
//// ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class | ||
// this.producer = new KafkaProducer<>(properties); | ||
// this.topic = topic; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters