我一直在使用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-stream 的 kafka binder,如何配置并发消息消费者(在单个消费者 jvm 中)?如果我理解正确,在使用 kafka 时并发消息消耗需要分区,但scs 文档表明要使用分区,您需要通过 partitionKeyExpression 或 partitionKeyExtractorClass 在生产者中指定分区选择。Kafka 文档提到了循环分区。
scs 文档根本没有提到 spring.cloud.stream.bindings.*.concurrency ,尽管这在我上面描述的用例中似乎很重要。使用生产者配置
spring:
cloud:
stream:
bindings:
customer-save:
destination: customer-save
group: customer-save
content-type: application/json
partitionCount: 3
Run Code Online (Sandbox Code Playgroud)
和消费者配置
spring:
cloud:
stream:
bindings:
customer-save:
destination: customer-save
group: customer-save
content-type: application/x-java-object;type=foo.Customer
partitioned: true
concurrency: 3
Run Code Online (Sandbox Code Playgroud)
我似乎得到了我想要的行为(至少在某种程度上)。我可以看到有时有 3 个消费者线程处于活动状态,尽管似乎确实存在一些除循环之外的分区在起作用,因为有些消息似乎在等待繁忙的消费者线程并在该线程完成后被消耗。我认为这是因为消息被发送到同一个分区。
当我没有指定 partitionKeyExpression 或 partitionKeyExtractorClass 时,是否有一些默认的密钥提取和分区策略在生产者上使用?这是使用 kafka 设置 scs 使用者的合适方法,您希望多个线程使用消息以增加使用者吞吐量?
是否有一个应该与spring-cloud-stream一起使用的请求-答复模式?我在spring-cloud-stream上可以找到的所有文档都针对MessageChannel.send即发即弃类型的生产者,我对spring-integration的@MessagingGateway很熟悉,但是我不确定这会如何与spring-cloud-stream合作。当您具有一个REST POST端点,该端点使用分配的标识符保存实体并且您需要将分配的标识符返回给调用者,但仍要使用消息传递时,这将很有用。
我一直在玩 spring-cloud-stream (1.0.0.BUILD-SNAPSHOT with kafka binder) 并注意到消费者离线时,发送的任何消息都会丢失。当我启动消费者时,它不会处理发送到 kafka 的积压请求。这是故意的吗?
我一直在网上搜寻有关将 spring-cloud-netflix eureka 服务器部署到 aws 的正确方法的指导。我们一直在为使用 spring-cloud 和 nodejs 的微服务使用 docker,所以我一直在尝试将我的 spring-boot spring-cloud eureka 应用程序部署到 ECS。spring-cloud 文档中的信息非常有限,但我在这里找到了一些相当有用的信息:https : //www.slideshare.net/ToddMiller34/spring-cloud-into-production。基于此,我目前有以下几点:
标准 spring-cloud-starter-eureka-server (spring-cloud Camden.SR5, spring-boot 1.5.1) 与
@Bean
@Autowired
@Profile("aws")
public EurekaInstanceConfigBean eurekaInstanceConfigBean(InetUtils inetUtils) {
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);
AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
config.setHostname(info.get(AmazonInfo.MetaDataKey.publicHostname));
config.setIpAddress(info.get(AmazonInfo.MetaDataKey.publicIpv4));
config.setDataCenterInfo(info);
return config;
}
Run Code Online (Sandbox Code Playgroud)
来自 cloud config repo 的相关配置部分:
eureka:
instance:
non-secure-port: ${server.port}
environment: test
client:
eurekaServerDNSName: test.mydomain.com
datacenter: cloud
client:
region: us-west-2
registerWithEureka: true
fetchRegistry: true
eurekaServerURLContext: eureka
eurekaServerPort: 8761
useDnsForFetchingServiceUrls: true …Run Code Online (Sandbox Code Playgroud)