缺少必要的参数" [authorizer-properties]" apache kafka简单的生产者api错误

时间:2017-11-22 08:52:02

标签: apache-kafka kafka-producer-api apache-kafka-connect

在eclipse中编写kafka生成器代码时,我在下面提到错误提示,在这里我想编写一个简单的生产者代码并在kafka控制台消费者上显示消息我启动了zookeeper和kafka服务器并完美地创建了主题。

这是代码:

import java.util.Properties;
import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;

public class ProducerTest {
    public static void mian(String ar[]){
        Properties prop=new Properties();

        prop.put("zk.connect","localhost:2181");
        prop.put("serializer.class","kafka.serializer.StringEncoder");
        prop.put("metadata.broker.list","localhost:9092");

        ProducerConfig config=new ProducerConfig(prop);

        Producer producer=new Producer(config);

        String msg="Sa resta rasta ra";

        producer.send(new KeyedMessage("test",msg));
    }
} 

Missing required argument "[authorizer-properties]"
Option                                  Description                            
----*emphasized text*--                                  -----------                            
--add                                   Indicates you are trying to add ACLs.  
--allow-host <allow-host>               Host from which principals listed in --
                                       allow-principal will have access. If 
                                        you have specified --allow-principal 
                                         then the default for this option     
                                          will be set to * which allows access 
                                          from all hosts.                      
--allow-principal <allow-principal>     principal is in principalType:name     
                                         format. User:* is the wild card  

任何人都可以帮我解决这个错误。

1 个答案:

答案 0 :(得分:0)

我不知道为什么我收到此错误消息但是现在它已经自动消失我只是创建了分离的连接方法并从main方法调用此方法。

 public static void main(String ar[]){
 ProducerTest producer=new ProducerTest();
 producer.messageConnetion();
 }

 public void messageConnetion(){
 Properties properties=new Properties();

 properties.put("zk.connect","localhost:8121");
 properties.put("serializer.class","kafka.serializer.StringEncoder");
 properties.put("metadata.broker.list","localhost:9092");

 ProducerConfig config=new ProducerConfig(prop);

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

 producer.send(new KeyedMessage<String, String> ("test","JaySiyaRam"));
}