Code for the Sample Java Producer

Use this sample producer when you follow the steps in "Getting Started with MapR Streams".

import org.apache.kafka.clients.producer.KafkaProducer;
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 producer;
    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException, TimeoutException {
        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<String, String> rec = new ProducerRecord<String, String>(topic, 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(String[] args) {
        Properties props = new Properties();
        producer = new KafkaProducer<String, String>(props);