2017-11-22 29 views
0

kafka 제작자 코드를 일식에 쓰는 동안 아래에 오류 설명이 표시됩니다. 여기 간단한 제작자 코드를 작성하고 kafka 콘솔에 메시지를 표시하고 싶습니다. 소비자 내가 사육사와 카프카 서버를 시작하고 주제를 완벽하게 만들었습니다.필수 인수가 없습니다. "[authorizer-properties]"apache kafka 간단한 제작자 API 오류

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 

사람이 날이 오류를 해결하기 위해 도와주세요 : 여기

는 코드입니다.

+0

모든 나는 해결책을 얻었는지, 내가 main 메소드를 포함하는 다른 클래스를 생성하고 난 ProducerTest 클래스의 주요 메소드를 제거하고 잘 작동하는 메소드를 호출하여 간단한 무효 방법에 코드를 넣어. –

답변

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")); 
}