Quick Start

In order to learn about sec in the following sections you will need a basic setup. Below are instructions to get you up and running.

EventStoreDB Setup#

First we need to get an EventStoreDB node loaded up. One easy way to do this is to use docker and start up a single node in in-secure mode as follows:

docker run -it --rm --name es-node \
-p 2113:2113 \
-e EVENTSTORE_MEM_DB=True \
-e EVENTSTORE_INSECURE=True \
-e EVENTSTORE_GOSSIP_ON_SINGLE_NODE=True \
-e EVENTSTORE_DISCOVER_VIA_DNS=False \
-e EVENTSTORE_START_STANDARD_PROJECTIONS=True \
eventstore/eventstore:21.10.2-bionic

The above is enough to get something up and running for the purpose of exploration and learning. Consult the EventStoreDB docs for more details on configuration for production setup.

Scala Setup#

Create a new project with sec as dependency:

libraryDependencies += "io.github.ahjohannessen" %% "sec-fs2" % "0.20.7"

Verify Your Setup#

In order to verify that you can reach the database try out the following IOApp:

import cats.effect._
import sec.api._
object HelloWorld extends IOApp {
def run(args: List[String]): IO[ExitCode] = EsClient
.singleNode[IO](Endpoint("127.0.0.1", 2113))
.resource.use(client =>
client.gossip.read.map(_.render).flatMap(str => IO(println(str)))
)
.as(ExitCode.Success)
}

The methods used on EsClient are explained in the subsequent sections.