Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize as Json #13

Closed
stuartsaltzman opened this issue Dec 10, 2015 · 4 comments
Closed

Serialize as Json #13

stuartsaltzman opened this issue Dec 10, 2015 · 4 comments

Comments

@stuartsaltzman
Copy link

Is it possible to serialize the payload as Json using this persistence plugin? I think the plugin would need to honor any configured serialization plugins? Thanks!

@acjay
Copy link

acjay commented Jan 7, 2016

I also would appreciate this ability

@acjay
Copy link

acjay commented Jan 7, 2016

If I'm not mistaken, it seems like this plugin will use whatever the registered serializer is for a given type:

val result = messages.map { write =>
write.payload.foldLeft(Try(Vector.empty[SQLSyntax])) { (acc, x) =>
for {
a <- acc
bytes <- serialization.serialize(x)
} yield a :+ sqls"(${keys(x.persistenceId)}, ${x.sequenceNr}, $bytes)"
}
}

Would this mean that one could register their own JSON serializers for the built-in Akka Persistence data structures in application.conf, as well as JSON serializers for their own event types, and everything would work?

I suppose one would also want to change the message types in the docs from BYTEA to JSON. You could use JSONB, but that seems less appropriate for most use cases. Both give you Postgres sugar for querying, but JSONB adds overhead in encoding, which doesn't carry its weight if planning to do the vast majority of querying via Akka Persistence.

@acjay
Copy link

acjay commented Jan 7, 2016

Okay, I think I'm going to give this a shot, unless someone like @okumin with real knowledge reports back with a reason to think this wouldn't work, or might not be advisable. For my application, I'm expecting throughput to be on the order of an event per second max, so I'm not super concerned about latency at this point. The idea of being able to directly examine the underlying store and also to manage deployment of a familiar DB is really attractive for my purposes. I'll report back!

@okumin
Copy link
Owner

okumin commented Jan 10, 2016

@stuartsaltzman @acjay
Excuse me for my late response.

You can serialize events or states by your custom serializers like the sample.

However, you may not store that as special types, e.g. JSONB.

Table schemas should be defined for each application considering its performance characteristic, so I'm planning to make table schemas customizable.

@okumin okumin closed this as completed Oct 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants