Ok, made one baby step. I was missing an implicit ActorMaterializer within
scope. Fixed that. Now, compile errors are:
*[error]
/Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:50:
type mismatch;*
*[error] found : Unit*
*[error] required: akka.http.scaladsl.marshalling.ToResponseMarshallable*
*[error] (bank ? oa) onSuccess {*
*[error] ^*
*[error]
/Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:58:
type mismatch;*
*[error] found : Unit*
*[error] required: akka.http.scaladsl.marshalling.ToResponseMarshallable*
*[error] (bank ? t) onSuccess {*
*[error] ^*
*[error] two errors found*
*[error] (compile:compile) Compilation failed*
*[error] Total time: 1 s, completed Sep 10, 2015 10:27:10 AM*
On Wednesday, September 9, 2015 at 6:41:18 PM UTC-5, Matthew Adams wrote:
>
> Hi all,
>
> I'm trying to understand using actors with the routing DSL. How do I
> complete using the routing DSL given an actor that I'm asking and may
> return different responses? Here's the code:
>
>
> *object RestApiJsonProtocols extends DefaultJsonProtocol with
> SprayJsonSupport {*
>
> * implicit val jfAmount = jsonFormat1(Amount)*
>
>
> * implicit val jfOpenAccount = jsonFormat2(OpenAccount)*
>
> * implicit val jfDeposit = jsonFormat2(Deposit)*
>
> * implicit val jfWithdraw = jsonFormat2(Withdraw)*
>
> * implicit val jfGetBalance = jsonFormat1(GetBalance)*
>
> * implicit val jfTransfer = jsonFormat3(Transfer)*
>
> * implicit val jfGetAccounts = jsonFormat0(GetAccounts)*
>
> * implicit val jfBalance = jsonFormat2(Balance)*
>
> * implicit val jfAccounts = jsonFormat1(Accounts)*
>
> * implicit val jfTransferResult = jsonFormat4(TransferResult)*
>
> * implicit val jfNoSuchAccount = jsonFormat2(NoSuchAccount)*
>
> * implicit val jfAccountAlreadyExists = jsonFormat2(AccountAlreadyExists)*
>
> * implicit val jfInsufficientFunds = jsonFormat3(InsufficientFunds)*
>
> *}*
>
>
> * import RestApiJsonProtocols._*
>
>
> * val myRoute =*
>
> * path("accounts") {*
>
> * post {*
>
> * entity(as[OpenAccount]) { oa =>*
>
> * complete {*
>
> * (bank ? oa) onSuccess { **// "bank" is an Actor*
>
> * case b: Balance => b // WRONG*
>
> * case x: AccountAlreadyExists => x // WRONG*
>
> * }*
>
> * }*
>
> * } ~*
>
> * entity(as[Transfer]) { t =>*
>
> * complete {*
>
> * (bank ? t) onSuccess { **// "bank" is an Actor*
>
> * case tr: TransferResult => tr // WRONG*
>
> * case nsax: NoSuchAccount => nsax** // WRONG*
>
> * case ifx: InsufficientFunds => ifx** // WRONG*
>
> * }*
>
> * }*
>
> * }*
>
> * } ~*
>
> * get {*
>
> * complete((bank ? GetAccounts()).mapTo[Accounts]) // RIGHT!*
>
> * }*
>
> * }*
>
>
> I don't know what the right magical incantation is but here are my current
> compilation errors.
>
>
> *> compile*
>
> *[info] Compiling 3 Scala sources to
> /Users/matthew/Documents/github/payment-flow/solution/target/scala-2.11/classes...*
>
> *[error]
> /Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:53:
>
> could not find implicit value for parameter um:
> akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[com.demo.akka.http.BankCommands.OpenAccount]*
>
> *[error] entity(as[OpenAccount]) { oa =>*
>
> *[error] ^*
>
> *[error]
> /Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:55:
>
> type mismatch;*
>
> *[error] found : Unit*
>
> *[error] required: akka.http.scaladsl.marshalling.ToResponseMarshallable*
>
> *[error] (bank ? oa) onSuccess {*
>
> *[error] ^*
>
> *[error]
> /Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:61:
>
> could not find implicit value for parameter um:
> akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[com.demo.akka.http.BankCommands.Transfer]*
>
> *[error] entity(as[Transfer]) { t =>*
>
> *[error] ^*
>
> *[error]
> /Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:63:
>
> type mismatch;*
>
> *[error] found : Unit*
>
> *[error] required: akka.http.scaladsl.marshalling.ToResponseMarshallable*
>
> *[error] (bank ? t) onSuccess {*
>
> *[error] ^*
>
> *[error] four errors found*
>
> *[error] (compile:compile) Compilation failed*
>
> *[error] Total time: 1 s, completed Sep 9, 2015 6:30:19 PM*
>
> As you can see from the route, if an OpenAccount message is POSTed to
> /accounts I use ask to send the actor (bank) the OpenAccount message. It
> responds with either a Balance or AccountAlreadyExists message. If a
> Transfer message is POSTed to /accounts, I use ask to send the actor the
> Transfer message, which responds with either TransferResult, NoSuchAccount,
> or InsufficientFunds message. In either case, I want to send the message
> that the actor responds with back to the client as JSON.
>
> The GET directive's content shows no errors (in Scala IDE or IntelliJ) and
> is inspired by
> https://groups.google.com/forum/#!topic/akka-dev/ei-0OzzgKd0 which I felt
> lucky to find.
>
> I'm kind of on the clock on this one and could use some help.
>
> Thanks,
> Matthew
>
>
>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.