Skip to content

Commit 67f8a7b

Browse files
committed
update jdbc schema provider to handle event processor offsets so as to use its own pool of database connections
1 parent 733c289 commit 67f8a7b

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ThisBuild / organization := "app.softnetwork"
3030

3131
name := "generic-persistence-api"
3232

33-
ThisBuild / version := "0.2.6"
33+
ThisBuild / version := "0.2.6.1"
3434

3535
ThisBuild / scalaVersion := "2.12.11"
3636

jdbc/build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import app.softnetwork.sbt.build.Versions
2+
app.softnetwork.sbt.build.Publication.settings
23

34
Test / parallelExecution := false
45

jdbc/src/main/resources/softnetwork-jdbc-persistence.conf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ jdbc-durable-state-store {
5353
}
5454

5555
jdbc-event-processor-offsets {
56+
db {
57+
url = "jdbc:postgresql://"${db.ip}":"${db.port}"/"${db.name}"?reWriteBatchedInserts=true"
58+
user = ${credentials.db.username}
59+
password = ${credentials.db.password}
60+
driver = "org.postgresql.Driver"
61+
numThreads = ${db.max-connections}
62+
minConnections = 10
63+
maxConnections = 50
64+
idleTimeout = 10000 //10 seconds
65+
}
5666
schema = ${credentials.db.username}
5767
table = "event_processor_offsets"
5868
}
@@ -65,8 +75,8 @@ slick {
6575
password = ${credentials.db.password}
6676
driver = "org.postgresql.Driver"
6777
numThreads = ${db.max-connections}
68-
maxConnections = ${db.max-connections}
6978
minConnections = ${db.min-connections}
79+
maxConnections = ${db.max-connections}
7080
idleTimeout = 10000 //10 seconds
7181
}
7282
}
@@ -78,10 +88,10 @@ db {
7888
port = ${?DB_PORT}
7989
name = "softnetwork"
8090
name = ${?DB_NAME}
81-
max-connections = 100
82-
max-connections = ${?DB_MAX_CONNECTIONS}
8391
min-connections = 10
8492
min-connections = ${?DB_MIN_CONNECTIONS}
93+
max-connections = 100
94+
max-connections = ${?DB_MAX_CONNECTIONS}
8595
}
8696

8797
credentials{

jdbc/src/main/scala/app/softnetwork/persistence/jdbc/config/Settings.scala renamed to jdbc/src/main/scala/app/softnetwork/persistence/jdbc/config/JdbcSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import configs.Configs
66

77
/** Created by smanciot on 15/09/2020.
88
*/
9-
object Settings extends StrictLogging {
9+
object JdbcSettings extends StrictLogging {
1010

1111
case class JdbcEventProcessorOffsets(schema: String, table: String)
1212

jdbc/src/main/scala/app/softnetwork/persistence/jdbc/query/JdbcJournalProvider.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import akka.persistence.jdbc.query.scaladsl.JdbcReadJournal
66
import akka.persistence.query.{EventEnvelope, Offset, PersistenceQuery, Sequence}
77

88
import akka.stream.scaladsl.Source
9-
import app.softnetwork.persistence.jdbc.config.Settings
109

1110
import slick.jdbc.JdbcBackend.Session
1211

1312
import scala.concurrent.Future
1413

14+
import app.softnetwork.persistence.jdbc.config.JdbcSettings._
1515
import app.softnetwork.persistence.query.JournalProvider
1616

1717
import scala.util.{Failure, Success, Try}
@@ -20,8 +20,6 @@ import scala.util.{Failure, Success, Try}
2020
*/
2121
trait JdbcJournalProvider extends JournalProvider { _: JdbcSchemaProvider =>
2222

23-
import Settings._
24-
2523
lazy val offsetSchema: String = jdbcEventProcessorOffsets.schema
2624

2725
lazy val offsetTable: String = jdbcEventProcessorOffsets.table

jdbc/src/main/scala/app/softnetwork/persistence/jdbc/query/JdbcSchemaProvider.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ trait JdbcSchemaProvider extends SchemaProvider with ClasspathResources with Str
3232

3333
def cfg: Config = ConfigFactory.load()
3434

35-
def db: Database = JdbcBackend.createDatabase(cfg, "slick.db")
35+
lazy val db: Database = JdbcBackend.createDatabase(cfg, "jdbc-event-processor-offsets.db")
3636

3737
def initSchema(): Unit = {
3838
create(schemaType.schema)

0 commit comments

Comments
 (0)