Skip to content

Instantly share code, notes, and snippets.

@devinrsmith
Created August 6, 2015 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinrsmith/5466ba2dcffa32583043 to your computer and use it in GitHub Desktop.
Save devinrsmith/5466ba2dcffa32583043 to your computer and use it in GitHub Desktop.
Trying to create simple producer with new KafkaProducer
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
/**
* Created by dsmith on 8/5/15.
*/
public class SimpleProducer {
public static void main(String[] args) throws ExecutionException, InterruptedException {
Properties props = new Properties();
props.put("bootstrap.servers", args[0]);
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("metadata.fetch.timeout.ms", 1000);
final Producer<String, String> producer = new KafkaProducer<>(props);
producer.send(new ProducerRecord<>("test-topic", "test-key", "test-value")).get();
producer.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment