2023-12-24 09:43:23 +08:00
|
|
|
package com.baeldung.partitioningstrategy;
|
|
|
|
|
|
|
|
import org.springframework.kafka.core.KafkaTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class KafkaProducer {
|
|
|
|
|
|
|
|
private final KafkaTemplate<String, String> kafkaTemplate;
|
|
|
|
|
|
|
|
public KafkaProducer(KafkaTemplate<String, String> kafkaTemplate) {
|
|
|
|
this.kafkaTemplate = kafkaTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void send(String topic, String key, String message) {
|
|
|
|
kafkaTemplate.send(topic, key, message);
|
|
|
|
}
|
|
|
|
|
2023-12-25 13:33:22 +08:00
|
|
|
public void send(String topic, Integer partition, String key, String message) {
|
|
|
|
kafkaTemplate.send(topic, partition, key, message);
|
|
|
|
}
|
|
|
|
|
2023-12-25 11:25:53 +08:00
|
|
|
public void send(String topic, String message) {
|
2023-12-24 09:43:23 +08:00
|
|
|
kafkaTemplate.send(topic, message);
|
|
|
|
}
|
|
|
|
}
|