title: Apache kafka separate producer and consumer
body: <p>I have multiple servers from where the messages will be produced, and I need broker and consumer at one server.
  If I have both producer and consumer running on same server then it works fine, but not sure what changes need to be done to keep producers separate. I don't want any dependency of zookeeper and kafka servers at producer servers as there are many and they will increase. 
  I tried with changing bootstrap server to the broker/consumer server like 192.168.0.1:9092 while setting up KafkaProducer but still not able to generate messages. Not sure what am I missing, please help me out here.</p>
  
  <p><strong>producer.props</strong></p>
  
  <pre><code>bootstrap.servers=192.168.0.1:9092
  acks=all
  retries=0
  batch.size=16384
  auto.commit.interval.ms=1000
  linger.ms=0
  key.serializer=org.apache.kafka.common.serialization.StringSerializer
  value.serializer=org.apache.kafka.common.serialization.StringSerializer
  block.on.buffer.full=true
  </code></pre>
  
  <p><strong>Producer code</strong></p>
  
  <pre><code>public class Producer {
      public static void main(String[] args) throws IOException {
          // set up the producer
          KafkaProducer&lt;String, String&gt; producer;
          System.out.println("1");
          try (InputStream props = Resources.getResource("producer.props").openStream()) {
              Properties properties = new Properties();
              properties.load(props);
              producer = new KafkaProducer&lt;&gt;(properties);
          }
  
          try {
              for (int i = 0; i &lt; 1000000; i++) {
  
                  // send lots of messages
                  System.out.println("bedore send");
                      producer.send(new ProducerRecord&lt;String, String&gt;(
                              "fast-messages",
                              String.format("{\"type\":\"marker\", \"t\":%.3f, \"k\":%d}", System.nanoTime() * 1e-9, i)));
                      producer.send(new ProducerRecord&lt;String, String&gt;(
                              "summary-markers",
                              String.format("{\"type\":\"other\", \"t\":%.3f, \"k\":%d}", System.nanoTime() * 1e-9, i)));
                      producer.flush();
                      System.out.println("Sent msg number " + i);
              }
              System.out.println("fdone");
          } catch (Throwable throwable) {
              throwable.printStackTrace();
              System.out.printf("%s", throwable.getStackTrace());
          } finally {
              producer.close();
          }
  
      }
  }
  </code></pre>