Our Reader invokes the process() method; this method belonging to the Producer class. As with the consumer interface, the producer interface encapsulates all of the common behavior of the Kafka producers. The two producers in this chapter implement this producer interface.
In a file called Producer.java, located in the src/main/java/monedero directory, copy the content of Listing 2.6:
package monedero;
import java.util.Properties;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
public interface Producer {
void process(String message); //1
static void write(KafkaProducer<String, String> producer,
String topic, String message) { //2
ProducerRecord<String, String> pr = new ProducerRecord<>(topic, message);
producer...