Coder Social home page Coder Social logo

Comments (6)

satabin avatar satabin commented on July 23, 2024

ConfigFactory.load() resolves the default configuration before it is merged with your overridden one. So all substitution are already replaced. What you want is to resolve the configuration after the merge occurred.

If you want to override the reference.conf by a string in your code, you should merge with the unresolved default configuration. Something like:

private val config = ConfigFactory.parseString(
    """
        akka {
          persistence.journal.plugin = "akka-persistence-redis.journal"
        }
        akka-persistence-redis {
          redis {
            host = redis
          }
        }
        """.stripMargin
  ).withFallback(ConfigFactory.parseResources("reference.conf")).resolve()

However I would recommend to use the standard mechanism described in the documentation

from akka-persistence-redis.

l15k4 avatar l15k4 commented on July 23, 2024

What? I don't thinks so, it is just a fallback for the primary :

  private val config = ConfigFactory.parseString(
    """
        akka {
          persistence.journal.plugin = "akka-persistence-redis.journal"
        }
        akka-persistence-redis {
          redis {
            host = redis
          }
        }
        """.stripMargin
  ).withFallback(ConfigFactory.load())
  println(config.getString("akka-persistence-redis.redis.host"))
  println(config.getString("akka-persistence-redis.redis.mode"))

Prints :

redis
simple

from akka-persistence-redis.

satabin avatar satabin commented on July 23, 2024

Yes, because the merge overrides the specific host key you are querying.

But the journal uses a substitution which default to to akka-persistence-redis.redis which is resolved by the load method before the merge occurs.

Try:

 println(config.getConfig("akka-persistence-redis.journal.redis"))

Please try my solution and you will see the difference. That’s just the way the config library works.

from akka-persistence-redis.

l15k4 avatar l15k4 commented on July 23, 2024

Hmm, I still can't make it work :
redis.conf :

akka {
  extensions = ["com.romix.akka.serialization.kryo.KryoSerializationExtension$"]
  persistence.journal.plugin = "akka-persistence-redis.journal"
}
akka-persistence-redis {
  redis {
    host = redis
  }
}
val system = ActorSystem("example", ConfigFactory.load("redis").withFallback(ConfigFactory.parseResources("reference.conf")).resolve())

Still connecting to localhost :-/

from akka-persistence-redis.

satabin avatar satabin commented on July 23, 2024

Still the same problem. load resolves, but the resolution mechanism does not allow to resolve substitution in reference that are overridden in application (or redis in your case) (see the documentation)

For your example to work, either provide your overloading in a reference.conf file and simply call Configfactory.load or try the solution I gave you, where we only parse (hence without resolving) all the configuration, then merge them, and finally resolve the result. Remember that load method do resolve things.

ConfigFactory.load("redis") parses, merges, and resolve all the reference.conf files in your classpath, then parses redis.conf, merges it with the already merged and resolved references.conf, and resolves the result. What you want is to merge before any resolution is performed and that’s exactly what my first solution does.

Another way to do it is to have a redis.conf file that looks like this:

akka {
  persistence.journal.plugin = "akka-persistence-redis.journal"
}
akka-persistence-redis {
  redis {
    host = redis
  }

 journal.redis = ${akka-persistence-redis.redis}
}

and then just ConfigFactory.load("redis")

from akka-persistence-redis.

l15k4 avatar l15k4 commented on July 23, 2024

I see, 🤦‍♂️ I grasp the problem now, thank you for your help and patience @satabin

from akka-persistence-redis.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.