一、  The method iterator() is ambiguous for the type KafkaStream<byte[],byte[]>

最近在学习消息总线Kafka的时候,在IDEA中写了一个简单的生产者和消费者demo。但是消费者端一直报错。错误信息如下:

  1  ConsumerIterator<byte[],byte[]> it =stream.iterator();
2 这句代码老是报错,The method iterator() is ambiguous for the type KafkaStream<byte[],byte[]>

后来博主在网上找了一些资料,解决方法记录一下:

poom.xml文件如下:

  1 <dependencies>
2 <dependency>
3 <groupId>org.apache.kafka</groupId>
4 <artifactId>kafka_2.9.2</artifactId>
5 <version>0.8.1.1</version>
6 <exclusions>
7 <exclusion>
8 <artifactId>jmxtools</artifactId>
9 <groupId>com.sun.jdmk</groupId>
10 </exclusion>
11 <exclusion>
12 <artifactId>jmxri</artifactId>
13 <groupId>com.sun.jmx</groupId>
14 </exclusion>
15 <exclusion>
16 <artifactId>jms</artifactId>
17 <groupId>javax.jms</groupId>
18 </exclusion>
19 <exclusion>
20 <groupId>org.apache.zookeeper</groupId>
21 <artifactId>zookeeper</artifactId>
22 </exclusion>
23 <exclusion>
24 <groupId>org.slf4j</groupId>
25 <artifactId>slf4j-log4j12</artifactId>
26 </exclusion>
27 <exclusion>
28 <groupId>org.slf4j</groupId>
29 <artifactId>slf4j-api</artifactId>
30 </exclusion>
31 </exclusions>
32 </dependency>
33 </dependencies>
34
35 <build>
36 <plugins>
37 <plugin>
38 <artifactId>maven-assembly-plugin</artifactId>
39 <configuration>
40 <descriptorRefs>
41 <descriptorRef>jar-with-dependencies</descriptorRef>
42 </descriptorRefs>
43 <archive>
44 <manifest>
45 <mainClass></mainClass>
46 </manifest>
47 </archive>
48 </configuration>
49 <executions>
50 <execution>
51 <id>make-assembly</id>
52 <phase>package</phase>
53 <goals>
54 <goal>single</goal>
55 </goals>
56 </execution>
57 </executions>
58 </plugin>
59 <!--<plugin>-->
60 <!--<groupId>org.apache.maven.plugins</groupId>-->
61 <!--<artifactId>maven-compiler-plugin</artifactId>-->
62 <!--<version>3.1</version>-->
63 <!--<configuration>-->
64 <!--<source>1.8</source>-->
65 <!--<target>1.8</target>-->
66 <!--<showWarnings>true</showWarnings>-->
67 <!--</configuration>-->
68 <!--</plugin>-->
69 </plugins>
70 </build>

首先将maven中的poom.xml文件中以下内容注释掉:

  1 <plugin>
2 <groupId>org.apache.maven.plugins</groupId>
3 <artifactId>maven-compiler-plugin</artifactId>
4 <version>3.1</version>
5 <configuration>
6 <source>${jdk.version}</source>
7 <target>${jdk.version}</target>
8 <showWarnings>true</showWarnings>
9 </configuration>
10 </plugin>

然后在自己的IDEA MAVEN项目中配置默认jdk版本:

配置方法如下:

第一种:在maven的安装目录找到settings.xml文件,在里面添加如下代码

  1 <profile>
2 <id>jdk-1.8</id>
3 <activation>
4 <activeByDefault>true</activeByDefault>
5 <jdk>1.8</jdk>
6 </activation>
7 <properties>
8 <maven.compiler.source>1.8</maven.compiler.source>
9 <maven.compiler.target>1.8</maven.compiler.target>
10 <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
11 </properties>
12 </profile>

添加完后,在对IDEA进行设置。file->setting->maven->user settings file,user settings file那里选择maven安装目录下的settings.xml文件.

