Hi, All

I am running the kafka producer code:

import java.util.*;

import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;

public class TestProducer {
    public static void main(String[] args) {
        long events = Long.parseLong(args[0]);
        Random rnd = new Random();

        Properties props = new Properties();
        props.put("metadata.broker.list", "10.100.70.128:9092,
10.100.70.128:9093,10.100.70.128:9094");
        props.put("serializer.class", "kafka.serializer.StringEncoder");
        props.put("partitioner.class", "example.producer.SimplePartitioner"
);
        props.put("request.required.acks", "1");

        ProducerConfig config = new ProducerConfig(props);

        Producer<String, String> producer = new Producer<String,
String>(config);

        for (long nEvents = 0; nEvents < events; nEvents++) {
               long runtime = new Date().getTime();
               String ip = “192.168.2.” + rnd.nextInt(255);
               String msg = runtime + “,www.example.com,” + ip;
               KeyedMessage<String, String> data = new KeyedMessage<String,
String>("page_visits", ip, msg);
               producer.send(data);
        }
        producer.close();
    }
}

It should be straightforwards, but when I compile it in IntelliJ IDEA, I
got such error
 Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile
(default-compile) on project kafka-producer: Compilation failure
[ERROR]
C:\Users\sa\Desktop\Workload\kafka\kafkaprj\kafka-json-producer\src\main\java\kafka\example\TestProducer.java:[35,20]
error: cannot access Serializable, which is the producer object.

Any idea of this?

thanks

-- 

Alec Li

Reply via email to