Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions runtime/src/main/scala/akka/grpc/GrpcClientSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,22 @@ object GrpcClientSettings {
* @param clientName of the client configuration to lookup config from the ActorSystem's config
*/
def fromConfig(clientName: String)(implicit actorSystem: ClassicActorSystemProvider): GrpcClientSettings = {
val system = actorSystem.classicSystem
val akkaGrpcClientConfig = system.settings.config.getConfig("akka.grpc.client")
val clientConfig = {
// Use config named "*" by default
val defaultServiceConfig = akkaGrpcClientConfig.getConfig("\"*\"")
require(
akkaGrpcClientConfig.hasPath(s""""$clientName""""),
s"Config path `akka.grpc.client.$clientName` does not exist")
akkaGrpcClientConfig.getConfig(s""""$clientName"""").withFallback(defaultServiceConfig)
}
val akkaGrpcClientConfig = actorSystem.classicSystem.settings.config.getConfig("akka.grpc.client")
fromConfig(clientName, akkaGrpcClientConfig)
}

/**
* Look up client settings from the given configuration. Will look for an entry with the given name client name
* directly in the config block. Each client configuration falls back to the defaults defined in reference.conf
*
* @param clientName of the client configuration to lookup config from the ActorSystem's config
Comment thread
johanandren marked this conversation as resolved.
Outdated
*/
def fromConfig(clientName: String, config: Config)(
implicit actorSystem: ClassicActorSystemProvider): GrpcClientSettings = {
// Use config named "*" by default
val defaultServiceConfig = actorSystem.classicSystem.settings.config.getConfig("akka.grpc.client.\"*\"")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering if this should be config.withFallback(actorSystem.classicSystem.settings.config) in case the given config also overrides default config, but fine to not support that kind of override.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah, maybe not a bad idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave that and revisit in case we figure out that it is very useful.

require(config.hasPath(s""""$clientName""""), s"Config path `akka.grpc.client.$clientName` does not exist")
val clientConfig = config.getConfig(s""""$clientName"""").withFallback(defaultServiceConfig)
GrpcClientSettings.fromConfig(clientConfig)
}

Expand Down
16 changes: 16 additions & 0 deletions runtime/src/test/scala/akka/grpc/GrpcClientSettingsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ class GrpcClientSettingsSpec extends AnyWordSpec with Matchers with ScalaFutures
settings.serviceDiscovery should not be null
} finally actorSystem.terminate()
}

"allow a user provided config object" in {
val config = ConfigFactory.parseString("""
"service-with-user-config" {
host = "my-host"
port = 43
service-discovery {
mechanism = "static"
}
}
""")
val settings = GrpcClientSettings.fromConfig("service-with-user-config", config)
settings.defaultPort should ===(43)
settings.useTls should ===(true) // from system default config

}
}

override def afterAll(): Unit = {
Expand Down