Sorry, but that’s step into the wrong direction. You should use the `onSuccess` 
or similar directives.
For an example take a look here: 
https://github.com/hseeberger/reactive-flows/blob/master/src/main/scala/de/heikoseeberger/reactiveflows/HttpService.scala#L72
 
<https://github.com/hseeberger/reactive-flows/blob/master/src/main/scala/de/heikoseeberger/reactiveflows/HttpService.scala#L72>

Don’t forget to provide implicit values for Timeout, ExecutionContext and 
Materializer.

Cheers
Heiko

--

Heiko Seeberger
Home: heikoseeberger.de <http://heikoseeberger.de/>
Twitter: @hseeberger <https://twitter.com/hseeberger>
Public key: keybase.io/hseeberger <https://keybase.io/hseeberger>
> On 10 Sep 2015, at 18:00, Matthew Adams <[email protected]> wrote:
> 
> ...and half a baby step further.  I changed onSuccess to match.  Now I think 
> the problem is one of typing:  (bank ? oa) is of type Future[Any], which 
> makes sense because the match clause will return either a Balance or an 
> AccountAlreadyExists type.  Changed route to
> 
>   val route =
> 
>     path("accounts") {
> 
>       post {
> 
>         entity(as[OpenAccount]) { oa =>
> 
>           bank ? oa match {
> 
>             case b: Balance => complete(b)
> 
>             case x: AccountAlreadyExists => complete(x)
> 
>           }
> 
>         } ~
> 
>           entity(as[Transfer]) { t =>
> 
>             bank ? t match {
> 
>               case tr: TransferResult => complete(tr)
> 
>               case nsax: NoSuchAccount => complete(nsax)
> 
>               case ifx: InsufficientFunds => complete(ifx)
> 
>             }
> 
>           }
> 
>       } ~
> 
>         get {
> 
>           complete((bank ? GetAccounts()).mapTo[Accounts])
> 
>         }
> 
> 
> but still getting compilation errors
> 
> [error] 
> /Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:50:
>  type mismatch;
> [error]  found   : scala.concurrent.Future[Any] with 
> com.demo.akka.http.BankResults.Balance
> [error]  required: akka.http.scaladsl.marshalling.ToResponseMarshallable
> [error]             case b: Balance => complete(b)
> [error]                                         ^
> [error] 
> /Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:51:
>  type mismatch;
> [error]  found   : scala.concurrent.Future[Any] with 
> com.demo.akka.http.BankResults.AccountAlreadyExists
> [error]  required: akka.http.scaladsl.marshalling.ToResponseMarshallable
> [error]             case x: AccountAlreadyExists => complete(x)
> [error]                                                      ^
> [error] 
> /Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:56:
>  type mismatch;
> [error]  found   : scala.concurrent.Future[Any] with 
> com.demo.akka.http.BankResults.TransferResult
> [error]  required: akka.http.scaladsl.marshalling.ToResponseMarshallable
> [error]               case tr: TransferResult => complete(tr)
> [error]                                                   ^
> [error] 
> /Users/matthew/Documents/github/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:57:
>  type mismatch;
> [error]  found   : scala.concurrent.Future[Any] with 
> com.demo.akka.http.BankResults.NoSuchAccount
> [error]  required: akka.http.scaladsl.marshalling.ToResponseMarshallable
> [error]               case nsax: NoSuchAccount => complete(nsax)
> [error]                                                    ^
> [error] 
> /Users/matthew/Documents/github/SciSpike/Scala-2-Course-PP/lesson-360-exercises/payment-flow/solution/src/main/scala/com/demo/akka/http/Rest.scala:58:
>  type mismatch;
> [error]  found   : scala.concurrent.Future[Any] with 
> com.demo.akka.http.BankResults.InsufficientFunds
> [error]  required: akka.http.scaladsl.marshalling.ToResponseMarshallable
> [error]               case ifx: InsufficientFunds => complete(ifx)
> [error]                                                       ^
> [error] 5 errors found
> [error] (compile:compile) Compilation failed
> [error] Total time: 1 s, completed Sep 10, 2015 10:57:35 AM
> 
> Still poking away...
> 
> On Thursday, September 10, 2015 at 10:44:02 AM UTC-5, Matthew Adams wrote:
> 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 
> <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/ <http://akka.io/docs/>
> >>>>>>>>>> Check the FAQ: 
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html 
> >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html>
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user 
> >>>>>>>>>> <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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/akka-user 
> <http://groups.google.com/group/akka-user>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
>>>>>>>>>>      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.

Reply via email to