Akka projections on events that are not tagged


I want to start using akka projection in my project. I am using akka cluster and I’d like to use the ShardedDaemonProcess to distribute the load. Currently I have a database with ~million events that have not been tagged and as I understand it I need to tag my events in order to use the library.

Is there any way to process events that have not been tagged?

I would add the tags directly in the database table. Which journal plugin do you use?

I’m using akka-persistence-jdbc

Then it should only be a a matter of adding the tag to the tags column in the journal table.

When using ShardedDaemonProcess you will use several tags to distribute the projection instances. It’s important that you use the same hashing mechanism in the db migration job as will later be used by your application.

The recommendation in the documentation is to use

math.abs(entityContext.entityId.hashCode % tags.size)

Instead of the entityId you could use the persistenceId if you find that easier. You have the persistence_id in the table. Then you must also use the persistenceId in the EventSourcedBehavior tagging.

Thanks so much!

I assume I have to write the DB migration in scala instead of raw SQL since I have to calculate the java hash code?

Yeah, that’s probably beyond what you can do with SQL. Alternatively you have some other hashing algorithm that you can do with SQL and then replicate that to Scala in the EventSourcedBehavior tagging.

Anyway, a few million rows shouldn’t be a problem to iterate from a Scala program.