缺少必需的参数“[authorizer properties]”apache kafka simple producer api错误

i2byvkas  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(645)

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

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

任何人请帮我解决这个错误。

hmmo2u0o

hmmo2u0o1#

我不知道为什么会收到这个错误消息,但是现在它自动消失了,我只是为连接创建了一个分离的方法,并从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"));
}

相关问题