All Projects → innFactory → akka-persistence-gcp-datastore

innFactory / akka-persistence-gcp-datastore

Licence: Apache-2.0 license
akka-persistence-gcp-datastore is a journal and snapshot store plugin for akka-persistence using google cloud firestore in datastore mode.

Programming Languages

scala
5932 projects
shell
77523 projects

Projects that are alternatives of or similar to akka-persistence-gcp-datastore

akka-persistence-foundationdb
A replicated Akka Persistence journal backed by FoundationDB
Stars: ✭ 43 (+138.89%)
Mutual labels:  akka, cqrs, akka-persistence, event-sourcing
firebase-event-sourcing
Event Sourcing + CQRS + DDD for Firebase
Stars: ✭ 14 (-22.22%)
Mutual labels:  cqrs, event-sourcing, firestore
atomic-store
Atomic event store for Scala/Akka
Stars: ✭ 17 (-5.56%)
Mutual labels:  akka, akka-persistence, event-sourcing
stem
Event sourcing framework based on ZIO and pluggable runtime (currently working with Akka cluster)
Stars: ✭ 22 (+22.22%)
Mutual labels:  akka, cqrs, event-sourcing
akka-persistence-spanner
Spanner plugin for Akka Persistence
Stars: ✭ 12 (-33.33%)
Mutual labels:  akka, akka-persistence, event-sourcing
Akka Ddd
Akka CQRS/ES framework
Stars: ✭ 330 (+1733.33%)
Mutual labels:  akka, cqrs, event-sourcing
Ddd Leaven Akka V2
Sample e-commerce system #Microservices #Akka #Reactive-DDD #CQRS
Stars: ✭ 362 (+1911.11%)
Mutual labels:  akka, cqrs, event-sourcing
Akkatecture
a cqrs and event sourcing framework for dotnet core using akka.net
Stars: ✭ 414 (+2200%)
Mutual labels:  akka, cqrs, event-sourcing
endless
Scala library to describe sharded and event sourced entities using tagless-final algebras
Stars: ✭ 70 (+288.89%)
Mutual labels:  akka, cqrs, event-sourcing
slack-community
Docs related to DDD-CQRS-ES Discord Community
Stars: ✭ 58 (+222.22%)
Mutual labels:  cqrs, event-sourcing
wolkenkit-todomvc
wolkenkit-todomvc is a todo application.
Stars: ✭ 15 (-16.67%)
Mutual labels:  cqrs, event-sourcing
go-eventually
Idiomatic Event Sourcing in Go
Stars: ✭ 76 (+322.22%)
Mutual labels:  cqrs, event-sourcing
microservice-template
📖 Nest.js based microservice repository template
Stars: ✭ 131 (+627.78%)
Mutual labels:  cqrs, event-sourcing
EcommerceDDD
Experimental full-stack application using Domain-Driven Design, CQRS, and Event Sourcing.
Stars: ✭ 178 (+888.89%)
Mutual labels:  cqrs, event-sourcing
e-shop
Sample Spring Cloud microservices e-shop.
Stars: ✭ 48 (+166.67%)
Mutual labels:  cqrs, event-sourcing
backend
Ergonode backend repository
Stars: ✭ 100 (+455.56%)
Mutual labels:  cqrs, event-sourcing
chronicle
An event sourced CQRS framework for Rust
Stars: ✭ 36 (+100%)
Mutual labels:  cqrs, event-sourcing
Learning.EventStore
A framework for CQRS, Eventsourcing, and messaging that uses Redis pub/sub for messaging and offers event persistence in Redis, SQL Server, or PostgreSQL.
Stars: ✭ 58 (+222.22%)
Mutual labels:  cqrs, event-sourcing
serverless-cqrs
CQRS example using AWS Lambda
Stars: ✭ 17 (-5.56%)
Mutual labels:  cqrs, event-sourcing
cqrs
A lightweight, opinionated CQRS and event sourcing framework targeting serverless architectures.
Stars: ✭ 155 (+761.11%)
Mutual labels:  cqrs, event-sourcing

GCP Datastore Akka Persistence Plugin

Test Download shields.io Codacy Badge Scala Steward badge

akka-persistence-gcp-datastore is a journal and snapshot store plugin for akka-persistence using Google Cloud Datastore. It uses the official Google Java Dependency to talk with the datastore.

