Overriding multiple config values in Typesafe config when using an uberjar to deploy

前端 未结 3 893
广开言路
广开言路 2020-12-14 03:32

I\'ve an Akka application which uses multiple configuration values (IP address, port numbers) defined in resource/application.conf. I\'m using the sbt-ass

相关标签:
3条回答
  • 2020-12-14 04:05

    We do it in prod like so:

    #deploy_prod.conf
    include "application"
    
    akka.remote.hostname = "prod.blah.com"    
    
    # Example of passing in S3 keys
    s3.awsAccessKeyId="YOUR_KEY"
    s3.awsSecretAccessKey="YOUR_SECRET_KEY"
    

    The above file must end in .conf. It has all the production environment specific configs, and lives outside the jar, so you deploy an identical Akka artifact to all servers. It will override anything in application.conf.

    Then in the startup script:

    java -Dconfig.file=/full/path/deploy_prod.conf -jar your.jar com.your.Main
    
    0 讨论(0)
  • 2020-12-14 04:14

    I was able to programmatically override default akka config with:

    val customConf =
          ConfigFactory.parseString(s"""
                akka {
                  persistence.snapshot-store.local{
                    dir = target/snapshot
                  }
                  persistence.journal.leveldb.dir = target/journal
                }
            """)
    val config = customConf.withFallback(original).resolve()    
    logger.info(config.root().render())
    val system = ActorSystem("iSystem", config)
    
    0 讨论(0)
  • 2020-12-14 04:27

    There are various ways to achieve that:

    1. You either set a classpath to include application.conf from external directory and appear on the classpath before other classpath entries like your jar. To do that you can use regular java -classpath myconfdir:theapp.jar and specify main class explicitly.

    2. You can alternatively include another conf file into your file with include "application" directive in your conf file.

    3. You can set environment variable in application.conf that will point to a file to include. You set env in shell afterwards.

    4. You can override values programmatically: config.withValue("hostname", ConfigValueFactory.fromAnyRef("localhost"). ActorSystem takes a Conf object or loads from default conf if not provided.

    5. The easiest by far is to just pick another file with -Dconfig.resource=/dev.conf java command line argument.

    For more details refer to official docs here.

    0 讨论(0)
提交回复
热议问题