All Projects → akkadotnet → Akka.Persistence.MongoDB

akkadotnet / Akka.Persistence.MongoDB

Licence: Apache-2.0 license
MongoDB support for Akka.Persistence

Programming Languages

C#
18002 projects
F#
602 projects
powershell
5483 projects
shell
77523 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to Akka.Persistence.MongoDB

akka-cqrs-activator
Issue tracker PoC application written in Scala (Akka) and JavaScript (React) that demonstrates event sourcing and CQRS
Stars: ✭ 33 (+10%)
Mutual labels:  actors, akka
Akka Essentials
Java/Scala Examples from the book - Akka Essentials
Stars: ✭ 700 (+2233.33%)
Mutual labels:  actors, akka
Protoactor Go
Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
Stars: ✭ 3,934 (+13013.33%)
Mutual labels:  actors, akka
nact
nact ⇒ node.js + actors ⇒ your services have never been so µ
Stars: ✭ 1,003 (+3243.33%)
Mutual labels:  actors, akka
Actors
Evaluation of API and performance of different actor libraries
Stars: ✭ 125 (+316.67%)
Mutual labels:  actors, akka
protoactor-go
Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
Stars: ✭ 4,138 (+13693.33%)
Mutual labels:  actors, akka
Akkadotnet Code Samples
Akka.NET professional reference code samples
Stars: ✭ 451 (+1403.33%)
Mutual labels:  actors, akka
Akkatecture
a cqrs and event sourcing framework for dotnet core using akka.net
Stars: ✭ 414 (+1280%)
Mutual labels:  actors, akka
Akka Monitoring
Monitoring system instrumentation for Akka.NET actor systems
Stars: ✭ 105 (+250%)
Mutual labels:  actors, akka
Protoactor Dotnet
Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
Stars: ✭ 1,070 (+3466.67%)
Mutual labels:  actors, akka
MuezzinAPI
A web server application for Islamic prayer times
Stars: ✭ 33 (+10%)
Mutual labels:  actors, akka
Akka Guide
🌴 A chinese guide of Akka, based on Java.
Stars: ✭ 217 (+623.33%)
Mutual labels:  actors, akka
akka-contextual-actor
A really small library (just a few classes) which lets you trace your actors messages transparently propagating a common context together with your messages and adding the specified values to the MDC of the underlying logging framework.
Stars: ✭ 17 (-43.33%)
Mutual labels:  actors, akka
Robots
Actor system for Rust
Stars: ✭ 294 (+880%)
Mutual labels:  actors, akka
protoactor-python
Proto Actor - Ultra fast distributed actors
Stars: ✭ 78 (+160%)
Mutual labels:  actors, akka
Nact
nact ⇒ node.js + actors ⇒ your services have never been so µ
Stars: ✭ 848 (+2726.67%)
Mutual labels:  actors, akka
Tacks
Real-time multiplayer sailing game, in your browser
Stars: ✭ 134 (+346.67%)
Mutual labels:  actors, akka
endless
Scala library to describe sharded and event sourced entities using tagless-final algebras
Stars: ✭ 70 (+133.33%)
Mutual labels:  actors, akka
young-crawler
scala结合actor编写的分布式网络爬虫
Stars: ✭ 15 (-50%)
Mutual labels:  akka
Actors.jl
Concurrent computing in Julia based on the Actor Model
Stars: ✭ 95 (+216.67%)
Mutual labels:  actors

Akka.Persistence.MongoDB

Akka Persistence journal and snapshot store backed by MongoDB database.

Setup

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

akka.persistence.journal.plugin = "akka.persistence.journal.mongodb"
akka.persistence.journal.mongodb.connection-string = "<database connection string>"
akka.persistence.journal.mongodb.collection = "<journal collection>"

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

akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.mongodb"
akka.persistence.snapshot-store.mongodb.connection-string = "<database connection string>"
akka.persistence.snapshot-store.mongodb.collection = "<snapshot-store collection>"

Remember that connection string must be provided separately to Journal and Snapshot Store. To finish setup simply initialize plugin using: MongoDbPersistence.Get(actorSystem);

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):

