Getting Started Akka Persistence Projections

Team,

I am working on app built on event sourcing/cqrs/ddd approach. For querying/searching/reporting, found out Projections are the right fit.

I searched from any examples over github. Did not find any.

It would be very helpful. Let me know from where to start.

Any links and suggestions are welcome.

-Prakhyat M M

Hi,

This depends on exactly what you mean by “projection” - do you mean the generic term (e.g. to service queries such as “customers whose first name begins with “R”) or specifically projections within the Event Store which are most suited for temporal correlation
querying, indexing etc?

James

Hi James,

I meant service queries such as “customers whose first name begins with “R” but using eventstore.

If you don’t mind can you let me know What do you mean by temporal correlation querying?

-prakhyat m m

So there is in the client a CatchUpSubscription this basically allows you to use your event store as a queue (including for all messages hitting it). This will forward all the events to a handler of your choice. You would then in that handler update a database etc of your choosing. eg when you receive “OrderPlaced” you would insert into table … You can then query that persistent store directly

Cheers,

Greg

See here btw: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB0QtwIwAA&url=http%3A%2F%2Fwww.ustream.tv%2Frecorded%2F46673907&ei=Q3nzU9e9K4_yoASG24DYCw&usg=AFQjCNE6dfNvCAeJSqoopMqYr40qAZZkog&sig2=Pes2aWzGahj74xSZ2R3kpw&bvm=bv.73373277,d.cGU

Hi Greg,

Thanks again.

Can you help me with code sample in GitHub or net. I will go through the code in detail. Below text gave me a hint on projection ,To be frank Below is very short note I want to understand projections in detail.

There are no examples available in this regard. I want to use projections for business related querying/reporting.

-prakhyat m m

See CountAllEvents https://github.com/EventStore/EventStore.JVM more in the repo. You would just be inserting/updating your store of choice instead of counting in a variable

Cheers,

Greg

Greg,

Thanks I will look into code.

I was following your comments from post “improving performance of akka persistence”. In this post also you mentioned about eventstore.jvm. Did not feel that is write post to ask below question.

What is eventstore.jvm?what is the purpose of this project?

-prakhyat m n

It is the officially supported event store jvm client (it talks over the protobuf over tcp protocol). It is currently written in scala/akka and has java wrappers for java developers.

Cheers,

Greg

Also the akka.persistence adapter uses the client to talk to the event store.

Greg,

Thanks again.

Does this project have any example showing querying with complex joins?

What you would do is setup a subscription just like in the example, in that actor/java code you would then write into whatever model you wanted (say sql or hadoop or a graphdb) then you would query whatever data storage you put it into. Obviously we don’t include how to query with joins in SQL as it has nothing to do with us and there is plenty of documentation for whichever database you happen to choose to use for such querying.

Hi Greg,

I looked at https://github.com/EventStore/EventStore.JVM. I was not able to figure out How to use it to integrate with akka persistence event store.

Let me give you some clarity on what I want to achieve.

My app is based upon approach event sourced/cqrs/DDD.

My app uses Akka Persistence with cassandra event store.

Consider I have domain model’s,

Bank
Customer

Account

Bank object will have many customers.

Every customer will have multiple accounts.

Consider for sake of discussion I have made each Domain object as Aggregate Root using API PesistentActor. Each AR is a single writer.

Consider app is designed to receive below events,

  1. createBank

  2. addCustomer

  3. createAccount

  4. creditAccount

  5. debitAccount

Consider system receives events,

  1. createBank —> to create “BankAkka”. Bank AR will receive this event.

  2. addCustomer --> to include customer “Meee”. Customer AR will receive this event.

  3. createAccount -->create savings account. Account AR will receive this event.

  4. creditAccount–>200$. Account AR will receive this event.

  5. debitAccount -->150$. Account AR will receive this event.

Each AR after receiving event will save event to event store and later handled by handler.

I want to implement a query : Give all customers in system whose balance is less then 100$.

How to integrate EventStore.JVM with event store of akka persistence. In my event store is cassandra.

-Prakhyat M M

There is a separate project to use event store with Akka.peristence on that github account the jvm project is the client. That said using event store with Akka.persistence is an either or decision with Cassandra

Greg,

There is a separate project to use event store with Akka.peristence on that github account the jvm project is the client.

[Prakhyat] can you share the project. Also will it have example for using projection?

That said using event store with Akka.persistence is an either or decision with Cassandra.

[Prakhyat] I did not understand what you meant.

https://github.com/EventStore/EventStore.Akka.Persistence

You mention you use Cassandra as your Akka.persistence store. Event store is it’s own db and that is the driver for Akka.persistence with it (depends on eventstore.jvm which is the client)