我的Spring Boot应用程序遇到了一个非常奇怪的问题。 我正在使用Eureka / Ribbon开发微服务应用程序以进行服务发现,该应用程序是一个统计生成器,提供了用于csv上传的API,并链接到数据库以进行数据检索,比较和持久性。
存在问题的流程非常简单:
该调用是通过api(通过邮递员和浏览器进行尝试)进行的,该API调用了转换器微服务。 转换器微服务将遍历上传直接列出每个未处理的文件。 然后,在同一微服务中使用此列表进行处理。首先,转换器调用数据检索器微服务,该服务返回三个对象列表。然后使用它们基于csvs构建pojo。
在这里出现问题的地方是,此方法执行两次,而其他方法仅执行一次。
Csv-uploader微服务(入口端点)
@GetMapping("/proxy/csv/process")
public void processProxyCsv(){
logger.info("Called for processing uploaded CSVs");
csvConverterServiceProxy.processPendingCsv();
}
和使用的代理:
@FeignClient(name="bbx-rev-csv-converter")
@RibbonClient(name="bbx-rev-csv-converter")
public interface CsvConverterServiceProxy {
@GetMapping("/csv/process/running")
public String processPendingCsv();
}
到目前为止,一切似乎都正常,日志仅显示一次。
然后,我们转到csv-converter微服务,其中发生了所有魔术(错误也包括bug),入口端点先前称为:
@GetMapping("/csv/process/running")
public ResponseEntity<String> processPendingCsv() {
HttpHeaders headers = new HttpHeaders();
HttpStatus status = HttpStatus.BAD_REQUEST;
String reason = "Pending...";
logger.info("API call for processing pending CSVs.");
if (fileHandlerService.checkForNonProcessedFiles()) {
logger.info("Check over, returning to entry flow.");
logger.info("file path : " + fileHandlerService.getUploadedFilePath().toString());
csvConverterService.convertAllCsv(fileHandlerService.getUploadedFilePath());
reason = "Processing pending CSVs in progress...";
} else {
reason = "No pending files found.";
}
status = HttpStatus.OK;
return new ResponseEntity<String>(reason, headers, status);
}
这时,基于日志,此操作执行两次。
我已经仔细阅读了所有代码,没有两次调用,也没有因为调用此代理方法而错误地创建了一个循环(或者至少没有找到它,实际上,我希望我做些愚蠢的事情)。 / p>
甚至在所有服务都运行了一段时间(几分钟后)后,当我调用同一端点时,它变得很奇怪。调用仅进行一次。
这是日志:
首先,Csv上传器日志:
2018-08-09 14:35:17.407 INFO 4588 --- [nio-8000-exec-7] Csv-up-ctrl : Called for processing uploaded CSVs
csv转换器日志...
2018-08-09 14:35:17.470 INFO 17280 --- [nio-8006-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-08-09 14:35:17.470 INFO 17280 --- [nio-8006-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-08-09 14:35:17.504 INFO 17280 --- [nio-8006-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 34 ms
2018-08-09 14:35:17.547 INFO 17280 --- [nio-8006-exec-1] Csv converter controller : API call for processing pending CSVs.
2018-08-09 14:35:17.548 INFO 17280 --- [nio-8006-exec-1] File checker service : Checking for unprocessed files ...
2018-08-09 14:35:17.555 INFO 17280 --- [nio-8006-exec-1] File checker service : Found 1 unprocessed files : [test_file.csv]
2018-08-09 14:35:17.555 INFO 17280 --- [nio-8006-exec-1] Csv converter controller : Check over, returning to entry flow.
2018-08-09 14:35:17.555 INFO 17280 --- [nio-8006-exec-1] Csv converter controller : file path : E:\workspace\Blackbox-reversements\csv-uploader\uploads\todo
2018-08-09 14:35:17.555 INFO 17280 --- [nio-8006-exec-1] Csv converter service : convertAllCsv call
2018-08-09 14:35:17.561 INFO 17280 --- [nio-8006-exec-1] s.c.a.AnnotationConfigApplicationContext : Refreshing SpringClientFactory-bbx-rev-ext-data-retriever: startup date [Thu Aug 09 14:35:17 CEST 2018]; parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7d18bd1a
2018-08-09 14:35:17.659 INFO 17280 --- [nio-8006-exec-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-08-09 14:35:18.002 INFO 17280 --- [nio-8006-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: bbx-rev-ext-data-retriever.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2018-08-09 14:35:18.034 INFO 17280 --- [nio-8006-exec-1] c.n.u.concurrent.ShutdownEnabledTimer : Shutdown hook installed for: NFLoadBalancer-PingTimer-bbx-rev-ext-data-retriever
2018-08-09 14:35:18.079 INFO 17280 --- [nio-8006-exec-1] c.netflix.loadbalancer.BaseLoadBalancer : Client: bbx-rev-ext-data-retriever instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=bbx-rev-ext-data-retriever,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2018-08-09 14:35:18.090 INFO 17280 --- [nio-8006-exec-1] c.n.l.DynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater
2018-08-09 14:35:18.125 INFO 17280 --- [nio-8006-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: bbx-rev-ext-data-retriever.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2018-08-09 14:35:18.127 INFO 17280 --- [nio-8006-exec-1] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client bbx-rev-ext-data-retriever initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=bbx-rev-ext-data-retriever,current list of Servers=[192.168.0.130:8036],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:192.168.0.130:8036; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 01:00:00 CET 1970; First connection made: Thu Jan 01 01:00:00 CET 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@11bc0eb
2018-08-09 14:35:18.414 INFO 17280 --- [nio-8006-exec-5] Csv converter controller : API call for processing pending CSVs.
2018-08-09 14:35:18.414 INFO 17280 --- [nio-8006-exec-5] File checker service : Checking for unprocessed files ...
2018-08-09 14:35:18.415 INFO 17280 --- [nio-8006-exec-5] File checker service : Found 1 unprocessed files : [test_file.csv]
2018-08-09 14:35:18.415 INFO 17280 --- [nio-8006-exec-5] Csv converter controller : Check over, returning to entry flow.
2018-08-09 14:35:18.415 INFO 17280 --- [nio-8006-exec-5] Csv converter controller : file path : E:\workspace\Blackbox-reversements\csv-uploader\uploads\todo
2018-08-09 14:35:18.415 INFO 17280 --- [nio-8006-exec-5] Csv converter service : convertAllCsv call
2018-08-09 14:35:18.989 INFO 17280 --- [nio-8006-exec-5] Csv converter service : CSVs path will go here
2018-08-09 14:35:19.050 INFO 17280 --- [nio-8006-exec-1] Csv converter service : CSVs path will go here
2018-08-09 14:35:19.095 INFO 17280 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty : Flipping property: bbx-rev-ext-data-retriever.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
所以不太好。可能是配置问题吗?对于我的微服务配置,我一直将其保持为原始状态:
对于主要班级:
@SpringBootApplication
@EnableFeignClients("com.telemaque.blackbox.reversement.csvuploader")
@EnableDiscoveryClient
public class CsvUploaderApplication {...
对于application.properties文件:
spring.application.name=bbx-rev-csv-converter
server.port=8006
eureka.client.service-url.default-zone=http://localhost:8761/eureka
和命名服务器的application.properties:
spring.application.name=bbx-rev-naming-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
对于命名服务器:
@SpringBootApplication
@EnableEurekaServer
public class NamingServerApplication {...
对于代理:
@FeignClient(name="bbx-rev-ext-data-retriever")
@RibbonClient(name="bbx-rev-ext-data-retriever")
public interface ExternalDataRetrieverProxy {...
我一直在浏览eureka git,看向弹簧的一面,但仍然不明白。这让我发疯,如果您有任何想法,我想听听!
非常感谢您的帮助!
编辑:进行了更多测试,我在命名服务器中发现了奇怪的日志:
2018-08-09 14:55:08.320 INFO 15068 --- [nio-8761-exec-2] c.n.e.registry.AbstractInstanceRegistry : Registered instance BBX-REV-CSV-CONVERTER/192.168.0.130:bbx-rev-csv-converter:8006 with status UP (replication=false)
2018-08-09 14:55:08.832 INFO 15068 --- [io-8761-exec-10] c.n.e.registry.AbstractInstanceRegistry : Registered instance BBX-REV-CSV-CONVERTER/192.168.0.130:bbx-rev-csv-converter:8006 with status UP (replication=true)
此外,当我直接调用API(而不是通过第一个微服务)时,它只能正确执行一次。
答案 0 :(得分:0)
这可能是因为功能区在连接超时时会重试。有关该检查的详细信息spring retry。要解决此问题,您可以按照以下步骤操作:-
feignClientName.ribbon.OkToRetryOnAllOperations=false
使用者的 application.properties 中,您还可以在application.yml
处查看更多属性