各位大神,我是初学者,今天接触kafka。我想在kafka上运行自己写的生产者程序,怎么做?

0
已邀请:
1

为了明天time - hadoop hive 大数据 java python 2015-10-12 回答

public class ProducerTest {
 @test
 public void test() throws Exception {
  Properties props = new Properties();
  props.put("metadata.broker.list", "192.168.1.104:9092");
  props.put("serializer.class", StringEncoder.class.getName());
  
  ProducerConfig producerConfig = new ProducerConfig(props);
  Producer<String, String> producer = new Producer<String,String>(producerConfig);
  
  KeyedMessage<String, String> message = new KeyedMessage<String, String>("topic1", "message aaaaaaaaaa");
  producer.send(message);
 }
}
就类似这样的吧  进行消息发送

要回复问题请先登录注册