2016-08-05 7 views
1

Ich versuche, einen einfachen Http-Client mit Akka Http Client API zu schreiben. Auf dem Weg zu diesem Ich habe den folgenden Code geschriebenKonnte nicht auf den Typ Unmarshaller im Wert akka.http.javadsl.unmarshalling zugreifen

import akka.actor.ActorSystem 
import akka.http.scaladsl.Http 
import akka.http.scaladsl.model._ 
import akka.http.scaladsl.unmarshalling._ 
import akka.stream.ActorMaterializer 
import akka.stream.scaladsl.{Sink, Source} 
import scala.concurrent.duration._ 
import scala.concurrent.{Await} 
import akka.http.scaladsl.server.Directives 
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport 
import spray.json._ 

final case class Post(postId: Int, id: Int, name: String, email: String, body: String) 

trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol { 
    implicit val postFormat = jsonFormat5(Post.apply) 
} 

class AkkaHttpClient extends App with Directives with JsonSupport { 
    implicit val system = ActorSystem("my-Actor") 
    implicit val actorMaterializer = ActorMaterializer() 
    implicit val executionContext = system.dispatcher 
    val httpClient = Http().outgoingConnection(host="http://jsonplaceholder.typicode.com/") 
    val flow = Source.single(HttpRequest(uri = Uri("/comments/1"))) 
     .via(httpClient) 
     .mapAsync(1)(r => Unmarshal(r.entity).to[Post]) 
     .runWith(Sink.head) 

    val results = Await.result(flow, 15 seconds) 
    println(results) 
} 

Meine build.sbt Datei

name := "Akka-Http-Client" 
version := "1.0" 
scalaVersion := "2.11.8" 
libraryDependencies ++= Seq(
    "com.typesafe.akka" %% "akka-http-experimental" % "2.4.9-RC1", 
    "com.typesafe.akka" %% "akka-http-spray-json-experimental" % "2.4.9-RC1" 
) 

wie

sieht Wenn ich versuche, meinen Code ich diese Fehler

Error:scalac: missing or invalid dependency detected while loading class file 'Unmarshaller.class'. 
Could not access type Unmarshaller in value akka.http.javadsl.unmarshalling, 
because it (or its dependencies) are missing. Check your build definition for 
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) 
A full rebuild may help if 'Unmarshaller.class' was compiled against an incompatible version of akka.http.javadsl.unmarshalling. 

Antwort

2

Ich habe zu kompilieren Das gleiche Problem bei 2.4.9-RC1, das auf 2.4.8 zurückfällt, löst das Problem.

ODER Sie könnten diese Problemumgehung verwenden, die hier beschrieben wird: https://github.com/akka/akka/issues/21105

+0

danke. Das hat den Trick für mich gemacht. –

Verwandte Themen