2017-03-28 3 views
2

현재 akka와 akka-http 스택으로 래핑 된 지속성 스택에 대한 실험을하고 있습니다.akka-http 및 JsonEntityStreamingSupport

참고 : 지속성을 위해 Akka FSM을 mongodb에 유지하기 위해 공식 플러그인을 사용하고 있습니다.

하지만 내 문제는 JsonEntityStreamingSupport, recommended by akka to serve Source as json입니다.

내 경우

, 내가 코드

implicit val jsonEntityStreamingSupport: JsonEntityStreamingSupport = EntityStreamingSupport.json() 

val readJournal = PersistenceQuery(system).readJournalFor[ScalaDslMongoReadJournal](MongoReadJournal.Identifier) 

val route = 
    path("workflows") { 
    get { 
     complete(readJournal.currentPersistenceIds()) 
    } 
} 

Http().bindAndHandle(route, "localhost", 8081) 

이 조각을 가지고 있지만 불행하게도,이 오류와 함께 :

$ curl localhost:8081/workflows 
curl: (56) Recv failure: Connection reset by peer 

내가 어떤 오류 또는 정보로 이어질 수 로그를 볼 수 없습니다 서버가 연결을 닫는 이유.

이미 이런 종류의 실험을 수행 한 사람이 있습니까?

내가 akka 2.4.16과 함께 테스트하고 있습니다 akka-HTTP 좋아 10.0.5

답변

2

, 나는 그것을 알아 냈다.

readJournal.currentPersistenceIds()Source[String, NotUsed]입니다. 이 akka-http specs에 지정된대로

그러나,

This is wrong since we try to render JSON, but String is not a valid top level element we need to provide an explicit Marshaller[String, ByteString] if we really want to render a list of strings.

그래서 나는 그것을위한 Marshaller을 제공해야합니다. 예를 들어, 동일한 테스트에서 제공하는 것 :

implicit val stringFormat = Marshaller[String, ByteString] { ec ⇒ s ⇒ 
    Future.successful { 
    List(Marshalling.WithFixedContentType(ContentTypes.`application/json`,() ⇒ 
     ByteString("\"" + s + "\"")) // "raw string" to be rendered as json element in our stream must be enclosed by "" 
    ) 
    } 
}