外部化配置Akka [英] Externalize configuration Akka

查看:79
本文介绍了外部化配置Akka的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Akka的新手,我遇到了以下问题。

I am new in Akka and I faced the problem below.

我想外部化我的应用程序中的配置。更具体地说,我有一些随每个环境而不同的变量。因此,我认为我可以为每个环境设置特定的环境变量(秘密等)。
但是我可以对每个环境使用不同的一些变量(非秘密)怎么办?

I want to externalize the configuration in my App. More specifically, I have some variables that are different per each environment. So I think that I can have specific environment variables (secrets, etc) for each environment. But what I can do with some variables (non-secrets) which are different per each environment?

dev.properties , application.conf deploy.json 文件?
从这些文件中加载变量的正确方法是什么?

What is the difference between, dev.properties, application.conf, deploy.json files? What is the proper way to load variables from those files?

推荐答案

有几种选择:


  • 环境变量并支持替换(也支持在文件中具有默认值,并且仅在设置了环境变量的情况下使用)。 - https://github.com/lightbend/config#optional -system-or-env-variable-overrides

  • 系统属性,如果在启动JVM时设置了系统属性,并且该系统属性与config中的路径匹配文件,它会覆盖设置

  • 您可以使用系统属性-application.conf 文件https://github.com/lightbend/config#standard-behavior rel = nofollow noreferrer> https://github.com/lightbend/config#standard-behavior

  • Environment variables and using the support for substitution (there is also support for having default in the file and only use the environment vars if they are set). - https://github.com/lightbend/config#optional-system-or-env-variable-overrides
  • System properties, if you set a system property when you start the JVM, and that system property matches a path in the config file, it overrides the setting
  • You can point to an alternative application.conf file using a system property - https://github.com/lightbend/config#standard-behavior

如果这还不够的话,您还可以通过编程方式创建 Config 实例来选择逻辑,从而完全自定义逻辑,然后在创建时将其传递到 ActorSystem

If that is not enough you could also do completely custom logic around selecting logic by programmatically creating a Config instance and passing that to the ActorSystem when you create it.

dev.properties deploy.json 是AFAIK与Akka无关,除非有特殊说明

The dev.properties and deploy.json is AFAIK not related to Akka, unless something specifically done in your application.

这篇关于外部化配置Akka的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