Scala 2.12 & 2.13, Java 8 & Java 11, akka 2.6.X are supported.

The plugin supports the following functionality:

  • serialization of events and snapshots with play-json
  • peristence-query api
  • custom serialization

Related Blogposts

Usage & Setup

Versions: The table below lists the versions and their main dependencies

Version to use Scala 2.12 Scala 2.13 Scala 3 / Dotty Akka play-json google-cloud-datastore
1.0.2 ? 2.6.x 2.8.x 1.102.x

Dependency

You just need to add the following dependency to you sbt dependencies

libraryDependencies += "de.innfactory" %% "akka-persistence-gcp-datastore" % "X.Y.Z"

Configuration

Take a look at reference.conf under src/main/resources We forked the cqrs cassandra lightbend example with necessary changes for gcp-datastore (@ Demo Test Project available based on the CQRS Example from Lightbend https://github.com/innFactory/akka-persistence-gcp-datastore-example)

Add the following to your application.conf for a basic configuration:

akka {
  # use google cloud datastore as journal and snapshot store
  persistence {

    journal {
      plugin = "gcp-datastore-journal"
      auto-start-journals = ["gcp-datastore-journal"]
    }

    snapshot-store {
      plugin = "gcp-datastore-snapshot"
      auto-start-snapshot-stores = ["gcp-datastore-snapshot"]
    }
  }
}

Datastore Configuration

  1. Google Cloud Project with Datastore or FireStore in Datastore mode enabled

  2. Create a index.yml file with content bolow in the project that will use this plugin:

    indexes:
      - kind: journal
        properties:
          - name: persistenceId
          - name: sequenceNr
            direction: desc
    
      - kind: snapshot
        properties:
          - name: persistenceId
          - name: timestamp
            direction: desc
    
      - kind: snapshot
        properties:
          - name: persistenceId
          - name: timestamp
    
      - kind: journal
        properties:
        - name: tagsKey
        - name: timestamp
    
      - kind: journal
        properties:
        - name: persistenceId
        - name: sequenceNr
    

    index.yml

  3. Open terminal and execute

    gcloud app deploy index.yaml
    

    This is telling the GCP Datastore to build indexes for the plugin based on the yaml file

  4. Create a service account for read and write to datastore. Download the json and add it to the project

    src/main/resources/datastore.json
    

Persistence query API

The plugin supports the Persistence query APi, mostly used in CQRS applications to transform/migrate the events from the write side to the read side.

The ReadJournal is retrieved via the akka.persistence.datastore.journal.read.DatastoreScaladslReadJournal and akka.persistence.datastore.journal.read.DatastoreJavadslReadJournal. There is also a DatastoreReadJournalProvider.

import akka.persistence.datastore.journal.read.DatastoreScaladslReadJournal
import akka.persistence.query.{ EventEnvelope, PersistenceQuery }

val system = ??? //ActorSystem akka-classic or akka-typed then system.toClassic is needed. see the example.
val readJournal =
    PersistenceQuery(system).readJournalFor[DatastoreScaladslReadJournal]("gcp-datastore-query")

Supported Queries

All queries are live streams and they are not completed when they reaches the end of the currently stored events, but continue to push new events when new events are persisted.

eventsByTag

eventsByTags is used for retrieving events that were marked with a given tag.

eventsByPersistenceId

eventsByPersistenceId is used for retrieving events for a specific PersistentActor identified by its persistenceId

Testing

To test this plugin

(Source: https://cloud.google.com/datastore/docs/tools/datastore-emulator)

  1. gcloud components install cloud-datastore-emulator

  2. gcloud beta emulators datastore start --no-store-on-disk --consistency=1.0

  3. Set Env Variable DATASTORE_TESTHOST=http://<host>:<port> of datastore emulator

  4. Execute sbt run

  5. Before executing test reset datastore data: curl -X POST http://<host>:<port>/reset

There is a shell script under .circle ci which runs all of these tests. cqrs tests are outsourced in the example project.

Contribution policy

Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.

Credits

innFactory GmbH is a lightbend partner from germany. We are experts for Apps, BigData & Cloud Computing. If you need help with your next project, feel free to ask for our support.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].