org.springframework.cloud.consul.ConsulProperties Java Examples

The following examples show how to use org.springframework.cloud.consul.ConsulProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsulPropertySourceLocatorTests.java    From spring-cloud-formula with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    this.properties = new ConsulProperties();
    this.client = new ConsulClient(this.properties.getHost(),
            this.properties.getPort());
    this.client.deleteKVValues(PREFIX);
    this.client.setKVValue(KEY1, VALUE1);
    this.client.setKVValue(KEY2, VALUE2);

    this.context = new SpringApplicationBuilder(Config.class)
            .web(WebApplicationType.NONE).run("--SPRING_APPLICATION_NAME=" + APP_NAME,
                    "--spring.cloud.consul.config.prefix=" + PREFIX,
                    "--spring.cloud.consul.config.token-enabled=false",
                    "--spring.cloud.consul.config.system-labels=app-test,env-test,d-test",
                    "spring.cloud.consul.config.watch.delay=10");

    this.client = this.context.getBean(ConsulClient.class);
    this.properties = this.context.getBean(ConsulProperties.class);
    this.environment = this.context.getEnvironment();
}
 
Example #2
Source File: ConsulPropertySourceLocatorFilesTests.java    From spring-cloud-consul with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
	this.properties = new ConsulProperties();
	this.client = new ConsulClient(this.properties.getHost(),
			this.properties.getPort());
	this.client.setKVValue(ROOT + APPLICATION_YML, "foo: bar\nmy.baz: ${foo}");
	this.client.setKVValue(ROOT + APPLICATION_DEV_YML,
			"foo: bar-dev\nmy.baz: ${foo}");
	this.client.setKVValue(ROOT + "/master.ref", UUID.randomUUID().toString());
	this.client.setKVValue(ROOT + APP_NAME_PROPS, "foo: bar-app\nmy.baz: ${foo}");
	this.client.setKVValue(ROOT + APP_NAME_DEV_PROPS,
			"foo: bar-app-dev\nmy.baz: ${foo}");

	this.context = new SpringApplicationBuilder(Config.class)
			.web(WebApplicationType.NONE).run("--spring.application.name=" + APP_NAME,
					"--spring.cloud.consul.config.prefix=" + ROOT,
					"--spring.cloud.consul.config.format=FILES",
					"--spring.profiles.active=dev",
					"spring.cloud.consul.config.watch.delay=1");

	this.client = this.context.getBean(ConsulClient.class);
	this.properties = this.context.getBean(ConsulProperties.class);
	this.environment = this.context.getEnvironment();
}
 
Example #3
Source File: ConsulPropertySourceLocatorTests.java    From spring-cloud-consul with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
	this.properties = new ConsulProperties();
	this.client = new ConsulClient(this.properties.getHost(),
			this.properties.getPort());
	this.client.deleteKVValues(PREFIX);
	this.client.setKVValue(KEY1, VALUE1);
	this.client.setKVValue(KEY2, VALUE2);

	this.context = new SpringApplicationBuilder(Config.class)
			.web(WebApplicationType.NONE).run("--SPRING_APPLICATION_NAME=" + APP_NAME,
					"--spring.cloud.consul.config.prefix=" + ROOT,
					"spring.cloud.consul.config.watch.delay=10");

	this.client = this.context.getBean(ConsulClient.class);
	this.properties = this.context.getBean(ConsulProperties.class);
	this.environment = this.context.getEnvironment();
}
 
Example #4
Source File: ConsulPropertySourceLocatorAppNameCustomizedTests.java    From spring-cloud-consul with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
	this.properties = new ConsulProperties();
	this.client = new ConsulClient(this.properties.getHost(),
			this.properties.getPort());
	this.client.deleteKVValues(PREFIX);
	this.client.setKVValue(KEY1, VALUE1);
	this.client.setKVValue(KEY2, VALUE2);

	this.context = new SpringApplicationBuilder(Config.class)
			.web(WebApplicationType.NONE)
			.run("--spring.application.name=testConsulPropertySourceLocatorAppNameCustomized",
					"--spring.cloud.consul.config.name=" + CONFIG_NAME,
					"--spring.cloud.consul.config.prefix=" + ROOT);

	this.client = this.context.getBean(ConsulClient.class);
	this.properties = this.context.getBean(ConsulProperties.class);
	this.environment = this.context.getEnvironment();
}
 
