title: Spring-boot batch file read and send data to Kafka
body: <p>I am having trouble sending data from CSV file to Kafka. Here is my code for writer.java for batch processing </p>
  
  <hr>
  
  <pre><code>import java.util.List;
  
  import javax.persistence.criteria.CriteriaBuilder.In;
  
  import org.springframework.batch.item.ItemWriter;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.kafka.core.KafkaTemplate;
  
  import com.codenotfound.kafka.repository.*;
  
  import java.util.*;
  
  import com.codenotfound.kafka.Car;
  import com.codenotfound.kafka.producer.Sender;
  
  
  public class Writer implements ItemWriter&lt;Car&gt;{
  
      private final Repository repo;
  
      public Writer(Repository repo) {
          this.repo = repo ;       
      }
  
      @Override
      public void write(List&lt;? extends Car&gt; car) throws Exception {
          repo.save(car);
      }   
  }
  </code></pre>
  
  <p>So instead of <strong>repo.save(car)</strong>, I want this car class details to be sent to Kafka.
  Here is my Car class and Repository interface respectively</p>
  
  <hr>
  
  <pre><code>@Entity
  @Table(name = "Car")
  
  public class Car {
  
  
    private String make;
  
    private String manufacturer;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
  
    public Car() {
      //super();
    }
  
    public Car(String make, String manufacturer) {
      super();
      this.make = make;
      this.manufacturer = manufacturer;
    }
  
    public String getMake() {
      return make;
    }
  
    public void setMake(String make) {
      this.make = make;
    }
  
    public String getManufacturer() {
      return manufacturer;
    }
  
  
    public void setManufacturer(String manufacturer) {
      this.manufacturer = manufacturer;
    }
  
    public long getId() {
      return id;
    }
  
  
    public void setId(long id) {
      this.id = id;
    }
  
    @Override
    public String toString() {
      return "Car [make=" + make + ", manufacturer=" + manufacturer + ", id=" + id + "]";
    }
  }   
  </code></pre>
  
  <hr>
  
  <p>and Repository class</p>
  
  <hr>
  
  <pre><code>public interface Repository extends CrudRepository&lt;Car, Long&gt;,CustomRepository {
  }
  </code></pre>
  
  <hr>
  
  <p>My Sender file for Kafka is:</p>
  
  <hr>
  
  <pre><code>package com.codenotfound.kafka.producer;
  
  import java.util.List;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.kafka.core.KafkaTemplate;
  
  import com.codenotfound.kafka.Car;
  
  public class Sender {
  
    private static final Logger LOGGER = LoggerFactory.getLogger(Sender.class);
  
    @Value("${topic.json}")
    private String jsonTopic;
  
    @Autowired
    private KafkaTemplate&lt;String, Car&gt; kafkaTemplate;
  
    public void send(Car car) {
      LOGGER.info("sending car='{}'", car.toString());
      kafkaTemplate.send(jsonTopic, car);
    }
  }
  </code></pre>
  
  <hr>
  
  <p>Please suggest to me a method to send data from a CSV file to my Kafka.</p>