Getting Started

Dependencies

Maven
<properties>
  <scala.binary.version>2.12</scala.binary.version>
</properties>
<dependency>
  <groupId>com.lightbend.akka</groupId>
  <artifactId>akka-persistence-spanner_${scala.binary.version}</artifactId>
  <version>1.0.0-RC5</version>
</dependency>
sbt
libraryDependencies += "com.lightbend.akka" %% "akka-persistence-spanner" % "1.0.0-RC5"
Gradle
versions += [
  ScalaBinary: "2.12"
]
dependencies {
  compile group: 'com.lightbend.akka', name: "akka-persistence-spanner_${versions.ScalaBinary}", version: '1.0.0-RC5'
}

This plugin depends on Akka 2.6.x and note that it is important that all akka-* dependencies are in the same version, so it is recommended to depend on them explicitly to avoid problems with transient dependencies causing an unlucky mix of versions.

The plugin is published for Scala 2.13 and 2.12.

Enabling

See configuring as a journal, snapshot store or how to use the query plugin

Local testing

The Spanner emulator can be used to test without requiring connection to Spanner.

The emulator can be setup using the instructions in the Google documentation, using gcloud, or via Docker. Here’s a sample docker compose file that will start the emulator and forward the HTTP and gRPC ports of the emulator. This plugin only relies on gRPC.

version: '2'
services:
  spanner:
    image: gcr.io/cloud-spanner-emulator/emulator
    ports:
      - "9010:9010"
      - "9020:9020"

The emulator only supports one concurrent transaction. This can be a major limitation for realistic testing. The emulator is best used for basic verification and then realistic testing done with spanner.

To run tests with the emulator you need the following configuration:

akka.persistence.journal.plugin = "akka.persistence.spanner.journal"
akka.persistence.spanner {
  session-pool {
    max-size = 1
  }
  use-auth = false
}
akka.grpc.client.spanner-client {
  host = localhost
  port = 9010
  use-tls = false
}

Creating the schema

You can use the testkit to create and drop the database. Add test testkit dependency:

Maven
<properties>
  <scala.binary.version>2.12</scala.binary.version>
</properties>
<dependency>
  <groupId>com.lightbend.akka</groupId>
  <artifactId>akka-persistence-spanner-testkit_${scala.binary.version}</artifactId>
  <version>1.0.0-RC5</version>
</dependency>
sbt
libraryDependencies += "com.lightbend.akka" %% "akka-persistence-spanner-testkit" % "1.0.0-RC5"
Gradle
versions += [
  ScalaBinary: "2.12"
]
dependencies {
  compile group: 'com.lightbend.akka', name: "akka-persistence-spanner-testkit_${versions.ScalaBinary}", version: '1.0.0-RC5'
}

To create and drop the database:

Java
public static final SpannerTestkit spannerTestkit = new SpannerTestkit(testKit.system());

@BeforeClass
public static void createDatabase() {
  spannerTestkit.createDatabaseAndSchema();
}

@AfterClass
public static void dropDatabase() {
  spannerTestkit.dropDatabase();
}
Scala
val spannerTestkit = new SpannerTestkit(system)

override protected def beforeAll(): Unit = {
  super.beforeAll()
  spannerTestkit.createDatabaseAndSchema()
}

protected override def afterAll(): Unit = {
  spannerTestkit.dropDatabase()
  super.afterAll()
}
Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.