I've been building Kafka Producer Service. I used ?
wildcard type of generics for key value so it could either be an Integer
String
etc.
@Slf4j
public abstract class ProducerService<T> {
protected KafkaClientConfigProperties properties;
@Autowired
protected KafkaTemplate<?, T> kafkaTemplate;
public void send(T value, Iterable<Header> headers) {
ProducerRecord<?, T> record = new ProducerRecord<>(properties.getTopic(), null, null, null, value, headers);
this.kafkaTemplate.send(record);
}
However upon calling the send
method with an argument of ProducerRecord
i am having an error of
The method send(ProducerRecord<capture#2-of ?,T>) in the type KafkaTemplate<capture#2-of ?,T> is not applicable for the arguments (ProducerRecord<capture#3-of ?,T>)
I also tried
ProducerRecord<String, T> record = new ProducerRecord<>(properties.getTopic(), null, null, null, value, headers);
And having an error of
ProducerRecord<String, T> record = new ProducerRecord<>(properties.getTopic(), null, null, null, value, headers);
Can someone please help me understand what's wrong with the code? Thanks
ProducerService
? – akortex