• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Apache Kafka + Apache Camel集成+ POC问题java.util.Hashtable.put上的java.lang.NullPointerException(Hashtable.java:459)

java 来源:Pallavi Gupta 4次浏览

这是我的路由生成器。在这里,我试图从我的文件插入数据topic.Later,我通过我的主要方法,并使用骆驼上下文我运行它。我尝试了几个代码,但没有人帮助我。我正在开发Apache kafka的POC – 骆驼。Apache Kafka + Apache Camel集成+ POC问题java.util.Hashtable.put上的java.lang.NullPointerException(Hashtable.java:459)

public class SimpleRouteBuilder extends RouteBuilder { 

    @Override 
    public void configure() throws Exception { 

     String topicName = "test120"; 
     String kafkaServer = "kafka:localhost:9092"; 
     String zooKeeperHost = "zookeeperHost=localhost&zookeeperPort=2181"; 
     String serializerClass = "serializerClass=kafka.serializer.StringEncoder"; 

     String toKafka = "kafka:localhost:9092?topic=test120;zookeeperHost=localhost;zookeeperPort=2181;groupId=group1"; 


    // toKafka = new StringBuilder().append("&").append(serializerClass).toString(); 

       /*new StringBuilder().append(kafkaServer).append("?").append(topicName).append("&") 
       .append(zooKeeperHost).append("&").append(serializerClass).toString();*/ 

     from("file:C:/inbox?noop=true").to(toKafka); 


    } 
} 

这是我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>HelloWorld</groupId> 
    <artifactId>Pallavi</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <dependencies> 
     <dependency> 
      <groupId>org.apache.camel</groupId> 
      <artifactId>camel-core</artifactId> 
      <version>2.20.1</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.camel</groupId> 
      <artifactId>camel-kafka</artifactId> 
      <version>2.20.1</version> 
     </dependency> 

     <dependency> 
      <groupId>org.scala-lang</groupId> 
      <artifactId>scala-library</artifactId> 
      <version>2.11.0</version> 
     </dependency> 
    </dependencies> 

</project> 

这是我的主类:

import org.apache.camel.CamelContext; 
import org.apache.camel.impl.DefaultCamelContext; 

public class MainApp { 

    public static void main(String[] args) { 
     SimpleRouteBuilder routeBuilder = new SimpleRouteBuilder(); 
     CamelContext ctx = new DefaultCamelContext(); 
     try { 
      ctx.addRoutes(routeBuilder); 
      ctx.start(); 
      Thread.sleep(5 * 60 * 1000); 
      ctx.stop(); 
      System.out.println("hi i am working"); 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
     } 

    } 
} 

错误是:

java.lang.NullPointerException 
    at java.util.Hashtable.put(Hashtable.java:459) 
    at org.apache.camel.component.kafka.KafkaProducer.getProps(KafkaProducer.java:63) 
    at org.apache.camel.component.kafka.KafkaProducer.doStart(KafkaProducer.java:89) 
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:75) 
    at org.apache.camel.impl.DeferServiceStartupListener.onCamelContextStarted(DeferServiceStartupListener.java:49) 
    at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3859) 
    at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3638) 
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3490) 
    at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:208) 
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3249) 
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3245) 
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3268) 
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3245) 
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3168) 
    at demo.MainApp.main(MainApp.java:13) 
Picked up _JAVA_OPTIONS: -Xmx512M -Xms512M 


===========解决方案如下:

您需要配置brokers选项在端点上。或者在全球的kafka组件上。

我已经登录了票,使骆驼在报告在下一个版本一个更好的异常:https://issues.apache.org/jira/browse/CAMEL-12090

这里有一个例子卡夫卡,你可以看看太:https://github.com/apache/camel/tree/master/examples/camel-example-kafka


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)