спрей-маршрутизация - акка спроси у Marshaller

Я пытаюсь выполнить службу в spray.io, следуя примерам из оригинальной документации, и я застрял на сообщении об ошибке:

could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller[scala.concurrent.Future[AdImporterServiceActor.StatusOfImport]]


val adServiceRoute: Route = {
    path("service" / "import" / "status") {
      get {
        respondWithMediaType(`text/plain`) {
          complete {
            adImporterService.ask(GetImportStatus)(1 second).mapTo[StatusOfImport]
          }
        }
      }
    }
  }

  implicit val importStatusMarshaller: Marshaller[StatusOfImport] =
    Marshaller.of[StatusOfImport](ContentTypes.`text/plain`) { (value, contentType, ctx) =>
      val string = "Hello marshalled status"
      ctx.marshalTo(HttpEntity(contentType, string))
    }

куда

  case class StatusOfImport(statuses: Map[String, ImportStatus], activeRequests:Set[Import])

  case class ImportStatusUpdate(adId: String, statusUpdate: ImportStatus)

Я не уверен, что мне здесь не хватает. Может кто более опытный подскажет?

Спасибо


person jaksky    schedule 12.03.2015    source источник
comment
Прежде всего, вам нужно предоставить implicit instance из spray.httpx.marshalling.ToResponseMarshaller[ A ], если вы хотите маршалировать некоторый тип A, который сообщает маршаллеру о том, как маршалировать эту вещь. Но здесь... вы пытаетесь marshal Future. Звучит странно, как вы думаете, что бы вы написали, если бы вам пришлось от Stringify до Future[ Int ] ?. Пример - вместо List( 1, 2, 3 ) можно написать что-то вроде [ 1, 2, 3 ].   -  person sarveshseri    schedule 12.03.2015
comment
@SarveshKumarSingh Я следил за примерами из источника Spray github.com/spray/spray/blob/master/examples/spray-routing/ или spray.io/documentation/1.2.2/spray-routing/#longer-example   -  person jaksky    schedule 12.03.2015


Ответы (2)


Я думаю, вам нужен неявный ExecutionContext в области действия, чтобы обеспечить возможность сортировки Future.

person rahilb    schedule 12.03.2015

Измените эту часть, также import scala.concurrent.ExecutionContext.Implicits.global

    respondWithMediaType(MediaTypes.`text/plain`) { ctx=>

    (adImporterService.ask(GetImportStatus)(1 second).mapTo[StatusOfImport]).onComplete {
                case Success(s) => ctx.complete(s)
                case Failure(x)=> ctx.complete(StatusCodes.RequestTimeout)
              }
}
person S.Karthik    schedule 12.03.2015