Comments (1)
Of course I need to deserialize the data the same way it was serialized, so I looked the code for that up in the akka-persistence-dynamodb
library and came up with the solution. It's possible to deserialize Journal events using ByteArrayJournalSerializer
class like this:
sealed trait EventDecodingResult[E]
final case class Successful[E](event: E) extends EventDecodingResult[E]
final case class Failed[E](error: String) extends EventDecodingResult[E]
class EventDecoder[E](val serializer: ByteArrayJournalSerializer, val journalConfig: JournalPluginConfig) {
def decode(recordImage: Map[String, AttributeValue]): EventDecodingResult[E] = {
result(serializer.deserialize(recordImage.toJournalRow(journalConfig)), 1.second) match {
case (representation, _, _) => Successful(representation.payload.asInstanceOf[E])
case _ => Failed("could not decode event")
}
}
}
object EventDecoder {
def apply[E](actorSystem: ActorSystem[AnyRef]): EventDecoder[E] = {
val serialization = SerializationExtension(actorSystem)
val journalConfigPath = "j5ik2o.dynamo-db-journal"
val journalConfig = fromConfig(load.getConfig(journalConfigPath))
val serializer = new ByteArrayJournalSerializer(serialization, journalConfig.tagSeparator, None, None)
new EventDecoder[E](serializer, journalConfig)
}
}
object Implicits {
implicit class AttributeValueMapImplicits(val recordImage: Map[String, AttributeValue]) {
def toJournalRow(journalConfig: JournalPluginConfig): JournalRow = {
val columnsConfig = journalConfig.columnsDefConfig
JournalRow(
persistenceId = PersistenceId(recordImage(columnsConfig.persistenceIdColumnName).getS),
sequenceNumber = SequenceNumber(recordImage(columnsConfig.sequenceNrColumnName).getN.toLong),
deleted = recordImage(columnsConfig.deletedColumnName).getBOOL,
message = recordImage.get(columnsConfig.messageColumnName).map(_.getB.array()).get,
ordering = recordImage(columnsConfig.orderingColumnName).getN.toLong,
tags = recordImage.get(columnsConfig.tagsColumnName).map(_.getS)
)
}
}
}
from akka-persistence-dynamodb.
Related Issues (16)
- Missing akka-persistence-dynamodb-base dependency artifact HOT 2
- configuration question HOT 1
- Dynamo DB table setup
- Suggested DynamoDB setup doesn't work with default configuration HOT 3
- Dependency Dashboard
- "dynamo-db-journal" is confusingly close to "dynamodb-journal" HOT 3
- [NotIssue] Question on Sequence based and PartitionId based key schemes HOT 2
- Documentation in scaladex show incorrect table name HOT 1
- Unable to run with dynamodb-local due to missing region configuration
- MessageDigest exception under high load HOT 1
- sonarqube
- eventsByTag do not produce new events
- Unable to resolve dependency for Scala 2.13 HOT 1
- Query plugin used to read "eventsByTag" from the journal is complaining about Bad Request HOT 4
- Journal entries do not delete with soft-delete=false HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from akka-persistence-dynamodb.