Spring Eureka Ribbon方法执行两次
我的Spring boot应用程序遇到了一个非常奇怪的问题。 我正在与Eureka/Ribbon一起开发一个用于服务发现的microservice应用程序,该应用程序是一个统计生成器,为csv上传提供API,并链接到数据库以进行数据检索、比较和持久性 有缺陷的流程非常简单:Spring Eureka Ribbon方法执行两次,spring,spring-boot,microservices,netflix-eureka,netflix-ribbon,Spring,Spring Boot,Microservices,Netflix Eureka,Netflix Ribbon,我的Spring boot应用程序遇到了一个非常奇怪的问题。 我正在与Eureka/Ribbon一起开发一个用于服务发现的microservice应用程序,该应用程序是一个统计生成器,为csv上传提供API,并链接到数据库以进行数据检索、比较和持久性 有缺陷的流程非常简单: 检查上载目录中是否有未处理的文件 获取未处理文件的路径并将其放入数组中 对于此数组的每个元素,将它们从Csv转换为pojo 发财 调用是从一个api(通过邮递员和浏览器尝试)发出的,该api调用转换器微服务。 conver
@FeignClient(name="bbx-rev-csv-converter")
@RibbonClient(name="bbx-rev-csv-converter")
public interface CsvConverterServiceProxy {
@GetMapping("/csv/process/running")
public String processPendingCsv();
}
到目前为止一切正常,日志只出现一次
然后我们转到csv converter microservice,在那里发生了所有神奇的事情(还有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);
}
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 {...
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)
对于命名服务器:
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 {...
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)
对于代理:
@FeignClient(name="bbx-rev-ext-data-retriever")
@RibbonClient(name="bbx-rev-ext-data-retriever")
public interface ExternalDataRetrieverProxy {...
我一直在看这里,eureka git,从spring的角度看,仍然无法理解它。这让我发疯了,如果你知道的话,我很想听
非常感谢你的帮助
编辑:又做了一些测试,我在命名服务器中发现了一个奇怪的日志:
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 {...
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时(不是通过第一个微服务),它只正确执行一次。这可能是因为Ribbon在连接超时时会重试。关于那张支票的详情。要解决此问题,您可以执行以下步骤:-
- 在csv converter microservice消费者的应用程序.properties中