Search in sources :

Example 1 with BootstrapConfig

use of io.github.quickmsg.common.config.BootstrapConfig in project smqtt by quickmsg.

the class AbstractStarter method start.

public static void start(String path) {
    BootstrapConfig config = null;
    if (path != null) {
        if (path.endsWith(FileExtension.PROPERTIES_SYMBOL)) {
            ObjectMapper mapper = new ObjectMapper(new JavaPropsFactory());
            try {
                config = mapper.readValue(new File(path), BootstrapConfig.class);
            } catch (Exception e) {
                log.error("properties read error", e);
            }
        } else if (path.endsWith(FileExtension.YAML_SYMBOL_1) || path.endsWith(FileExtension.YAML_SYMBOL_2)) {
            ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
            try {
                config = mapper.readValue(new File(path), BootstrapConfig.class);
            } catch (Exception e) {
                log.error("yaml read error", e);
                return;
            }
        } else {
            throw new NotSupportConfigException();
        }
    }
    if (config == null) {
        config = BootstrapConfig.defaultConfig();
    }
    Bootstrap.builder().rootLevel(Level.toLevel(config.getSmqttConfig().getLogLevel())).tcpConfig(config.getSmqttConfig().getTcpConfig()).httpConfig(config.getSmqttConfig().getHttpConfig()).websocketConfig(config.getSmqttConfig().getWebsocketConfig()).clusterConfig(config.getSmqttConfig().getClusterConfig()).redisConfig(config.getSmqttConfig().getRedisConfig()).databaseConfig(config.getSmqttConfig().getDatabaseConfig()).meterConfig(config.getSmqttConfig().getMeterConfig()).ruleChainDefinitions(config.getSmqttConfig().getRuleChainDefinitions()).sourceDefinitions(config.getSmqttConfig().getRuleSources()).aclConfig(config.getSmqttConfig().getAcl()).build().doOnStarted(AbstractStarter::printUiUrl).startAwait();
}
Also used : JavaPropsFactory(com.fasterxml.jackson.dataformat.javaprop.JavaPropsFactory) NotSupportConfigException(io.github.quickmsg.exception.NotSupportConfigException) BootstrapConfig(io.github.quickmsg.common.config.BootstrapConfig) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NotSupportConfigException(io.github.quickmsg.exception.NotSupportConfigException)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JavaPropsFactory (com.fasterxml.jackson.dataformat.javaprop.JavaPropsFactory)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 BootstrapConfig (io.github.quickmsg.common.config.BootstrapConfig)1 NotSupportConfigException (io.github.quickmsg.exception.NotSupportConfigException)1 File (java.io.File)1