Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properties加载建议? #64

Closed
VanXD opened this issue Aug 16, 2018 · 1 comment
Closed

properties加载建议? #64

VanXD opened this issue Aug 16, 2018 · 1 comment
Labels
area/configuration Issues or PRs related to configurations of Sentinel kind/enhancement Category issues or prs related to enhancement.

Comments

@VanXD
Copy link

VanXD commented Aug 16, 2018

根据代码可以看到是拿的${appName}.properties文件中的配置.
但是这个appName要从JVM属性上拿, 实在不太方便...
咱们可以考虑像Spring或者Dubbo一样, 默认就去拿application.properties或者dubbo.properties吗?
或者最好的就是提供JavaConfig方案?我们就可以想在哪里写配置都行了.

    private static void loadProps() {
        // Resolve app name.
        AppNameUtil.resolveAppName();
        try {
            String appName = AppNameUtil.getAppName();
            if (appName == null) {
                appName = "";
            }
            // We first retrieve the properties from the property file.
            String fileName = LogBase.getLogBaseDir() + appName + ".properties";
            File file = new File(fileName);
            if (file.exists()) {
                RecordLog.info("read SentinelConfig from " + fileName);
                FileInputStream fis = new FileInputStream(fileName);
                Properties fileProps = new Properties();
                fileProps.load(fis);
                fis.close();

                for (Object key : fileProps.keySet()) {
                    SentinelConfig.setConfig((String)key, (String)fileProps.get(key));
                    try {
                        String systemValue = System.getProperty((String)key);
                        if (!StringUtil.isEmpty(systemValue)) {
                            SentinelConfig.setConfig((String)key, systemValue);
                        }
                    } catch (Exception e) {
                        RecordLog.info(e.getMessage(), e);
                    }
                    RecordLog.info(key + " value: " + SentinelConfig.getConfig((String)key));
                }
            }
        } catch (Throwable ioe) {
            RecordLog.info(ioe.getMessage(), ioe);
        }

        // JVM parameter override file config.
        for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
            SentinelConfig.setConfig(entry.getKey().toString(), entry.getValue().toString());
        }
    }
@sczyh30
Copy link
Member

sczyh30 commented Jul 8, 2019

This will be fixed in #804.

If you're using Spring Boot/Spring Cloud you could leverage Spring Cloud Alibaba to support configuring via application.properties: https://github.com/spring-cloud-incubator/spring-cloud-alibaba/wiki/Sentinel#more

@sczyh30 sczyh30 closed this as completed Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration Issues or PRs related to configurations of Sentinel kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
2 participants