Поддержка на стороне чтения Lagom Jdbc: com.typesafe.config.ConfigException $ Отсутствует: не найден параметр конфигурации для ключа 'slick.profile' - PullRequest
0 голосов
/ 04 мая 2018

Я пытаюсь настроить процессор чтения JDBC в сервисе lagom:

class ProjectEventsProcessor(readSide: JdbcReadSide)(implicit ec: ExecutionContext) extends ReadSideProcessor[ProjectEvent] {

  def buildHandler = {
    readSide.builder[ProjectEvent]("projectEventOffset")
      .setEventHandler[ProjectCreated]((conn: Connection, e: EventStreamElement[ProjectCreated]) => insertProject(e.event))
      .build
  }

  private def insertProject(e: ProjectCreated) = {
    Logger.info(s"Got event $e")
  }

  override def aggregateTags: Set[AggregateEventTag[ProjectEvent]] = ProjectEvent.Tag.allTags
}

Службы подключаются к базе данных в порядке при запуске 15:40:32.575 [info] play.api.db.DefaultDBApi [] - Database [default] connected at jdbc:postgresql://localhost/postgres?user=postgres

Но сразу после этого я получаю исключение.

com.typesafe.config.ConfigException $ Отсутствует: нет настроек конфигурации найдено по ключу 'slick.profile'

Прежде всего, почему слик здесь вообще задействован?

Я использую JdbcReadSide, но не SlickReadSide.

Хорошо, скажем, JdbcReadSide как-то внутренне использует slick.

Я добавил slick.profile в application.config моего сервиса.

db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://localhost/postgres?user=postgres"

// Tried this way
slick.profile="slick.jdbc.PostgresProfile$" 

// Also this fay (copied from play documentation).
slick.dbs.default.profile="slick.jdbc.PostgresProfile$"
slick.dbs.default.db.dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
slick.dbs.default.db.properties.driver = "org.postgresql.Driver"

Но все равно получаю это исключение.

Что происходит? Как решить эту проблему?

1 Ответ

0 голосов
/ 24 июля 2018

Согласно документам , Lagom использует akka-persistence-jdbc, что под капотом:

использует Slick для отображения таблиц и управления асинхронным выполнением вызовов JDBC.

Полная конфигурация, использующая также пул соединений по умолчанию (HikariCP) для установки в файле application.conf, может быть следующей (в основном, скопированной из документации):

# Defaults to use for each Akka persistence plugin
jdbc-defaults.slick {

  # The Slick profile to use
  # set to one of: slick.jdbc.PostgresProfile$, slick.jdbc.MySQLProfile$, slick.jdbc.OracleProfile$ or slick.jdbc.H2Profile$
  profile = "slick.jdbc.PostgresProfile$"

  # The JNDI name for the Slick pre-configured DB
  # By default, this value will be used by all akka-persistence-jdbc plugin components (journal, read-journal and snapshot).
  # you may configure each plugin component to use different DB settings
  jndiDbName=DefaultDB
}


db.default {

  driver = "org.postgresql.Driver"
  url = "jdbc:postgresql://localhost/postgres?user=postgres"

  # The JNDI name for this DataSource
  # Play, and therefore Lagom, will automatically register this DataSource as a JNDI resource using this name.
  # This DataSource will be used to build a pre-configured Slick DB
  jndiName=DefaultDS

  # Lagom will configure a Slick Database, using the async-executor settings below
  # and register it as a JNDI resource using this name.
  # By default, all akka-persistence-jdbc plugin components will use this JDNI name
  # to lookup for this pre-configured Slick DB
  jndiDbName=DefaultDB

  async-executor {
    # number of objects that can be queued by the async executor
    queueSize = 10000

    # 5 * number of cores
    numThreads = 20

    # same as number of threads
    minConnections = 20

    # same as number of threads
    maxConnections = 20

    # if true, a Mbean for AsyncExecutor will be registered
    registerMbeans = false
  }

  # Hikari is the default connection pool and it's fine-tuned to use the same
  # values for minimum and maximum connections as defined for the async-executor above
  hikaricp {
    minimumIdle = ${db.default.async-executor.minConnections}
    maximumPoolSize = ${db.default.async-executor.maxConnections}
  }
}


lagom.persistence.jdbc {

  # Configuration for creating tables
  create-tables {

    # Whether tables should be created automatically as needed
    auto = true

    # How long to wait for tables to be created, before failing
    timeout = 20s

    # The cluster role to create tables from
    run-on-role = ""

    # Exponential backoff for failures configuration for creating tables
    failure-exponential-backoff {

      # minimum (initial) duration until processor is started again
      # after failure
      min = 3s

      # the exponential back-off is capped to this duration
      max = 30s

      # additional random delay is based on this factor
      random-factor = 0.2
    }
  }
}
...