0

I'm trying to integrate the Alpakka Mongo Connector into an application that heavily relies on the Akka libraries for stream processing. The application utilizes Akka HTTP as well.
I am encountering a dependency issue at run-time. In particular, I'm getting a NoClassDefFoundError for some kind of Success/Failure wrappers when I try to use the MongoSink.insertOne method provided by the Mongo connector. A full stack-trace:

java.lang.NoClassDefFoundError: com/mongodb/reactivestreams/client/Success
    at akka.stream.alpakka.mongodb.scaladsl.MongoFlow$.$anonfun$insertOne$1(MongoFlow.scala:44)
    at akka.stream.impl.fusing.Map$$anon$1.onPush(Ops.scala:53)
    at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:541)
    at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:423)
    at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:625)
    at akka.stream.impl.fusing.ActorGraphInterpreter$SimpleBoundaryEvent.execute(ActorGraphInterpreter.scala:56)
    at akka.stream.impl.fusing.ActorGraphInterpreter$SimpleBoundaryEvent.execute$(ActorGraphInterpreter.scala:52)
    at akka.stream.impl.fusing.ActorGraphInterpreter$BatchingActorInputBoundary$OnNext.execute(ActorGraphInterpreter.scala:95)
    at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:600)
    at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:769)
    at akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:784)
    at akka.actor.Actor.aroundReceive(Actor.scala:537)
    at akka.actor.Actor.aroundReceive$(Actor.scala:535)
    at akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:691)
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:577)
    at akka.actor.ActorCell.invoke(ActorCell.scala:547)
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:270)
    at akka.dispatch.Mailbox.run(Mailbox.scala:231)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:243)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.lang.ClassNotFoundException: com.mongodb.reactivestreams.client.Success
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 24 more

Dependencies:

val akkaHttpVersion = "10.2.1"
val akkaVersion = "2.6.10"
val scalaTestVersion = "3.2.0"
val scalaHtmlScraperVersion = "2.2.0"
val loggerVersion = "1.2.3"
val alpakkaMongoVersion = "2.0.2"

libraryDependencies ++= Seq(
  "org.mongodb.scala" %% "mongo-scala-driver" % "4.1.1",
  "com.typesafe.akka" %% "akka-stream-typed" % akkaVersion,    
  "com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
  "com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
  "com.lightbend.akka" %% "akka-stream-alpakka-mongodb" % "2.0.2",
  "ch.qos.logback" % "logback-classic" % loggerVersion,
  "org.scalactic" %% "scalactic" % scalaTestVersion,
  "org.scalatest" %% "scalatest" % scalaTestVersion,
 )

I also tried adding the org.mongodb:mongodb-driver-reactivestreams:4.1.1 dependency, but for some reason com.mongodb.reactivestreams.client.Success isn't part of the binary. I also tried different versions. Some help would definitely be appreciated. I'm using Scala 2.13.3

Levi Ramsey
  • 18,884
  • 1
  • 16
  • 30

1 Answers1

1

Your problem is related to the Mongo Reactive Streams Driver. The version that Alpakka uses is a little bit old (Aug 13, 2019). See in the Alpakka doc in the "direct dependencies" section:

org.mongodb mongodb-driver-reactivestreams 1.12.0

In that jar you can find the Success class:

enter image description here

Emiliano Martinez
  • 4,073
  • 2
  • 9
  • 19
  • 1
    I actually saw that and added the exact dependency that you just specified. After doing some digging however, I found out that having org.mongodb.scala: mongo-scala-driver 4.1.1 overwrote the reactive streams version from 1.12.0 to 4.1.1. After downgrading my scala driver to version 2.7.0 and adding the dependency you mentioned, my issue was resolved. Thank you for your time. Conclusion: Alpakka should update their connectors. – ubiquitousbyte Dec 30 '20 at 22:23