Created
August 6, 2015 02:23
-
-
Save devinrsmith/5466ba2dcffa32583043 to your computer and use it in GitHub Desktop.
Trying to create simple producer with new KafkaProducer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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