无法使用kafka在solr中提取数据

时间:2018-10-07 10:32:23

标签: java apache-spark solr apache-kafka

我正在尝试使用kafka将数据自动插入solr和banana,但是由于这个原因,对我来说这是不可能的

error in #Convert SolrDocuments

java.lang.NumberFormatException:对于输入字符串:“ 2007”         在java.lang.NumberFormatException.forInputString(NumberFormatException。java:65)         在java.lang.Integer.parseInt(Integer.java:580)         在java.lang.Integer.valueOf(Integer.java:766)         在com.example.streaming.EventParseUtil.convertData(EventParseUtil.java:24)         在com.example.streaming.CarEventsProcessor.lambda $ main $ 91ca40fe $ 1(CarEv entsProcessor.java:76)         在org.apache.spark.api.java.JavaPairRDD $$ anonfun $ toScalaFunction $ 1.appl y(JavaPairRDD.scala:1015)         在scala.collection.Iterator $$ anon $ 11.next(Iterator.scala:328)         在scala.collection.convert.Wrappers $ IteratorWrapper.next(Wrappers.scala:30)         在com.lucidworks.spark.SolrSupport $ 5.call(SolrSupport.java:216)         在com.lucidworks.spark.SolrSupport $ 5.call(SolrSupport.java:210)         在org.apache.spark.api.java.JavaRDDLike $$ anonfun $ foreachPartition $ 1.app ly(JavaRDDLike.scala:225)         在org.apache.spark.api.java.JavaRDDLike $$ anonfun $ foreachPartition $ 1.app ly(JavaRDDLike.scala:225)         在org.apache.spark.rdd.RDD $$ anonfun $ foreachPartition $ 1 $ anonfun $ apply $ 3 5.apply(RDD.scala:927)         在org.apache.spark.rdd.RDD $$ anonfun $ foreachPartition $ 1 $ anonfun $ apply $ 3 5.apply(RDD.scala:927)         在org.apache.spark.SparkContext $$ anonfun $ runJob $ 5.apply(SparkContext.sc ala:1857)         在org.apache.spark.SparkContext $$ anonfun $ runJob $ 5.apply(SparkContext.sc ala:1857)         在org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)         在org.apache.spark.scheduler.Task.run(Task.scala:89)         在org.apache.spark.executor.Executor $ TaskRunner.run(Executor.scala:247)         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor。java:1149)         在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor .java:624)         在java.lang.Thread.run(Thread.java:748) 18/10/06 01:10:08错误执行程序。执行程序:任务1.0在阶段0.0中的异常(T ID 1) java.lang.NumberFormatException:对于输入字符串:“ 2007”         在java.lang.NumberFormatException.forInputString(NumberFormatException。java:65)         在java.lang.Integer.parseInt(Integer.java:580)         在java.lang.Integer.valueOf(Integer.java:766)         在com.example.streaming.EventParseUtil.convertData(EventParseUtil.java:24)         在com.example.streaming.CarEventsProcessor.lambda $ main $ 91ca40fe $ 1(CarEv entsProcessor.java:76)         在org.apache.spark.api.java.JavaPairRDD $$ anonfun $ toScalaFunction $ 1.appl y(JavaPairRDD.scala:1015)         在scala.collection.Iterator $$ anon $ 11.next(Iterator.scala:328)         在scala.collection.convert.Wrappers $ IteratorWrapper.next(Wrappers.scala:30)         在com.lucidworks.spark.SolrSupport $ 5.call(SolrSupport.java:216)         在com.lucidworks.spark.SolrSupport $ 5.call(SolrSupport.java:210)         在org.apache.spark.api.java.JavaRDDLike $$ anonfun $ foreachPartition $ 1.app ly(JavaRDDLike.scala:225)         在org.apache.spark.api.java.JavaRDDLike $$ anonfun $ foreachPartition $ 1.app ly(JavaRDDLike.scala:225)         在org.apache.spark.rdd.RDD $$ anonfun $ foreachPartition $ 1 $ anonfun $ apply $ 3 5.apply(RDD.scala:927)         在org.apache.spark.rdd.RDD $$ anonfun $ foreachPartition $ 1 $ anonfun $ apply $ 3 5.apply(RDD.scala:927)         在org.apache.spark.SparkContext $$ anonfun $ runJob $ 5.apply(SparkContext.sc ala:1857)         在org.apache.spark.SparkContext $$ anonfun $ runJob $ 5.apply(SparkContext.sc ala:1857)         在org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)         在org.apache.spark.scheduler.Task.run(Task.scala:89)         在org.apache.spark.executor.Executor $ TaskRunner.run(Executor.scala:247)         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor。java:1149)         在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor .java:624)         在java.lang.Thread.run(Thread.java:748) 18/10/06 01:10:08错误执行器。执行器:阶段0.0(T ID 0)中的任务0.0异常 java.lang.NumberFormatException:对于输入字符串:“ 2007”         在java.lang.NumberFormatException.forInputString(NumberFormatException。java:65)         在java.lang.Integer.parseInt(Integer.java:580)         在java.lang.Integer.valueOf(Integer.java:766)         在com.example.streaming.EventParseUtil.convertData(EventParseUtil.java:24)         在com.example.streaming.CarEventsProcessor.lambda $ main $ 91ca40fe $ 1(CarEv entsProcessor.java:76)         在org.apache.spark.api.java.JavaPairRDD $$ anonfun $ toScalaFunction $ 1.appl y(JavaPairRDD.scala:1015)         在scala.collection.Iterator $$ anon $ 11.next(Iterator.scala:328)         在scala.collection.convert.Wrappers $ IteratorWrapper.next(Wrappers.scala:30)         在com.lucidworks.spark.SolrSupport $ 5.call(SolrSupport.java:216)         在com.lucidworks.spark.SolrSupport $ 5.call(SolrSupport.java:210)         在org.apache.spark.api.java.JavaRDDLike $$ anonfun $ foreachPartition $ 1.app ly(JavaRDDLike.scala:225)         在org.apache.spark.api.java.JavaRDDLike $$ anonfun $ foreachPartition $ 1.app ly(JavaRDDLike.scala:225)         在org.apache.spark.rdd.RDD $$ anonfun $ foreachPartition $ 1 $ anonfun $ apply $ 3 5.apply(RDD.scala:927)         在org.apache.spark.rdd.RDD $$ anonfun $ foreachPartition $ 1 $ anonfun $ apply $ 3 5.apply(RDD.scala:927)         在org.apache.spark.SparkContext $$ anonfun $ runJob $ 5.apply(SparkContext.sc ala:1857)         在org.apache.spark.SparkContext $$ anonfun $ runJob $ 5.apply(SparkContext.sc ala:1857)         在org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)         在org.apache.spark.scheduler.Task.run(Task.scala:89)         在org.apache.spark.executor.Executor $ TaskRunner.run(Executor.scala:247)         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor。java:1149)         在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor .java:624)         在java.lang.Thread.run(Thread.java:748) 18/10/06 01:10:08错误spark.SolrSupport:将批次发送到集合connectedCar
    数据由于以下原因而失败:org.apache.solr.common.SolrException:找不到集合:
   connectedCarData

