package apache.kafka.producer.java;

import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;

import java.util.Properties;
import java.util.Random;

/**
 * Project Name: KafkaProducer (Java)
 * Dated: April 04, 2016
 */

class MyProducer {
    // Variables
    private String topic;
    private int events;
    private long intraEventDuration;

    // Kafka Producer
    private Producer<String, String> kafkaProducer;

    MyProducer(String kafkaBroker, String topic, int events, long intraEventDuration) {
        this.topic = topic;
        this.events = events;
        this.intraEventDuration = intraEventDuration;

        // setting up properties to be used to communicate to kafka
        Properties props = new Properties();
        props.put("metadata.broker.list", kafkaBroker);
        props.put("serializer.class", "kafka.serializer.StringEncoder");
        props.put("partitioner.class", "kafka.producer.DefaultPartitioner");
        props.put("request.required.acks", "1");
        ProducerConfig config = new ProducerConfig(props);

        kafkaProducer = new Producer<>(config);
    }

    void processAndPush() throws InterruptedException {
        String myData;
        Random random = new Random();

        KeyedMessage<String, String> message;

        for(int i = 0 ; i <= this.events ; i++) {
            myData = "<" + random.nextFloat() + ">";
            message = new KeyedMessage<>(this.topic, myData);
            System.out.println("Data Produced => " + message);
            this.kafkaProducer.send(message);

            Thread.sleep(this.intraEventDuration);
        }

        kafkaProducer.close();
    }
}
@@ -1,8 +1,608 @@
+/**%0A * Copyright 2016 Ankit Sarraf%0A * %0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * %0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A %0A
 package 
@@ -2295,8 +2295,9 @@
 %0A    %7D%0A%7D
+%0A

Update MyProducer.java