360SDN.COM

elasticsearch使用TransportClient初始化抛异常io.netty.util.internal.ObjectUtil.ch

来源:  2018-08-31 19:41:02    评论:0点击:

来源:https://blog.csdn.net/hyneria_hope/article/details/79136380

elasticsearch使用TransportClient初始化抛异常io.netty.util.internal.ObjectUtil.checkPositiv
Caused by: java.lang.NoSuchMethodError: io.netty.util.internal.ObjectUtil.checkPositive(ILjava/lang/String;)I
at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:44)
~[netty-common-4.1.13.Final.jar:4.0.33.Final]
at io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:87)
~[netty-common-4.1.13.Final.jar:4.0.33.Final]

elasticsearch 5.5使用TransportClient初始化抛异常

 es版本说明

  • elasticsearch 5.5.3版本

 maven依赖包

  • elasticsearch java client包
 
<dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>x-pack-transport</artifactId>
      <version>5.6.0</version>
</dependency>
  • netty依赖包
<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.13.Final</version>
</dependency>

  • elasticsearch 6.*版本使用TransportClient初始化抛异常io.netty.util.internal.ObjectUtil.checkPositive,需要使用 netty 4.1.16.Final版本依赖包
  • <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.1.16.Final</version>
    </dependency>
    
    

     初始化client异常信息

    elasticsearch 集群安装x-pack插件,如果直接使用TransportClient无法连接到es集群,需要使用XPackTransportClient进行连接,需要添加x-pack-transport包,添加完后初始化client时抛出以下异常信息:

    Caused by: java.lang.NoSuchMethodError: io.netty.util.internal.ObjectUtil.checkPositive(ILjava/lang/String;)I
        at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:44) ~[netty-common-4.1.13.Final.jar:4.0.33.Final]
        at io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:87) ~[netty-common-4.1.13.Final.jar:4.0.33.Final]
    	
    	
     
    

    解决方法,只需要在初始化方法前添加

    // 避免netty冲突
    System.setProperty("es.set.netty.runtime.available.processors", "false");

    解决netty冲突后初始化client时还会抛出异常,异常信息如下:

    Caused by: java.lang.NoSuchMethodError: io.netty.buffer.CompositeByteBuf.addComponents(ZLjava/lang/Iterable;)Lio/netty/buffer/CompositeByteBuf;
        at org.elasticsearch.transport.netty4.Netty4Utils.toByteBuf(Netty4Utils.java:117) ~[transport-netty4-client-5.6.0.jar:5.6.0]
        at org.elasticsearch.transport.netty4.Netty4Transport.sendMessage(Netty4Transport.java:395) ~[transport-netty4-client-5.6.0.jar:5.6.0]

    netty版本冲突,低版本的netty启动时会抛异常,需要添加高版本的netty依赖,请看maven依赖包 项,将两项添加到你的pom.xml既可,如果还有问题请留言

    为您推荐

    友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
     Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权