What happened to akka.util.duration?

In a lot of old Akka examples you will see the following statements:

import akka.util.Timeout
import akka.util.duration._
implicit val askTimeout = Timeout(1 second)

This will give error ‘object duration is not a member of package akka.util’. It turns out duration is now included in Scala standard library. To fix the error use the following import statement:

import scala.concurrent.duration._

Check out the migration guide for other pieces of Akka functionality that have moved to Scala.

Advertisements

ClassNotFoundException when adding slf4j to Akka

When adding to a Akka project I got the following error java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLogger. I double checked my configuration and the Akka documentation. The documentation says the following:

Akka provides a logger for SL4FJ. This module is available in the ‘akka-slf4j.jar’. It has one single dependency; the slf4j-api jar. In runtime you also need a SLF4J backend, we recommend Logback.

No success. Continue reading

“value ? is not a member of akka.actor.ActorRef”

I was trying to use a Future in Akka today and got the following error message:

value ? is not a member of akka.actor.ActorRef

It turns out you have to import the akka.pattern.ask to use ‘?’. There is a implicit conversion from ActorRef to AskableActorRef.

So add the following import and you should be set to go (take note that ask does not start with a capital:

import akka.pattern.ask