我附上完整的代码。

有人怀疑失败可能是什么吗?

public class CarEventsProcessor {

 private CarEventsProcessor() {}

 public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
  if (args.length < 4) {
   System.err
    .println("Usage: CarEventsProcessor <brokers> <topics> <zk_url> <index_name>\n" +
     "  <brokers> is a list of one or more Kafka brokers\n" +
     "  <topics> is a list of one or more kafka topics to consume from\n" +
     " <zk_url> zookeeper url\n" +
     " <index_name> name of solr index\n\n");
   System.exit(1);
  }

  String brokers = args[0];
  String topics = args[1];
  String zk_url = args[2];
  String index_name = args[3];

  ObjectMapper objectMapper = new ObjectMapper();
  objectMapper.registerModule(new DefaultScalaModule());

  // Create context with a 2 seconds batch interval
  SparkConf sparkConf = new SparkConf()
   .setAppName("CarEventsProcessor");
  sparkConf.setMaster("local[4]");

  JavaStreamingContext jssc = new JavaStreamingContext(sparkConf, Durations.seconds(60));
  jssc.sparkContext().setLogLevel("ERROR");

  HashSet < String > topicsSet = new HashSet < String > (Arrays.asList(topics.split(",")));
  HashMap < String, String > kafkaParams = new HashMap < String, String > ();
  kafkaParams.put("metadata.broker.list", brokers);


  // Create direct kafka stream with brokers and topics
  JavaPairInputDStream < String, String > messages = KafkaUtils.createDirectStream(jssc, String.class, String.class,
   StringDecoder.class, StringDecoder.class, kafkaParams, topicsSet);


  // Get the messages and extract payload
  JavaDStream < String > events = messages
   .map(new Function < Tuple2 < String, String > , String > () {
    @Override
    public String call(Tuple2 < String, String > tuple2) {
     return tuple2._2();
    }
   });

  //convert to SolrDocuments
  JavaDStream < SolrInputDocument > parsedSolrEvents = events.map(incomingRecord -> EventParseUtil.convertData(incomingRecord));

  //send to solr
  SolrSupport.indexDStreamOfDocs(zk_url, index_name, 10, parsedSolrEvents);

  parsedSolrEvents.print();
  jssc.start();
  jssc.awaitTermination();
 }
}

1 个答案:

答案 0 :(得分:0)

NumberFormatException: For input string: "2007 "... at com.example.streaming.EventParseUtil.convertData(EventParseUtil.java: 24)

您已在包含空格的字符串上呼叫Integer.parseInt

必须将字符串参数修剪为该方法。

在错误的底部,您没有找到集合。


通常,HDP建议在Solr和Kafka之间获取此数据的方法是使用Nifi