initial commit

This commit is contained in:
Spencer Gibb
2014-12-01 15:52:48 -07:00
commit 69240b99f5
61 changed files with 27229 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-consul-sample</artifactId>
<packaging>jar</packaging>
<name>Spring Cloud Consul Sample</name>
<description>Spring Cloud Consul Sample</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-config</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-discovery</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-bus</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,64 @@
package org.springframework.cloud.consul.sample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.cloud.bus.jackson.SubtypeModule;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.consul.bus.SimpleRemoteEvent;
import org.springframework.cloud.consul.discovery.ConsulLoadBalancerClient;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Spencer Gibb
*/
@Configuration
@EnableAutoConfiguration
@RestController
@Slf4j
public class SampleApplication implements ApplicationListener<SimpleRemoteEvent> {
public static final String CLIENT_NAME = "testConsulApp";
@Autowired
ConsulLoadBalancerClient loadBalancer;
@Autowired
Environment env;
@Autowired(required = false)
RelaxedPropertyResolver resolver;
@RequestMapping("/")
public ServiceInstance lb() {
return loadBalancer.choose(CLIENT_NAME);
}
@RequestMapping("/myenv")
public String env(@RequestParam("prop") String prop) {
String property = new RelaxedPropertyResolver(env).getProperty(prop, "Not Found");
return property;
}
@Bean
public SubtypeModule sampleSubtypeModule() {
return new SubtypeModule(SimpleRemoteEvent.class);
}
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
@Override
public void onApplicationEvent(SimpleRemoteEvent event) {
log.info("Received event: {}", event);
}
}

View File

@@ -0,0 +1,20 @@
server:
port: 8080
#TODO: figure out why I need this here and in bootstrap.yml
spring:
application:
name: testConsulApp
security:
user:
name: user
password: password
endpoints:
health:
sensitive: false
restart:
enabled: true
shutdown:
enabled: true

View File

@@ -0,0 +1,7 @@
spring:
application:
name: testConsulApp
cloud:
config:
# TODO: refactor spring-cloud-config to use refresh, etc.. with out config client
enabled: false