我目前有许多可部署的应用程序,它们以分布式方式工作,以解决业务问题.我们目前正在使用许多属性配置文件来根据系统环境变量提供每个环境的更改配置.所有这些可部署应用程序共享数据库和消息传递的通用配置 目前,这是通过从类路径中获取属性文件并使两个已部署的应用程序共享包含属性文件的每个连接(db,jms)的公共jar来实现的.
我希望尽可能开始使用Spring Config Server外部化此配置.我有一个关于如何共享此常见配置的问题.
目前它看起来像这样: -
Web1
- 数据库
- jms
Messaging1
- 数据库
- jms
在这种情况下,两个部署的应用程序共享相同的连接,并且这些连接会根据环境(lab,prf,prd等)进行更改.如何为每个可部署应用程序配备应用程序配置的Spring配置服务器实现相同目的?
Application.yml
Web1.yml Web1
-dev.yml
Messaging1.yml
Messaging1-dev.yml
如果为环境更改了连接属性,我需要对每个可部署的应用程序配置进行更改,而不是只进行一次.
目前有没有实现这一目标?我只是错过了一个简单的观点吗?
我真的很难过这个.我们希望使用Spring Cloud Consul进行服务发现,我的大学正在推动使用Spring Cloud Consul Config而不是Spring Cloud Config,我之前已经为相关项目实施了Spring Cloud Consig Config.问题是,Spring Cloud Config运行良好,并且具有无缝的开箱即用版本控制管道(git),用于动态集中管理属性.为了在Spring Cloud Consul Config中支持相同的功能,似乎需要重新发明已经融入Spring Cloud Config的轮子.
有没有人有使用两者的经验?将两者结合使用是否合理?也就是说,有春天的云配置客户端指向一个春天的云配置服务器的更多的"静态"环境属性(事情,开发,质量保证期,生产都否则静态之间会发生变化)和Spring云领事配置像服务纯动态特性发现?
如果我错了,请有人纠正我,但是根据我的理解,为了使用Spring Cloud Consul Config支持"静态"属性的动态版本控制,我需要做些什么,我需要在git和物理之间进行某种管道"/config"每个Spring Cloud Consul Config应用程序实例的运行实例的目录:/
我有以下Spring cloud config application.yml:
spring:
application:
name: configserver
cloud:
config:
server:
git:
uri: https://xyz@bitbucket.org/xyz/microservices-configs.git
username: xyz
password: xyz
basedir: target/configs
server:
port: 8881
Run Code Online (Sandbox Code Playgroud)
以下是我bootstrap.yml的用户微服务:
spring:
application:
name: userservice
cloud:
config:
uri: http://localhost:8881/
Run Code Online (Sandbox Code Playgroud)
场景 - 1
当我在浏览器中点击配置服务器时:
http://localhost:8881/development/userservice-development.yml
它正确地提供文件.当我看到basedir目标/配置时,我看到:
- userservice.yml
- gateway.yml
Run Code Online (Sandbox Code Playgroud)
正是我想要的,因为我只在开发分支中添加了这两个文件.
场景 - 2
当我使用以下命令运行userservice微服务项目时:
mvn clean spring-boot:run -Dspring.profiles.active=development
它从git中获取正确的文件,但它从master分支结账!但不是我期待的开发分支.我期待对吗?(仅供参考我在master分支中有开发和生产yml)
所以问题是,我们如何使用配置服务器?是否有任何配置我们可以设置为仅从该特定分支获取yml?我认为我们需要设置一些标签,因为根据文档,默认标签是master.任何人都可以让我知道我们如何在上述场景中设置标签?
我一直在使用spring-boot中的指标,并对Spring-cloud如何改变行为产生一些混乱.
一个简单的最小弹簧启动1.3.3.RELEASE应用程序,带执行器和单个控制器:
@RestController
public class HelloController {
@Autowired
private CounterService counterService;
@RequestMapping("/hello")
public String sayHello(@RequestParam("name") String name) {
counterService.increment("counter.calls.hello");
return "Hello, " + name;
}
}
Run Code Online (Sandbox Code Playgroud)
此应用程序的度量标准端点具有
...
gauge.response.hello: 5,
gauge.response.metrics: 69,
gauge.response.star-star.favicon.ico: 2,
counter.status.200.star-star.favicon.ico: 4,
counter.status.200.metrics: 1,
counter.calls.hello: 5,
counter.status.200.hello: 5
Run Code Online (Sandbox Code Playgroud)
这是在spring-boot docs中描述的.我的自定义计数器(counter.calls.hello)按预期用作计数器.
现在,如果我将spring-cloud-starter-eureka(Brixton.RC1)添加到我的pom中并且不更改任何其他内容,则度量标准端点具有
...
gauge.servo.counter.calls.hello: 1,
normalized.servo.rest.totaltime: 0,
normalized.servo.rest.count: 0,
gauge.servo.rest.min: 0,
gauge.servo.rest.max: 0,
gauge.servo.response.hello: 7,
gauge.servo.response.star-star.favicon.ico: 2,
Run Code Online (Sandbox Code Playgroud)
正常的MVC指标消失了.响应代码信息在哪里?我的自定义计数器报告为gauge.servo.counter.calls.hello,但它不再作为计数器工作,它似乎只显示值1,即使我已经对HelloController进行了5次调用.稍微调试和搜索使我将计数器度量名称更改为meter.calls.hello,这会在度量响应中生成counter.servo.calls.hello,并恢复计数器功能.
进一步阅读表明,spring-cloud默认为指标伺服,并表明如果我使用java 8,我应该使用旁观者.将spring-cloud-starter-spectator添加到我的pom中,并返回"counter.calls.hello"作为计数器度量标准名称,度量标准端点具有
...
counter.calls.hello(): 3,
response.hello(): 7,
response.metrics(): 9,
response.star-star.favicon.ico(): 2,
Run Code Online (Sandbox Code Playgroud)
这有关于其余端点的内置信息更少,但我的自定义计数器似乎确实起作用.
有关指标的Spring-cloud文档似乎表明我应该使用ServoRegistry,无论是使用伺服还是旁观者.观众指标部分中的术语是不同的.柜台不按照我的预期运作.当我使用文档中描述的使用ServoRegistry发布一个简单的点击计数器时,我在度量标准端点中获得某种速率.
伺服和/或观众对弹簧靴提供的内容有一些附加价值吗?Spring-cloud文档表明,有更多信息记录到默认控制器指标,但它们没有显示在/ metrics中.我应该只是排除ServoMetricsAutoConfiguration并使用spring-boot实现吗?
我正在使用spring cloud eureka和spring cloud zuul proxy,我想知道是否有任何方法可以在eureka服务器中注册新服务时添加dymanic zuul路由,或者添加路由的唯一方法是编辑application.yml文件和重启spring zuul应用程序
zuul:
ignoredPatterns: /**/admin/**
routes:
users: /myusers/**
Run Code Online (Sandbox Code Playgroud) 如何在使用Spring Cloud AWS的Spring启动应用程序中禁用Cloudformation?
在亚马逊上运行我的应用程序时,我一直收到此错误:
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method 'stackResourceRegistryFactoryBean' threw exception; nested exception is com.amazonaws.AmazonServiceException: Stack for i-b5ce9e32 does not exist (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 75b3076a-176d-11e6-90cc-b55a643dc6d6)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 82 more
Caused by: com.amazonaws.AmazonServiceException: Stack for i-b5ce9e32 does not exist (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 75b3076a-176d-11e6-90cc-b55a643dc6d6)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1389)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:902)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.ja
...
Run Code Online (Sandbox Code Playgroud)
我不想使用cloudformation.(至少现在(是.)
java spring amazon-web-services spring-cloud spring-cloud-aws
我注意到Spring-Cloud ZUUL强制执行隔离到SEMAPHORE而不是THREAD默认值(根据Netflix的推荐).
评论org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand说:
我们希望默认为信号量隔离,因为这包含了另外两个已经线程隔离的命令
但我仍然没有得到它:-(那两个其他命令是什么?
以这种方式配置,Zuul只能调整加载但不允许超时并让客户端离开.简而言之,即使Hystrix超时设置为1000毫秒,只有在转发到链中的服务的调用返回时(或者由于例如ReadTimeout而超时),才会释放客户端.
我试图通过覆盖配置强制THREAD隔离(不幸的是,每个服务,因为在代码中强制默认),一切似乎按预期工作.但是,如果没有正确理解其含义,我并不热衷于这样做 - 当然关于代码中的注释以及Spring的Zuul版本采用的默认值.
有人可以提供更多信息吗?谢谢
所以我将Hystrix-AMQP的依赖项添加到我的服务中,日志文件变得疯狂,它只是继续记录指标的东西.我需要那个罐子才能将它与涡轮AMQP一起使用.
这是我在hystrix的gradle中所拥有的: -
compile ("org.springframework.cloud:spring-cloud-starter-hystrix:1.0.6.RELEASE")
compile ('org.springframework.cloud:spring-cloud-starter-bus-amqp:1.0.6.RELEASE')
compile ('org.springframework.cloud:spring-cloud-netflix-hystrix-amqp:1.0.7.RELEASE')
compile ('com.netflix.hystrix:hystrix-javanica:1.5.2')
Run Code Online (Sandbox Code Playgroud)
这是继续在我的日志中生成它继续运行: -
2016-05-03 13:49:14.698 INFO [LogMessage=Starting span: MilliSpan(begin=1462308554698, end=0, name=execution(HystrixStreamTask.sendMetrics()), traceId=21825112-0c71-4c6a-a9ca-51b11a21e4e5, parents=[], spanId=053946b5-7287-41f4-8579-d048655f41ea, remote=false, annotations={}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.698 INFO [LogMessage=Continued span: MilliSpan(begin=1462308554698, end=0, name=execution(HystrixStreamTask.sendMetrics()), traceId=21825112-0c71-4c6a-a9ca-51b11a21e4e5, parents=[], spanId=053946b5-7287-41f4-8579-d048655f41ea, remote=false, annotations={}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.698 INFO [LogMessage=Stopped span: MilliSpan(begin=1462308554698, end=1462308554698, name=execution(HystrixStreamTask.sendMetrics()), traceId=21825112-0c71-4c6a-a9ca-51b11a21e4e5, parents=[], spanId=053946b5-7287-41f4-8579-d048655f41ea, remote=false, annotations={/messaging/headers/id=e1cc5042-1a5c-e3f9-6f3c-de936d1aa959, /messaging/headers/timestamp=1462308554698, /messaging/payload/type=java.lang.String, /messaging/payload/size=592}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.698 INFO [LogMessage=Starting span: MilliSpan(begin=1462308554698, end=0, name=execution(HystrixStreamTask.gatherMetrics()), traceId=6cc342bb-9693-493a-8fa8-8a17c2ff06c3, parents=[], spanId=10cdee69-22f8-43ab-883f-3e09b29ab6fb, remote=false, annotations={}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.699 INFO [LogMessage=Continued …Run Code Online (Sandbox Code Playgroud) 我想使用Zuul作为我正在使用的一些REST服务的代理.我的问题是:因为我将它作为Spring Boot应用程序运行,有没有办法为高可用性配置它?
编辑:我是否需要在支持HA的应用服务器中部署我的应用程序?
spring spring-boot spring-cloud netflix-zuul spring-cloud-netflix
感谢您的时间.为简单起见,我创建了一个示例服务,如下所示:
@RestController
@RequestMapping("/")
public class ComputeController {
@GetMapping("/add")
public int add(@RequestParam("left") int left, @RequestParam("right") int right) {
return left + right;
}
}
Run Code Online (Sandbox Code Playgroud)
为了保护这个URL,我像这样配置spring-security:
management.security.enabled=true
security.user.name=admin
security.user.password=admin
Run Code Online (Sandbox Code Playgroud)
当我启动此服务并访问如下:
GET /add?left=100&right=11 HTTP/1.1
Authorization: ***** Hidden credentials *****
Host: localhost:7777
Connection: close
Run Code Online (Sandbox Code Playgroud)
这一切都很顺利.
在其他节点中,我通过netflix feign创建了一个"service-comsumer".这是一个Java接口.
@FeignClient(name = "API-GATEWAY", path = "/compute-service", fallback = ComputeServiceCircuitBreaker.class)
public interface ComputeServiceClient {
@RequestMapping(path = "/add", method = RequestMethod.GET)
public Integer add(@RequestParam("left") Integer left, @RequestParam("right") Integer right);
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何配置请求标题"授权".
任何的想法?再次感谢.
spring-cloud ×10
spring ×5
spring-boot ×4
netflix-zuul ×3
java ×2
amqp ×1
git ×1
hystrix ×1
netflix ×1
properties ×1
spring-mvc ×1