Sample Java Producer

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

public class SampleProducer {
    // Set the stream and topic to publish to.
    public static String topic = "/<path to and name of the stream>:<name of topic>";
    // Set the number of messages to send.
    public static int numMessages = 50;

    // Declare a new producer.
    public static KafkaProducer<Integer, String> producer;

    public static void main(String[] args) {

        for(int i = 0; i < numMessages; i++) {
            // Set content of each message.
            String messageText = "Msg " + i;

           /* Add each message to a record. A ProducerRecord object
              identifies the topic or specific partition to publish
	       a message to. */
            ProducerRecord<Integer, String> rec = new ProducerRecord(topic, i, messageText);

            // Send the record to the producer client library.
            System.out.println("Sent message number " + i);
        System.out.println("All done.");

    /* Set the value for a configuration parameter.
       This configuration parameter specifies which class
       to use to serialize the value of each message. */
    public static void configureProducer() {
        Properties props = new Properties();
        producer = new KafkaProducer(props);

For additional information, see