All Projects → akkadotnet → Akka.Persistence.PostgreSql

akkadotnet / Akka.Persistence.PostgreSql

Licence: Apache-2.0 license
Akka.Persistence.PostgreSql provider

Programming Languages

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

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

Akka.Logger.Serilog
Akka.NET logging integration for Serilog library
Stars: ✭ 22 (-31.25%)
Mutual labels:  akka, akkadotnet
nact
nact ⇒ node.js + actors ⇒ your services have never been so µ
Stars: ✭ 1,003 (+3034.38%)
Mutual labels:  akka
mmqtt
An Open-Source, Distributed MQTT Broker for IoT.
Stars: ✭ 58 (+81.25%)
Mutual labels:  akka
akka-microservice
Example of a microservice with Scala, Akka, Spray and Camel/ActiveMQ
Stars: ✭ 45 (+40.63%)
Mutual labels:  akka
kotlin-akka
Akka-Kotlin sample, and support library.
Stars: ✭ 25 (-21.87%)
Mutual labels:  akka
cassandra.realtime
Different ways to process data into Cassandra in realtime with technologies such as Kafka, Spark, Akka, Flink
Stars: ✭ 25 (-21.87%)
Mutual labels:  akka
chordial
A simple Scala implementation of Chord, a distributed lookup protocol
Stars: ✭ 24 (-25%)
Mutual labels:  akka
akka-mock-scheduler
A mock Akka scheduler to simplify testing scheduler-dependent code
Stars: ✭ 86 (+168.75%)
Mutual labels:  akka
jwt-akka-http
An example how to implement a very simple authentication and authorization with Akka HTTP. Related to https://blog.codecentric.de/en/2017/09/jwt-authentication-akka-http
Stars: ✭ 23 (-28.12%)
Mutual labels:  akka
akka-http-circe-json-template
Akka HTTP REST API Project Template using Akka HTTP 10.0.4 with Circe 0.7.0 targeting Scala 2.12.x
Stars: ✭ 21 (-34.37%)
Mutual labels:  akka
akkadotnet-bootstrap
Akka.Remote and Akka.Cluster Bootstrapping Tools for Akka.NET
Stars: ✭ 29 (-9.37%)
Mutual labels:  akkadotnet
play-grpc
Play + Akka gRPC
Stars: ✭ 31 (-3.12%)
Mutual labels:  akka
generator-jvm
Generate JVM (java, kotlin, scala) project with gradle / maven / sbt build systems and docker / docker-compose for rapid development
Stars: ✭ 40 (+25%)
Mutual labels:  akka
MuezzinAPI
A web server application for Islamic prayer times
Stars: ✭ 33 (+3.13%)
Mutual labels:  akka
ecommerce
A project for exploring Akka with Scala
Stars: ✭ 24 (-25%)
Mutual labels:  akka
stem
Event sourcing framework based on ZIO and pluggable runtime (currently working with Akka cluster)
Stars: ✭ 22 (-31.25%)
Mutual labels:  akka
akka-cluster-minimal
Akka Cluster - absolute minimal
Stars: ✭ 16 (-50%)
Mutual labels:  akka
akka-http-actor-per-request
Example akka application that uses the actor per request model
Stars: ✭ 16 (-50%)
Mutual labels:  akka
Akka.Persistence.SqlServer
Akka.Persistence.SqlServer provider
Stars: ✭ 53 (+65.63%)
Mutual labels:  akkadotnet
protoactor-go
Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
Stars: ✭ 4,138 (+12831.25%)
Mutual labels:  akka

Akka.Persistence.PostgreSql

Akka Persistence journal and snapshot store backed by PostgreSql database.

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

Remember that connection string must be provided separately to Journal and Snapshot Store.

akka.persistence{
	journal {
		plugin = "akka.persistence.journal.postgresql"
		postgresql {
			# qualified type name of the PostgreSql persistence journal actor
			class = "Akka.Persistence.PostgreSql.Journal.PostgreSqlJournal, Akka.Persistence.PostgreSql"

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

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

			# default SQL commands timeout
			connection-timeout = 30s

			# PostgreSql schema name to table corresponding with persistent journal
			schema-name = public

			# PostgreSql table corresponding with persistent journal
			table-name = event_journal

			# should corresponding journal table be initialized automatically
			auto-initialize = off
			
			# timestamp provider used for generation of journal entries timestamps
			timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
		
			# metadata table
			metadata-table-name = metadata

			# defines column db type used to store payload. Available option: BYTEA (default), JSON, JSONB
			stored-as = BYTEA

			# Setting used to toggle sequential read access when loading large objects
			# from journals and snapshot stores.
			sequential-access = off

			# When turned on, persistence will use `BIGINT` and `GENERATED ALWAYS AS IDENTITY`
			# for journal table schema creation.
			# NOTE: This only affects newly created tables, as such, it should not affect any
			#       existing database.
			#
			# !!!!! WARNING !!!!!
			# To use this feature, you have to have PorsgreSql version 10 or above
			use-bigint-identity-for-ordering-column = off
		}
	}

	snapshot-store {
		plugin = "akka.persistence.snapshot-store.postgresql"
		postgresql {
			# qualified type name of the PostgreSql persistence journal actor
			class = "Akka.Persistence.PostgreSql.Snapshot.PostgreSqlSnapshotStore, Akka.Persistence.PostgreSql"

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

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

			# default SQL commands timeout
			connection-timeout = 30s

			# PostgreSql schema name to table corresponding with persistent journal
			schema-name = public

			# PostgreSql table corresponding with persistent journal
			table-name = snapshot_store

			# should corresponding journal table be initialized automatically
			auto-initialize = off
			
			# defines column db type used to store payload. Available option: BYTEA (default), JSON, JSONB
			stored-as = BYTEA

			# Setting used to toggle sequential read access when loading large objects
			# from journals and snapshot stores.
			sequential-access = off
		}
	}
}

Table Schema

PostgreSql persistence plugin defines a default table schema used for journal, snapshot store and metadate table.

CREATE TABLE {your_journal_table_name} (
	ordering BIGSERIAL NOT NULL PRIMARY KEY,
    persistence_id VARCHAR(255) NOT NULL,
    sequence_nr BIGINT NOT NULL,
    is_deleted BOOLEAN NOT NULL,
    created_at BIGINT NOT NULL,
    manifest VARCHAR(500) NOT NULL,
    payload BYTEA NOT NULL,
    tags VARCHAR(100) NULL,
    serializer_id INTEGER NULL,
    CONSTRAINT {your_journal_table_name}_uq UNIQUE (persistence_id, sequence_nr)
);

CREATE TABLE {your_snapshot_table_name} (
    persistence_id VARCHAR(255) NOT NULL,
    sequence_nr BIGINT NOT NULL,
    created_at BIGINT NOT NULL,
    manifest VARCHAR(500) NOT NULL,
    payload BYTEA NOT NULL,
    serializer_id INTEGER NULL,
    CONSTRAINT {your_snapshot_table_name}_pk PRIMARY KEY (persistence_id, sequence_nr)
);

CREATE TABLE {your_metadata_table_name} (
    persistence_id VARCHAR(255) NOT NULL,
    sequence_nr BIGINT NOT NULL,
    CONSTRAINT {your_metadata_table_name}_pk PRIMARY KEY (persistence_id, sequence_nr)
);

Note that if you turn on the akka.persistence.journal.postgresql.use-bigint-identity-for-ordering-column flag, the journal table schema will be altered to the latest recommended primary key setting.

CREATE TABLE {your_journal_table_name} (
	ordering BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    persistence_id VARCHAR(255) NOT NULL,
    sequence_nr BIGINT NOT NULL,
    is_deleted BOOLEAN NOT NULL,
    created_at BIGINT NOT NULL,
    manifest VARCHAR(500) NOT NULL,
    payload BYTEA NOT NULL,
    tags VARCHAR(100) NULL,
    serializer_id INTEGER NULL,
    CONSTRAINT {your_journal_table_name}_uq UNIQUE (persistence_id, sequence_nr)
);

Since this script is only run once during table generation, we will not provide any migration path for this change, any migration is left as an exercise for the user.

Migration

From 1.1.0 to 1.3.1

ALTER TABLE {your_journal_table_name} ADD COLUMN serializer_id INTEGER NULL;
ALTER TABLE {your_snapshot_table_name} ADD COLUMN serializer_id INTEGER NULL;

From 1.0.6 to 1.1.0

CREATE TABLE {your_metadata_table_name} (
    persistence_id VARCHAR(255) NOT NULL,
    sequence_nr BIGINT NOT NULL,
    CONSTRAINT {your_metadata_table_name}_pk PRIMARY KEY (persistence_id, sequence_nr)
);

ALTER TABLE {your_journal_table_name} DROP CONSTRAINT {your_journal_table_name}_pk;
ALTER TABLE {your_journal_table_name} ADD COLUMN ordering BIGSERIAL NOT NULL PRIMARY KEY;
ALTER TABLE {your_journal_table_name} ADD COLUMN tags VARCHAR(100) NULL;
ALTER TABLE {your_journal_table_name} ADD CONSTRAINT {your_journal_table_name}_uq UNIQUE (persistence_id, sequence_nr);
ALTER TABLE {your_journal_table_name} ADD COLUMN created_at_temp BIGINT NOT NULL;

UPDATE {your_journal_table_name} SET created_at_temp=extract(epoch from create_at);

ALTER TABLE {your_journal_table_name} DROP COLUMN create_at;
ALTER TABLE {your_journal_table_name} DROP COLUMN created_at_ticks;
ALTER TABLE {your_journal_table_name} RENAME COLUMN created_at_temp TO create_at;

Tests

The PostgreSql tests are packaged and run as part of the default "All" build task.

In order to run the tests, you must do the following things:

  1. Download and install PostgreSql from: http://www.postgresql.org/download/
  2. Install PostgreSql with the default settings. The default connection string uses the following credentials:
  3. Username: postgres
  4. Password: postgres
  5. A custom app.config file can be used and needs to be placed in the same folder as the dll

or run postgres in docker

docker run -d --rm --name=akka-postgres-db -p 5432:5432 -l deployer=akkadotnet -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres postgres:9.6
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].