我一直在玩Spring Cloud Configuration.我喜欢解决方案的简单性以及它使用git作为默认配置存储的事实.
在将其作为集中式配置管理解决方案推出之前,我需要弄清楚两个方面.方面是:
高可用性
如何逐步推出配置更改(以支持金丝雀版本)
如果您已经在数据中心实现了这一点,或者只是玩这个,请分享您的想法!另外,我想听听创作者,他们如何看待单/跨数据中心环境中的推荐部署.
我正在寻找一个简单的例子,用于从运行Spring Cloud的配置服务器设置数据源(jdbc).我已经阅读了Spring的Spring.io文档并发现它们非常令人困惑.
有谁知道找个简单例子的地方?我试图在Github上运行他们的东西,但他们没有构建.
org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter类处理错误响应.
我想覆盖此过滤器以在转发时执行自定义响应而不是ZuulException等.
如何用我自己的版本替换它?只是写和注册?会这样做还是还需要其他东西?
我基于@spencergibb feign-eureka spring cloud starter示例构建了一个超级简单的Hystrix短路示例.起初我以为我无法得到hystrix javanica默认的fallbackMethod因为假装触发..现在,删除假,hystrix默认的fallbackMethod仍然没有捕获异常.
的pom.xml
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>1.0.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
:
</dependencies>
Run Code Online (Sandbox Code Playgroud)
主文件:
@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrix
@RestController
public class HelloClientApplication {
@Autowired
HelloClientComponent helloClientComponent;
@RequestMapping("/")
public String hello() {
return helloClientComponent.makeMultipleCalls();
}
public static void main(String[] args) {
SpringApplication.run(HelloClientApplication.class, args);
}
Run Code Online (Sandbox Code Playgroud)
}
HelloClientComponent.java(创建因为我知道javanica希望在spring托管组件或服务中):
@Component
public class HelloClientComponent {
@Autowired
RestTemplate restTemplate;
public String …Run Code Online (Sandbox Code Playgroud) Spring cloud配置服务器是微服务的sidecar应用程序的一个例子吗?
我有一个非常简单的Spring云应用程序如下:
@SpringBootApplication
@EnableDiscoveryClient
@RestController
@EnableAutoConfiguration
public class SpringCloudConsulDemoApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(SpringCloudConsulDemoApplication.class).web(true).run(args);
}
@Value("${my.message}")
private String message;
@RequestMapping("/")
public String home() {
return message;
}
@RequestMapping("/health")
public String health() {
return "Hello world";
}
}
Run Code Online (Sandbox Code Playgroud)
我在/ config/SpringCloudConsulDemo,dev /下的consul中配置了"my.message".当我更改"my.message"的值时,我在spring cloud app中获得了一些输出:
2016-06-26 12:41:18.621 INFO 1187 --- [pool-1-thread-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@601c9895: startup date [Sun Jun 26 12:41:18 CST 2016]; root of context hierarchy
2016-06-26 12:41:18.631 INFO 1187 --- [pool-1-thread-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and …Run Code Online (Sandbox Code Playgroud) 我正在寻找重启弹簧启动应用程序,所以使用Spring Actuator/restart端点正在使用curl,但我想在应用程序内部使用java代码调用相同的函数,我已经尝试过这段代码了,但它是不工作:
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
RestartEndpoint p = new RestartEndpoint();
p.invoke();
}
});
thread.setDaemon(false);
thread.start();
Run Code Online (Sandbox Code Playgroud) 如何使Spring Cloud Consul向外部IP注册?
我在docker中使用spring cloud consul运行spring boot应用程序。该应用程序正在docker集群上的docker网络内部运行。
这意味着如果spring consul使用主机名或IP地址注册,它将获得docker swarm内部的主机名或ip地址。我的领事服务器在docker群之外。
我有一个用于配置客户端和配置服务器的基本设置(与此处的教程完全相同-https : //spring.io/guides/gs/centralized-configuration/
我的问题是我可以解密服务器端的属性并将其作为纯文本发送,但是不能解密客户端而不是服务器端的属性。我正在使用对称加密,并且已经多次阅读了文档,但是无法在客户端工作时得到解密。
我在服务器端添加了以下属性,因此它不会在服务器端解密属性-
spring.cloud.config.server.encrypt.enabled=false
Run Code Online (Sandbox Code Playgroud)
我有一个application.yml文件,该文件具有加密的值-
name: '{cipher}hdshdghsgdhjsgdhsgdyassudyadssd2313wdw2e'
Run Code Online (Sandbox Code Playgroud)
我尝试将ENCRYPT_KEY / encrypt.key添加为客户端系统属性的环境变量。另外,尝试在application.properties和bootstrap.properties中添加相同的内容,但客户端无法解密。
先感谢您。
配置客户端POM-
.......................
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
..............
在配置服务器中,我添加了属性-
spring.cloud.config.server.encrypt.enabled=false
Run Code Online (Sandbox Code Playgroud)
在配置客户端上,我在application.properties和bootstrap.properties中都添加了crypto.key。 …
许多服务器使用相同的常量,有必要组织集中更改它们。在微服务架构中存储常数参数的最佳方法是什么?
例如,我们存储静态最终int MAX_PEOPLE_COUNT = 100; 该领域使用不同的微服务。如果我们更改此值,则所有微服务都应该看到它。
还要具有参数值的版本控制。