I am trying to get list of persistent events and send it as response(Action.async
). But I am not able to convert PersistenceQuery
results to Future
object. Here is the code
val queries = PersistenceQuery(actorSystem).readJournalFor[CassandraReadJournal](CassandraReadJournal.Identifier)
val source: Source[EventEnvelope, NotUsed] = queries.eventsByPersistenceId("MYID", 0, Long.MaxValue)
val mappedSource: Source[JsValue, NotUsed] = source.mapAsync(1) { e =>
e.event match {
case l: String =>
Future(Json.parse(l))
}
}
val finalResult: Future[List[JsValue]] = mappedSource.take(10).runFold(List[JsValue]())((a, b) => {
println(a)
a :+ b
})
finalResult
I am able to see prints within runFold
, but finalResult
was never returned. I even tried to Await
, even after waiting for minutes, it never returned. This finalResult
shows all the user activity wanted to send it as response as Action.async
. Please let me know what is the way to convert Source
to Future
object
--
>>>>>>>>>> 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 akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
Hmm. You're intentionally not using currentEventsByPersistenceId()? And your println() is showing 10 results?
On Sun, Dec 4, 2016 at 11:23 AM, Srinivas <chu...@gmail.com> wrote:
I am trying to get list of persistent events and send it as response(
Action.async
). But I am not able to convertPersistenceQuery
results toFuture
object. Here is the codeval queries = PersistenceQuery(actorSystem).readJournalFor[CassandraReadJournal](CassandraReadJournal.Identifier) val source: Source[EventEnvelope, NotUsed] = queries.eventsByPersistenceId("MYID", 0, Long.MaxValue) val mappedSource: Source[JsValue, NotUsed] = source.mapAsync(1) { e => e.event match { case l: String => Future(Json.parse(l)) } } val finalResult: Future[List[JsValue]] = mappedSource.take(10).runFold(List[JsValue]())((a, b) => { println(a) a :+ b }) finalResult
I am able to see prints within
runFold
, butfinalResult
was never returned. I even tried toAwait
, even after waiting for minutes, it never returned. ThisfinalResult
shows all the user activity wanted to send it as response asAction.async
. Please let me know what is the way to convertSource
toFuture
object
--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.
class UserController extends Controller {
def getUserActions(userId: String) = AuthenticatedAction.async {
UserService.getUserEvents(userId) map (Ok)
}
}
Object UserService {
def getUserEvents(userId: String): Future[List[JsValue]] = {
val queries = PersistenceQuery(actorSystem).readJournalFor[CassandraReadJournal](CassandraReadJournal.Identifier)
val source: Source[EventEnvelope, NotUsed] = queries.currentEventsByPersistenceId(leadId, 0, Long.MaxValue)
val mappedSource: Source[JsValue, NotUsed] = source.mapAsync(1) { e =>
e.event match { case l: String =>
Future(Json.parse(l))
} }
val finalResult: Future[List[JsValue]] = mappedSource.take(10).runFold(List[JsValue]())((a, b) => {
println(a)
a :+ b
})
finalResult
}
}
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit 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 akka-user+...@googlegroups.com.
In my case there were less than 10 events
--
>>>>>>>>>> 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 akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.