第二种方法是在第一种的基础之上:user settings的默认settigs.xml文件路径为:C:\Users\Administrator\.m2。只要把设置好的settings.xml文件复制到该目录下,然后update project就好了。

二、kafka消费消息的时候一直打印DEBUG org.apache.zookeeper.ClientCnxn - Got ping response for sessionid: 0x3638d0cc1260003 after 0ms

我的问题是因为集群中的zookeeper版本是3.4.5。但是我在IDEA的poom.xml文件中又排除了zookeeper的jar包。将poom.xml文件中对zookeeper的排除注释掉就可以了。

对exclusion解释:

用maven管理库依赖,有个好处就是连同库的依赖的全部jar文件一起下载,免去手工添加的麻烦,但同时也带来了同一个jar会被下载了不同版本的问题,好在pom的配置里面允许用<exclusion>来排除一些不需要同时下载的依赖jar 。

比如配置kafka,它会同时下载jmxri和jmxtools等相关的jar,但版本又不够新,这时可以排除它们:

  1 <dependency>
2 <groupId>org.apache.kafka</groupId>
3 <artifactId>kafka_2.9.2</artifactId>
4 <version>0.8.1.1</version>
5 <exclusions>
6 <exclusion>
7 <artifactId>jmxtools</artifactId>
8 <groupId>com.sun.jdmk</groupId>
9 </exclusion>
10 <exclusion>
11 <artifactId>jmxri</artifactId>
12 <groupId>com.sun.jmx</groupId>
13 </exclusion>
14 <exclusion>
15 <artifactId>jms</artifactId>
16 <groupId>javax.jms</groupId>
17 </exclusion>
18 <!--<exclusion>-->
19 <!--<groupId>org.apache.zookeeper</groupId>-->
20 <!--<artifactId>zookeeper</artifactId>-->
21 <!--</exclusion>-->
22 <exclusion>
23 <groupId>org.slf4j</groupId>
24 <artifactId>slf4j-log4j12</artifactId>
25 </exclusion>
26 <exclusion>
27 <groupId>org.slf4j</groupId>
28 <artifactId>slf4j-api</artifactId>
29 </exclusion>
30 </exclusions>
31 </dependency>

最新文章

  1. C#获取本机可用端口
  2. servlet有关概念
  3. Mac shell 添加VPN 路由
  4. hbase-architecture
  5. Windows2008系统忘记密码的解决方法
  6. Linux磁盘管理命令
  7. HDOJ 1846 Brave Game
  8. 深度分析DataTable如何筛选
  9. java(3) if结构
  10. SQL菜鸟学习札记(二)
  11. C#冒泡法排序源码
  12. R-FCN论文讲解(转载链接)
  13. 【问题与解决】showModalDialog is not defined 的解决方案
  14. 利用 httpmodule 强制所有页面使用同一基类
  15. January 01st, 2018 Week 01st Monday
  16. hdu 4432 第37届ACM/ICPC天津现场赛B题
  17. (最小生成树)QS Network -- ZOJ --1586
  18. Jenkins+github的一次定时构建示例
  19. POJ 1235 Machine Schedule 【二分图】
  20. SVN服务器搭建及客户端配置

热门文章

  1. Linux性能测试 sar命令
  2. 编写可移植C/C++程序的要点(12条)
  3. 汉顺平html5课程分享:6小时制作经典的坦克大战!
  4. BZOJ 3329 Xorequ 数字DP+矩阵乘法
  5. COM编程基础(C++)
  6. WPF 数据模板DataType属性的使用,不用指定ItemTemplate
  7. Asp +Js 无刷新分页
  8. 零元学Expression Blend 4 - Chapter 10 用实例了解布局容器系列-「StackPanel」
  9. WCF nginx反向代理遇到的问题
  10. 让bootstrap表格自动出现水平滚动条