Commit 8ff3462a by Dave Syer

Add bootstrap configuration for eureka-first

See gh-42
parent dd967120
...@@ -38,6 +38,11 @@ ...@@ -38,6 +38,11 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId> <artifactId>spring-cloud-netflix-core</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version> <version>1.0.0.BUILD-SNAPSHOT</version>
</dependency> </dependency>
......
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.netflix.archaius</groupId> <groupId>com.netflix.archaius</groupId>
<artifactId>archaius-core</artifactId> <artifactId>archaius-core</artifactId>
<optional>true</optional> <optional>true</optional>
......
/*
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.netflix.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.event.ContextRefreshedEvent;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.DiscoveryClient;
/**
* @author Dave Syer
*
*/
@ConditionalOnClass({DiscoveryClient.class, ConfigServicePropertySourceLocator.class})
@ConditionalOnExpression("${spring.cloud.bootstrap.config.useDiscovery:false}")
@Configuration
@EnableEurekaClient
@Import(EurekaClientAutoConfiguration.class)
@Slf4j
public class DiscoveryClientConfigServiceBootstrapConfiguration implements ApplicationListener<ContextRefreshedEvent> {
private static final String DEFAULT_CONFIG_SERVER = "CONFIGSERVER";
@Autowired
private DiscoveryClient client;
@Autowired
private ConfigServicePropertySourceLocator delegate;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
try {
log.info("Locating configserver via discovery");
InstanceInfo server = client.getNextServerFromEureka(DEFAULT_CONFIG_SERVER, false);
delegate.setUri(server.getHomePageUrl());
} catch (Exception e) {
log.warn("Could not locate configserver via discovery", e);
}
}
}
...@@ -16,15 +16,20 @@ ...@@ -16,15 +16,20 @@
package org.springframework.cloud.netflix.eureka; package org.springframework.cloud.netflix.eureka;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.management.MBeanServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.servo.ServoMetricReader;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.netflix.appinfo.EurekaInstanceConfig; import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.EurekaClientConfig; import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.converters.JsonXStream; import com.netflix.discovery.converters.JsonXStream;
import com.netflix.discovery.converters.XmlXStream; import com.netflix.discovery.converters.XmlXStream;
...@@ -38,11 +43,16 @@ import com.netflix.discovery.converters.XmlXStream; ...@@ -38,11 +43,16 @@ import com.netflix.discovery.converters.XmlXStream;
@ConditionalOnClass(EurekaClientConfig.class) @ConditionalOnClass(EurekaClientConfig.class)
@ConditionalOnExpression("${eureka.client.enabled:true}") @ConditionalOnExpression("${eureka.client.enabled:true}")
public class EurekaClientAutoConfiguration { public class EurekaClientAutoConfiguration {
@Autowired
private DiscoveryClient discoveryClient;
@PostConstruct @PostConstruct
public void init() { public void init() {
XmlXStream.getInstance().setMarshallingStrategy(new DataCenterAwareMarshallingStrategy()); XmlXStream.getInstance().setMarshallingStrategy(
JsonXStream.getInstance().setMarshallingStrategy(new DataCenterAwareMarshallingStrategy()); new DataCenterAwareMarshallingStrategy());
JsonXStream.getInstance().setMarshallingStrategy(
new DataCenterAwareMarshallingStrategy());
} }
@Bean @Bean
...@@ -56,4 +66,15 @@ public class EurekaClientAutoConfiguration { ...@@ -56,4 +66,15 @@ public class EurekaClientAutoConfiguration {
public EurekaInstanceConfigBean eurekaInstanceConfigBean() { public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
return new EurekaInstanceConfigBean(); return new EurekaInstanceConfigBean();
} }
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(MBeanServer.class)
@ConditionalOnExpression("${spring.jmx.enabled:true}")
public EurekaHealthIndicator eurekaHealthIndicator(MBeanServer server,
EurekaInstanceConfig config) {
return new EurekaHealthIndicator(discoveryClient, new ServoMetricReader(server),
config);
}
} }
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package org.springframework.cloud.netflix.eureka; package org.springframework.cloud.netflix.eureka;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import javax.management.MBeanServer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -28,7 +27,6 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerInitial ...@@ -28,7 +27,6 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerInitial
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory; import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.servo.ServoMetricReader;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.SmartLifecycle; import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -39,7 +37,6 @@ import org.springframework.context.annotation.ScopedProxyMode; ...@@ -39,7 +37,6 @@ import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import com.netflix.appinfo.ApplicationInfoManager; import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.appinfo.InstanceInfo.InstanceStatus; import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import com.netflix.discovery.DiscoveryManager; import com.netflix.discovery.DiscoveryManager;
import com.netflix.discovery.EurekaClientConfig; import com.netflix.discovery.EurekaClientConfig;
...@@ -149,15 +146,6 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered { ...@@ -149,15 +146,6 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
} }
@Bean @Bean
@ConditionalOnMissingBean
@ConditionalOnExpression("${spring.jmx.enabled:true}")
public EurekaHealthIndicator eurekaHealthIndicator(MBeanServer server,
EurekaInstanceConfig config) {
return new EurekaHealthIndicator(eurekaDiscoveryClient(),
new ServoMetricReader(server), config);
}
@Bean
protected ApplicationListener<EmbeddedServletContainerInitializedEvent> containerPortInitializer() { protected ApplicationListener<EmbeddedServletContainerInitializedEvent> containerPortInitializer() {
return new ApplicationListener<EmbeddedServletContainerInitializedEvent>() { return new ApplicationListener<EmbeddedServletContainerInitializedEvent>() {
......
...@@ -17,7 +17,6 @@ package org.springframework.cloud.netflix.hystrix; ...@@ -17,7 +17,6 @@ package org.springframework.cloud.netflix.hystrix;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -38,7 +37,6 @@ import org.springframework.core.Ordered; ...@@ -38,7 +37,6 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.hystrix.Hystrix; import com.netflix.hystrix.Hystrix;
......
...@@ -4,4 +4,7 @@ org.springframework.cloud.netflix.feign.FeignAutoConfiguration,\ ...@@ -4,4 +4,7 @@ org.springframework.cloud.netflix.feign.FeignAutoConfiguration,\
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration,\ org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration,\
org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration,\ org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration,\
org.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration,\ org.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration,\
org.springframework.cloud.netflix.servo.ServoMetricsAutoConfiguration org.springframework.cloud.netflix.servo.ServoMetricsAutoConfiguration
\ No newline at end of file
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment