Configuration

The plugin relies on @extrefSlick to do create the SQL dialect for the database in use, therefore the following must be configured in application.conf

Configure pekko-persistence:

  • instruct Apache Pekko persistence to use the jdbc-journal plugin,
  • instruct Apache Pekko persistence to use the jdbc-snapshot-store plugin,
  • instruct Apache Pekko persistence to use the jdbc-durable-state-store plugin (Postgres and H2 only)

Configure slick:

  • The following slick profiles are supported:
    • slick.jdbc.PostgresProfile$
    • slick.jdbc.MySQLProfile$
    • slick.jdbc.H2Profile$
    • slick.jdbc.OracleProfile$
    • slick.jdbc.SQLServerProfile$

Database Schema

@@@ note

Please note that the H2 database is not recommended to be used as a production database, and support for H2 is primarily for testing purposes.

@@@

For testing purposes the journal and snapshot tables can be created programmatically using the provided SchemaUtils.

Scala : @@snipsnip { #create }

Java : @@snipsnip { #create }

A dropIfExists variant is also available.

Note: SchemaUtils was introduced in version 5.0.0.

Reference Configuration

pekko-persistence-jdbc provides the defaults as part of the @extref:reference.conf. This file documents all the values which can be configured.

There are several possible ways to configure loading your database connections. Options will be explained below.

One database connection pool per journal type

There is the possibility to create a separate database connection pool per journal-type (one pool for the write-journal, one pool for the snapshot-journal, and one pool for the read-journal). This is the default and the following example configuration shows how this is configured:

Postgres : @@snipPostgres

MySQL : @@snipMySQL

H2 : @@snipH2

Oracle : @@snipOracle

SQL Server : @@snipSQL Server

Sharing the database connection pool between the journals

In order to create only one connection pool which is shared between all journals the following configuration can be used:

Postgres : @@snipPostgres

MySQL : @@snipMySQL

H2 : @@snipH2

Oracle : @@snipOracle

SQL Server : @@snipSQL Server

Customized loading of the db connection

It is also possible to load a custom database connection. In order to do so a custom implementation of @extref:SlickDatabaseProvider needs to be created. The methods that need to be implemented supply the Slick Database and Profile to the journals.

To enable your custom SlickDatabaseProvider, the fully qualified class name of the SlickDatabaseProvider needs to be configured in the application.conf. In addition, you might want to consider whether you want the database to be closed automatically:

pekko-persistence-jdbc {
  database-provider-fqcn = "com.mypackage.CustomSlickDatabaseProvider"
}
jdbc-journal {
  use-shared-db = "enabled" // setting this to any non-empty string prevents the journal from closing the database on shutdown
}
jdbc-snapshot-store {
  use-shared-db = "enabled" // setting this to any non-empty string prevents the snapshot-journal from closing the database on shutdown
}

DataSource lookup by JNDI name

The plugin uses Slick as the database access library. Slick @extrefsupports jndi for looking up @javadocDataSources.

To enable the JNDI lookup, you must add the following to your application.conf:

jdbc-journal {
  slick {
    profile = "slick.jdbc.PostgresProfile$"
    jndiName = "java:jboss/datasources/PostgresDS"
  }
}

When using the use-shared-db = slick setting, the follow configuration can serve as an example:

pekko-persistence-jdbc {
  shared-databases {
    slick {
      profile = "slick.jdbc.PostgresProfile$"
      jndiName = "java:/jboss/datasources/bla"
    }
  }
}

Explicitly shutting down the database connections

The plugin automatically shuts down the HikariCP connection pool when the ActorSystem is terminated. This is done using @apidocActorSystem.registerOnTermination.