コード例 #1
0
 public void publish(byte[] event, String Id) throws ExecutionException, InterruptedException {
   logger.debug("Send message");
   RecordMetadata m =
       kafkaProducer.send(new ProducerRecord<String, byte[]>("events", Id, event)).get();
   System.out.println("Message produced, offset: " + m.offset());
   System.out.println("Message produced, partition : " + m.partition());
   System.out.println("Message produced, topic: " + m.topic());
 }
コード例 #2
0
ファイル: ProducerOne.java プロジェクト: ggj2010/javabase
 private static void test(Producer<String, String> producer) {
   for (int i = testNumber; i > 0; i--) {
     // partion 随机
     //            ProducerRecord record = new ProducerRecord<String, String>(TopicOne.TOPIC, i%2,
     // i+"", i+"");
     ProducerRecord record = new ProducerRecord<String, String>(TopicOne.TOPIC, 0, i + "", i + "");
     producer.send(record);
   }
 }
 public void onStatus(Status status) {
   Tweet tweet = TwitterUtils.parseTweet(status);
   ProducerRecord<String, Tweet> data = new ProducerRecord<String, Tweet>(topic, tweet);
   producer.send(data);
 }