akka.persistence {
	journal {
	plugin = "akka.persistence.journal.mongodb"
		mongodb {
			# qualified type name of the MongoDb persistence journal actor
			class = "Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb"

			# connection string used for database access
			connection-string = ""

			# should corresponding journal table's indexes be initialized automatically
			auto-initialize = off

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

			# MongoDb collection corresponding with persistent journal
			collection = "EventJournal"

			# metadata collection
			metadata-collection = "Metadata"

			# For users with legacy data, who want to keep writing data to MongoDb using the original BSON format
			# and not the standard binary format introduced in v1.4.0 (see https://github.com/akkadotnet/Akka.Persistence.MongoDB/issues/72)
			# enable this setting via `legacy-serialization = on`.
			#
			# NOTE: this will likely break features such as Akka.Cluster.Sharding, IActorRef serialization, AtLeastOnceDelivery, and more.
			legacy-serialization = off
		}
	}

	snapshot-store {
	plugin = "akka.persistence.snapshot-store.mongodb"
		mongodb {
			# qualified type name of the MongoDB persistence snapshot actor
			class = "Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb"

			# connection string used for database access
			connection-string = ""

			# should corresponding snapshot's indexes be initialized automatically
			auto-initialize = off

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

			# MongoDb collection corresponding with persistent snapshot store
			collection = "SnapshotStore"

			# For users with legacy data, who want to keep writing data to MongoDb using the original BSON format
			# and not the standard binary format introduced in v1.4.0 (see https://github.com/akkadotnet/Akka.Persistence.MongoDB/issues/72)
			# enable this setting via `legacy-serialization = on`.
			#
			# NOTE: this will likely break features such as Akka.Cluster.Sharding, IActorRef serialization, AtLeastOnceDelivery, and more.
			legacy-serialization = off
		}
	}
}

Programmatic configuration

You can programmatically overrides the connection string setting in the HOCON configuration by adding a MongoDbPersistenceSetup to the ActorSystemSetup during ActorSystem creation. The MongoDbPersistenceSetup takes MongoClientSettings instances to be used to configure MongoDB client connection to the server. The connection-string settings in the HOCON configuration will be ignored if any of these MongoClientSettings exists inside the Setup object.

[!NOTE] The HOCON configuration is still needed for this to work, only the connection-string setting in the configuration will be overriden.

Setting connection override for both snapshot store and journal:

// Set snapshotClientSettings or journalClientSettings to null if you do not use them.
var snapshotClientSettings = new MongoClientSettings();
var journalClientSettings = new MongoClientSettings();

// database names are not needed when its client setting is set to null
var snapshotDatabaseName = "theSnapshotDatabase"
var journalDatabaseName = "theJournalDatabase"

var setup = BootstrapSetup.Create()
  .WithConfig(myHoconConfig)
  .And(new MongoDbPersistenceSetup(snapshotDatabaseName, snapshotClientSettings, journalDatabaseName, journalClientSettings));

var actorSystem = ActorSystem.Create("actorSystem", setup);

Setting connection override only for snapshot store:

var snapshotClientSettings = new MongoClientSettings();
var snapshotDatabaseName = "theSnapshotDatabase"

var setup = BootstrapSetup.Create()
  .WithConfig(myHoconConfig)
  .And(new MongoDbPersistenceSetup(snapshotDatabaseName, snapshotClientSettings, null, null));

var actorSystem = ActorSystem.Create("actorSystem", setup);

Setting connection override only for journal:

var journalClientSettings = new MongoClientSettings();
var journalDatabaseName = "theJournalDatabase"

var setup = BootstrapSetup.Create()
  .WithConfig(myHoconConfig)
  .And(new MongoDbPersistenceSetup(null, null, journalDatabaseName, journalClientSettings));

var actorSystem = ActorSystem.Create("actorSystem", setup);

Serialization

Going from v1.4.0 onwards, all events and snapshots are saved as byte arrays using the standard Akka.Persistence format.

However, in the event that you have one of the following use cases:

  1. Legacy data all stored in the original BSON / "object" format;
  2. A use case where BSON is preferable, i.e. so it can be queried directly via MongoDb queries rather than Akka.Persistence.Query; or
  3. A requirement to keep all data in human-readable form.

Then you can disable binary serialization (enabled by default) via the following HOCON:

akka.persistence.mongodb{
   journal{
    legacy-serialization = off
  }

  snapshot-store{
   legacy-serialization = off
 }
}

Setting legacy-serialization = on will allow you to save objects in a BSON format.

WARNING: However, legacy-serialization = on will break Akka.NET serialization. IActorRefs, Akka.Cluster.Sharding, AtLeastOnceDelivery actors, and other built-in Akka.NET use cases can't be properly supported using this format. Use it at your own risk.

Notice

  • The MongoDB operator to limit the number of documents in a query only accepts an integer while akka provides a long as maximum for the loading of events during the replay. Internally the long value is cast to an integer and if the value is higher then Int32.MaxValue, Int32.MaxValue is used. So if you have stored more then 2,147,483,647 events for a single PersistenceId, you may have a problem 😉
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].