Example #5
Source File: ConsulConfigBootstrapConfiguration.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public ConsulClient consulClient(ConsulProperties consulProperties,
                                 ConsulConfigProperties consulConfigProperties) {
    final int agentPort = consulProperties.getPort();
    final String agentHost = !StringUtils.isEmpty(consulProperties.getScheme())
            ? consulProperties.getScheme() + "://" + consulProperties.getHost()
            : consulProperties.getHost();

    logger.info("Init consul host: " + agentHost + " port: " + agentPort);
    if (consulProperties.getTls() != null) {
        ConsulProperties.TLSConfig tls = consulProperties.getTls();
        TLSConfig tlsConfig = new TLSConfig(
                tls.getKeyStoreInstanceType(),
                tls.getCertificatePath(),
                tls.getCertificatePassword(),
                tls.getKeyStorePath(),
                tls.getKeyStorePassword()
        );
        return new ConsulClient(agentHost, agentPort, tlsConfig);
    }
    HttpRequestInterceptor httpRequestInterceptor = new BmsCommonInterceptor();
    BmsHttpTransport httpTransport = new BmsHttpTransport(httpRequestInterceptor);
    ConsulRawClient rawClient = new ConsulRawClient(httpTransport.getHttpClient(),
            agentHost, agentPort, consulConfigProperties.getPath());
    return new ConsulClient(rawClient);
}
 
Example #6
Source File: ConsulPropertySourceLocatorFilesTests.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {


    this.properties = new ConsulProperties();
    this.client = new ConsulClient(this.properties.getHost(),
            this.properties.getPort());
    this.client.setKVValue(ROOT + APPLICATION_YML, "foo: bar\nmy.baz: ${foo}");
    this.client.setKVValue(ROOT + APPLICATION_DEV_YML,
            "foo: bar-dev\nmy.baz: ${foo}");
    this.client.setKVValue(ROOT + "/master.ref", UUID.randomUUID().toString());
    this.client.setKVValue(ROOT + APP_NAME_PROPS, "foo: bar-app\nmy.baz: ${foo}");
    this.client.setKVValue(ROOT + APP_NAME_DEV_PROPS,
            "foo: bar-app-dev\nmy.baz: ${foo}");

    this.context = new SpringApplicationBuilder(ConsulConfigBootstrapConfiguration.class)
            .web(WebApplicationType.NONE).run("--spring.application.name=" + APP_NAME,
                    "--spring.cloud.consul.config.prefix=" + ROOT,
                    "--spring.cloud.consul.config.format=FILES",
                    "--spring.cloud.consul.config.token-enabled=false",
                    "--spring.cloud.consul.config.default-context=application",
                    "--spring.cloud.consul.config.system-labels=application-dev,testFilesFormat," +
                            "testFilesFormat-dev",
                    "spring.cloud.consul.config.watch.delay=1");

    this.client = this.context.getBean(ConsulClient.class);
    this.properties = this.context.getBean(ConsulProperties.class);
    this.environment = this.context.getEnvironment();
}
 
Example #7
Source File: ConsulPropertySourceTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	this.properties = new ConsulProperties();
	this.prefix = "consulPropertySourceTests"
			+ new Random().nextInt(Integer.MAX_VALUE);
	this.client = new ConsulClient(this.properties.getHost(),
			this.properties.getPort());
}
 
Example #8
Source File: ConsulPropertyPrefixTests.java    From spring-cloud-consul with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	ConsulProperties properties = new ConsulProperties();
	this.client = new ConsulClient(properties.getHost(), properties.getPort());
}