Search in sources :

Example 1 with BrokerConfigProvider

use of org.wso2.broker.common.BrokerConfigProvider in project carbon-apimgt by wso2.

the class BrokerManager method initConfigProvider.

/**
 * Loads configurations during the broker start up.
 * method will try to <br/>
 * (1) Load the configuration file specified in 'broker.file' (e.g. -Dbroker.file=<FilePath>). <br/>
 * (2) If -Dbroker.file is not specified, the broker.yaml file exists in current directory and load it. <br/>
 * <p>
 * <b>Note: </b> if provided configuration file cannot be read broker will not start.
 *
 * @param startupContext startup context of the broker
 */
private static void initConfigProvider(StartupContext startupContext) throws ConfigurationException {
    Path brokerYamlFile;
    String brokerFilePath = System.getProperty(BrokerConfiguration.SYSTEM_PARAM_BROKER_CONFIG_FILE);
    if (brokerFilePath == null || brokerFilePath.trim().isEmpty()) {
        // use current path.
        brokerYamlFile = Paths.get("", BrokerConfiguration.BROKER_FILE_NAME).toAbsolutePath();
    } else {
        brokerYamlFile = Paths.get(brokerFilePath).toAbsolutePath();
    }
    ConfigProvider configProvider = ConfigProviderFactory.getConfigProvider(brokerYamlFile, null);
    startupContext.registerService(BrokerConfigProvider.class, (BrokerConfigProvider) configProvider::getConfigurationObject);
}
Also used : Path(java.nio.file.Path) BrokerConfigProvider(org.wso2.broker.common.BrokerConfigProvider) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider)

Example 2 with BrokerConfigProvider

use of org.wso2.broker.common.BrokerConfigProvider in project carbon-apimgt by wso2.

the class BrokerManager method start.

/**
 * Starting the broker
 */
public static void start() {
    try {
        StartupContext startupContext = new StartupContext();
        initConfigProvider(startupContext);
        BrokerConfigProvider service = startupContext.getService(BrokerConfigProvider.class);
        BrokerConfiguration brokerConfiguration = service.getConfigurationObject(BrokerConfiguration.NAMESPACE, BrokerConfiguration.class);
        DataSource dataSource = getDataSource(brokerConfiguration.getDataSource());
        startupContext.registerService(DataSource.class, dataSource);
        restServer = new BrokerRestServer(startupContext);
        broker = new Broker(startupContext);
        broker.startMessageDelivery();
        amqpServer = new Server(startupContext);
        amqpServer.start();
        restServer.start();
        loadUsers();
    } catch (Exception e) {
        log.error("Error while starting broker", e);
    }
}
Also used : StartupContext(org.wso2.broker.common.StartupContext) BrokerRestServer(org.wso2.broker.rest.BrokerRestServer) Broker(org.wso2.broker.core.Broker) Server(org.wso2.broker.amqp.Server) BrokerRestServer(org.wso2.broker.rest.BrokerRestServer) BrokerConfiguration(org.wso2.broker.core.configuration.BrokerConfiguration) BrokerConfigProvider(org.wso2.broker.common.BrokerConfigProvider) ConfigurationException(org.wso2.carbon.config.ConfigurationException) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource)

Aggregations

BrokerConfigProvider (org.wso2.broker.common.BrokerConfigProvider)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 Path (java.nio.file.Path)1 DataSource (javax.sql.DataSource)1 Server (org.wso2.broker.amqp.Server)1 StartupContext (org.wso2.broker.common.StartupContext)1 Broker (org.wso2.broker.core.Broker)1 BrokerConfiguration (org.wso2.broker.core.configuration.BrokerConfiguration)1 BrokerRestServer (org.wso2.broker.rest.BrokerRestServer)1 ConfigurationException (org.wso2.carbon.config.ConfigurationException)1 ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)1