Skip to content
Create a gist now

Instantly share code, notes, and snippets.

standalone producer
package com.trendrr.shared.kafka;
import java.util.HashMap;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicLong;
import kafka.javaapi.producer.Producer;
import kafka.javaapi.producer.ProducerData;
import kafka.producer.ProducerConfig;
public class StandaloneProducer {
public static String brokerlist = "1:broker1:9092 , 2:broker2:9092 , 3:broker3:9092 , 4:broker4:9092 , 5:broker5:9092";
public static AtomicLong counter = new AtomicLong(0l);
public static void main(String[] args){
Properties props = new Properties();
props.put("broker.list", brokerlist);
props.put("serializer.class", "kafka.serializer.StringEncoder");
props.put("producer.type", "async");
props.put("compression.codec", "1");
Producer<Integer, String> p = new Producer<Integer, String>(new ProducerConfig(props));
for (int i=0; i < 100000; i++) {
p.send(new ProducerData<Integer, String>("test_topic_1", Long.toString(counter.getAndIncrement())));
System.out.println("WROTE: " + counter.get() + " messages");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.