Giter Site home page Giter Site logo

lulzzz / hn-akka-persistence-bigtable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hafslundnett/hn-akka-persistence-bigtable

0.0 2.0 0.0 104 KB

Akka Persistence journal and snapshot store backed by Google Bigtable.

License: MIT License

C# 99.28% Dockerfile 0.72%

hn-akka-persistence-bigtable's Introduction

Hafslund.Akka.Persistence.Bigtable

Installation

This plugin is released publicly to nuget.org, and the latest released version can be installed by:

dotnet add package Hafslund.Akka.Persistence.Bigtable

To use the plugin as an extension, add the following line of code to the Akka system initialization:

BigtablePersistence.Get(actorSystem);

(Note that this is similar to how the Cluster extension is set up, e.g. Cluster.Get(actorSystem)).

If it is preferred to load the extension from config instead of through code, specify the FQCNs for the Journal and Snasphot store classes in HOCON:

akka.persistence.journal.bigtable.class = "Hafslund.Akka.Persistence.Bigtable.Snapshot.BigtableJournal, Hafslund.Akka.Persistence.Bigtable"
akka.persistence.snapshot-store.bigtable.class = "Hafslund.Akka.Persistence.Bigtable.Snapshot.BigtableSnapshotStore, Hafslund.Akka.Persistence.Bigtable"

Setup

The extension will load default configuration (see reference.conf from plugin source code), but as a minimum, the tablename has to be specified. There is no option to feed in a connection string for the table, as this is not how the Google Cloud SDK is set up to authenticate, see https://cloud.google.com/bigtable/docs/reference/libraries.

To activate the journal plugin, add the following lines to your actor system configuration file:

akka.persistence.journal.plugin = "akka.persistence.journal.bigtable"
akka.persistence.journal.bigtable.table-name = "your/bigtable/table/reference"

Similar configuration may be used to setup a Bigtable snapshot store:

akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot.bigtable"
akka.persistence.snapshot-store.bigtable.table-name = "your/bigtable/table/reference"

Note that the tables with column family must be created before running this plugin, as there is no auto-initialize configuration setting provided (this option would require a different authorization level with create access to Bigtable, than what it is recommended that the akka system should run under). For a brief introduction on how to create tables and column families, see https://cloud.google.com/bigtable/docs/quickstart-cbt.

For a working CBT installation setup with a ~/.cbtrc file pointing to the right project and instance, the following set of commands gives an example:

cbt createtable MyJournalEvents
cbt createfamily MyJournalEvents f
cbt createtable MySnapshotStore
cbt createfamily MySnapshotStore f

Note that the family name f is the default configuration in the plugin if not otherwise specified. If the table is not created with a column family matching the configuration, nothing will be persisted. To override the default column family name in config, set the following HOCON config property:

akka.persistence.journal.bigtable.family-name = otherfamily
akka.persistence.snapshot-store.bigtable.family-name = otherfamily

Sharding setup

If you would like to store sharding events and snapshots in separate tables, add the following line in code:

ShardingBigtablePersistence.Get(actorSystem);

or if it is preferred to load the extension from config instead of through code, specify the FQCNs for the Journal and Snapshot steore classes specific for sharding in HOCON:

akka.persistence.journal.bigtable.class = "Hafslund.Akka.Persistence.Bigtable.Journal.ShardingBigtableJournal, Hafslund.Akka.Persistence.Bigtable"
akka.persistence.snapshot-store.bigtable.class = "Hafslund.Akka.Persistence.Bigtable.Snapshot.ShardingBigtableSnapshotStore, Hafslund.Akka.Persistence.Bigtable"

Then make the following changes to your HOCON:

akka.cluster.sharding {
	journal-plugin-id = "akka.persistence.journal.bigtable-sharding"
	snapshot-plugin-id = "akka.persistence.snapshot-store.bigtable-sharding"
	state-store-mode = persistence
}

akka.persistence.journal.bigtable-sharding.table-name = "your/bigtable-sharding/table/reference/"
akka.persistence.snapshot-store.bigtable-sharding.table-name = "your/bigtable-sharding/table/reference"

If you are using a column family name other than the default f, remember to also set the following:

akka.persistence.journal.bigtable-sharding.family-name = otherfamily
akka.persistence.snapshot-store.bigtable-sharding.family-name = otherfamily

Configuration

Both journal and snapshot store share the same configuration keys (however they resides in separate scopes, so they are definied distinctly for either journal or snapshot store). Full configuration is given below (but note that minimal configuration is described above, and is mainly the table name).

akka.persistence {
  plugin = "akka.persistence.journal.bigtable"

  journal {
    bigtable {
	    # qualified type name of the Google Bigtable persistence journal actor
	    class = "Hafslund.Akka.Persistence.Bigtable.Journal.BigtableJournal, Hafslund.Akka.Persistence.Bigtable"

	    # the name of the Google Bigtable used to persist journal events
	    # (full name, i.e. 'projects/<project-id>/instances/<instance-id>/tables/<table-name> )
	    table-name = ""

	    # Column family name:
	    family-name = "f"

	    # dispatcher used to drive journal actor
	    plugin-dispatcher = "akka.actor.default-dispatcher"
    }

	# Only required if you want to store sharding events to separate table:
	bigtable-sharding {
	    # qualified type name of the Google Bigtable persistence journal actor
	    class = "Hafslund.Akka.Persistence.Bigtable.Journal.ShardingBigtableJournal, Hafslund.Akka.Persistence.Bigtable"

	    # the name of the Google Bigtable used to persist journal events
	    # (full name, i.e. 'projects/<project-id>/instances/<instance-id>/tables/<table-name> )
	    table-name = ""

	    # Column family name:
	    family-name = "f"
	    
	    # dispatcher used to drive journal actor
	    plugin-dispatcher = "akka.actor.default-dispatcher"
    }
  }  

  snapshot-store {
	plugin = "akka.persistence.snapshot-store.bigtable"
    
	bigtable {
	    # qualified type name of the Google Bigtable persistence snapshot storage actor
	    class = "Hafslund.Akka.Persistence.Bigtable.Snapshot.BigtableSnapshotStore, Hafslund.Akka.Persistence.Bigtable"

	    # the name of the Google Bigtable used to persist snapshots
	    # (full name, i.e. 'projects/<project-id>/instances/<instance-id>/tables/<table-name> )
	    table-name = ""
	    
	    # Column family name:
	    family-name = "f"

	    # dispatcher used to drive snapshot storage actor
	    plugin-dispatcher = "akka.actor.default-dispatcher"
    }

	# Only required if you want to store harding snapshots to a separate table:
	bigtable-sharding {
	    # qualified type name of the Google Bigtable persistence snapshot storage actor
	    class = "Hafslund.Akka.Persistence.Bigtable.Snapshot.ShardingBigtableSnapshotStore, Hafslund.Akka.Persistence.Bigtable"

	    # the name of the Google Bigtable used to persist snapshots
	    # (full name, i.e. 'projects/<project-id>/instances/<instance-id>/tables/<table-name> )
	    table-name = ""

	    # Column family name:
	    family-name = "f"

	    # dispatcher used to drive snapshot storage actor
	    plugin-dispatcher = "akka.actor.default-dispatcher"
    }
  }

hn-akka-persistence-bigtable's People

Contributors

erifol avatar ausol avatar danielab avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.