Search code examples
javacassandraelasticsearch-5datastax-java-driver

Exception while calling cassandra and elastic search from same program


I am trying to index my data at cassandra to elastic-search hosted in cloud. I am able to connect and index dummy data with elastic-search easily using transport client. But, when I add datastax driver dependency in my pom file to connect to cassandra I get following exeptions. Weird thing is I am not even connecting to the cassandra clusters. Thanks in advance

Exception in thread "main" java.lang.AbstractMethodError: io.netty.util.concurrent.MultithreadEventExecutorGroup.newChild(Ljava/util/concurrent/Executor;[Ljava/lang/Object;)Lio/netty/util/concurrent/EventExecutor; at io.netty.util.concurrent.MultithreadEventExecutorGroup.(MultithreadEventExecutorGroup.java:84) at io.netty.util.concurrent.MultithreadEventExecutorGroup.(MultithreadEventExecutorGroup.java:58) at io.netty.util.concurrent.MultithreadEventExecutorGroup.(MultithreadEventExecutorGroup.java:47) at io.netty.channel.MultithreadEventLoopGroup.(MultithreadEventLoopGroup.java:49) at io.netty.channel.nio.NioEventLoopGroup.(NioEventLoopGroup.java:68) at io.netty.channel.nio.NioEventLoopGroup.(NioEventLoopGroup.java:63) at io.netty.channel.nio.NioEventLoopGroup.(NioEventLoopGroup.java:54) at org.elasticsearch.transport.netty4.Netty4Transport.createBootstrap(Netty4Transport.java:201) at org.elasticsearch.transport.netty4.Netty4Transport.doStart(Netty4Transport.java:172) at org.elasticsearch.xpack.security.transport.netty4.SecurityNetty4Transport.doStart(SecurityNetty4Transport.java:74) at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:69) at org.elasticsearch.transport.TransportService.doStart(TransportService.java:196) at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:69) at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:208) at org.elasticsearch.client.transport.TransportClient.(TransportClient.java:268) at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:125) at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.(PreBuiltXPackTransportClient.java:55) at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.(PreBuiltXPackTransportClient.java:50) at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.(PreBuiltXPackTransportClient.java:46)


Solution

  • To get around potential conflicts between DataStax java driver's dependency of Netty and other libraries' dependencies on maven, you could use the 'shaded' classifier of the driver jar as described in the driver docs on the 'Using the shaded jar' page:

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>3.2.0</version>
        <classifier>shaded</classifier>
        <!-- Because the shaded JAR uses the original POM, you still need
            to exclude this dependency explicitly: -->
        <exclusions>
            <exclusion>
            <groupId>io.netty</groupId>
            <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    

    Note if you aren't using maven, other build tools like gradle should have a way of specifying the classifier, otherwise you can download the shaded jar directly from maven.