给定以下Spring Cloud设置:A data-service可以访问数据库,可以访问eureka-service服务注册表和发现,第3个服务business-service是封装业务案例的各种服务之一.
单元测试data-service没问题,我只是关掉eureka via
eureka.client.enabled=false
Run Code Online (Sandbox Code Playgroud)
并使用内存数据库进行测试.
要访问data-servicefrom business-service,我正在使用一个带@FeignClient("data-service")注释的接口DataClient,这个接口是@Autowired需要的.如果两者都在运行,Eureka会发现该服务.这适用于所有服务运行的类似生产的设置.
但现在我想对我的一些功能进行单元测试business-service.用它来启动测试服务不是问题
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
@SpringApplicationConfiguration(classes = Application.class)
Run Code Online (Sandbox Code Playgroud)
就像我在做的那样data-service.问题是我的Eureka依赖发现FeignClient...所以我的测试类崩溃,因为自动装配我的DataClient实例不起作用.
我能告诉Spring使用伪造的实例来DataClient进行测试吗?或者是让我的测试运行可访问的运行实例data-service和我的Eureka服务器的唯一方法?
根据这篇博客https://spring.io/blog/2015/07/14/microservices-with-spring
能够毫无问题地运行应用程序.按此顺序:
但是当尝试通过Web应用程序(http:// localhost:3333 /)使用http:// ACCOUNTS-SERVICE URL访问任何帐户服务端点(如http:// ACCOUNTS-SERVICE/accounts/123456789)时,我收到错误回复:
Response Status: 500 (Internal Server Error)
Cause: org.springframework.web.client.ResourceAccessException I/O error on GET request for "http://ACCOUNTS-SERVICE/accounts/123456789": ACCOUNTS-SERVICE; nested exception is java.net.UnknownHostException: ACCOUNTS-SERVICE
Run Code Online (Sandbox Code Playgroud)
当我向Web服务器而不是http:// ACCOUNTS-SERVICE提供帐户服务的真实地址(http:// localhost:2223 /)时,一切正常,但在这种情况下没有服务发现.
我想知道是否有一种Eureka客户端知道它的实际instanceId的方法(我正在寻找一种在同一主机和分布式conf上均可使用的解决方案)。
到目前为止,我使用的是手动定义的eureka.instance.instance-id: ${spring.application.name}:${random.int},但是每次访问它的值时,由于随机性,都会得到一个新值。因此,它与注册时生成并提供给服务器的总是不同的。
我正在通过 Zuul 调用我的演示服务。当我重新启动演示服务并在 Eureka 中注意到它时,Zuul 抛出了一个关于“负载均衡器没有可用的客户端服务器:演示服务”的异常。
当我继续通过 Zuul 调用演示服务时,它仅在 30 秒后才开始工作。
尤里卡服务器配置:
spring.application.name=registry
server.ip=127.0.0.1
server.port=6006
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${server.ip}:${server.port}/eureka/
eureka.server.enable-self-preservation=false
eureka.server.eviction-interval-timer-in-ms=5000
Run Code Online (Sandbox Code Playgroud)
祖尔配置:
spring.application.name=gateway
server.port=4002
## demo
zuul.routes.api-demo.path=/demo/**
zuul.routes.api-demo.serviceId=demo-service
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:6006/eureka
eureka.instance.prefer-ip-address=true
eureka.client.registryFetchIntervalSeconds=5
logging.level.root=debug
Run Code Online (Sandbox Code Playgroud)
尤里卡客户端配置(演示服务):
spring.application.name=demo-service
server.port=6020
endpoints.shutdown.enabled=true
endpoints.shutdown.sensitive=false
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:6006/eureka
eureka.instance.prefer-ip-address=true
eureka.instance.lease-renewal-interval-in-seconds=5
eureka.instance.lease-expiration-duration-in-seconds=10
eureka.client.healthcheck.enabled=true
Run Code Online (Sandbox Code Playgroud)
eureka.client.registryFetchIntervalSeconds=5考虑到 Zuul 最多需要 30 秒才能知道演示服务实例,因此似乎在 Zuul 配置中不起作用。我怎样才能让它正常工作?
我正在与 Eureka Netflix 合作,但遇到了一个小问题。当应用程序在 eureka 上自行注册时,它会像 DESKTOP 一样注册....
这是我的服务器属性:
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.instance.preferIpAddress=true
logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
Run Code Online (Sandbox Code Playgroud)
这是客户端:
spring:
application:
name: Test 2
server:
port: 0
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true
Run Code Online (Sandbox Code Playgroud)
所以我认为这是一些配置问题,但我不知道是什么。
我需要一些帮助来理解为什么在 Eureka 中注册的服务尽管没有实际运行,但仍希望相互通信。例如,我在 Eureka 注册了服务 A 和服务 B。如果我关闭服务 B,服务 A 仍会尝试与服务 B 通信 30 秒到 3 分钟,即使它没有运行。这样做的目的是什么?有什么办法可以解决吗?谢谢!
我正在尝试将客户端注册到 spring-eureka-server,客户端在注册后立即注销
尤里卡服务器日志:
2018-05-13 16:02:47.290 INFO 25557 --- [io-9091-exec-10] cneregistry.AbstractInstanceRegistry:注册实例 HELLO-CLIENT/192.168.43.96:hello-client:8072(状态为 false) ) 2018-05-13 16:02:47.438 INFO 25557 --- [nio-9091-exec-3] cneregistry.AbstractInstanceRegistry : 注册实例 HELLO-CLIENT/192.168.43.96:hello-client status:8072 (DOWNreplication=DOWNreplication) false) 2018-05-13 16:02:47.457 INFO 25557 --- [nio-9091-exec-2] cneregistry.AbstractInstanceRegistry:取消实例 HELLO-CLIENT/192.168.43.96:hello-client:8072 2018-05-13 16:02:47.950 INFO 25557 --- [nio-9091-exec-5] cneregistry.AbstractInstanceRegistry :注册实例 HELLO-CLIENT/192.168.43.96:hello-client:8072,状态为真) 2018-05-13 16:02:47。951 INFO 25557 --- [nio-9091-exec-5] cneregistry.AbstractInstanceRegistry : 取消实例 HELLO-CLIENT/192.168.43.96:hello-client:8072 (replication=true) 2018-05-13:256.703 25557 --- [a-EvictionTimer] cneregistry.AbstractInstanceRegistry:以 4ms 的补偿时间运行驱逐任务
尤里卡客户端日志:
2018-05-13 16:02:47.163 INFO 25676 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_HELLO-CLIENT/192.168.43.96:hello-client:8072: registering service... -13 16:02:47.212 信息 25676 --- [
main] …
我已经通过复制创建了Eureka 服务器,现在尝试启动客户端。当我尝试启动 时spring-microservices-eureka-client,出现以下错误。使用 Spring Boot 版本2.1.1.RELEASE。引导版本2.0.7.RELEASE和Finchley.SR2.
2018-12-28 13:52:16.741 INFO 20236 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application UNKNOWN with eureka with status UP
2018-12-28 13:52:16.742 INFO 20236 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1545985336742, current=UP, previous=STARTING]
2018-12-28 13:52:16.743 INFO 20236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org: registering service...
2018-12-28 13:52:16.749 INFO 20236 --- [ main] ringMicroservicesEurekaClientApplication : Started SpringMicroservicesEurekaClientApplication in 3.335 seconds (JVM running …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的 4 个微服务实施 Discovery First Bootstrap 方式。第一个是从 git 获取配置的配置服务器,第二个是 Eureka 服务器。当我运行 docker-compose up 时,我的配置服务器无法注册 eureka。我有:
请求执行错误。endpoint=DefaultEndpoint{ serviceUrl=' http://localhost:8761/ } 连接被拒绝
我的配置服务器
@EnableConfigServer
@EnableEurekaClient
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
Run Code Online (Sandbox Code Playgroud)
应用程序.yml
server:
port: 8888
spring:
cloud:
config:
server:
encrypt.enabled: false
git:
uri: https://github.com/Artuwok/artbook-config-repo/
searchPaths: userservice
username: Artuwok
password: Civilization1986
timeout: 10
force-pull: true
Run Code Online (Sandbox Code Playgroud)
引导程序.yml
spring:
application:
name: configserver
cloud:
config:
fail-fast: true
discovery.enabled: true
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl.defaultZone: http://localhost:8761/eureka/
Run Code Online (Sandbox Code Playgroud)
尤里卡级 …
我有一个 Spring Boot Eureka 服务器应用程序,它被配置为在端口 5000 而不是默认的 8761 端口中运行。但是,当我运行 SBA 时,在监听 localhost:8761 时,我在控制台上收到了一些与 java 连接被拒绝相关的错误
信息 10408 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient :从尤里卡服务器获取所有实例注册信息错误 10408 --- [tbeatExecutor-0] cndstdRedirectingEurekaHttpClient :请求执行错误。endpoint=DefaultEndpoint{ serviceUrl=' http://localhost:8761/eureka/ }
com.sun.jersey.api.client.ClientHandlerException:java.net.ConnectException:连接被拒绝:连接在 com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4 -1.19.1.jar:1.19.1]
稍后当我启动其他微服务时,我可以看到它们在 eureka 中正确注册并在端口 5000 上运行。但是为什么应用程序在启动 Eureka 服务器时会忽略配置?
同样从嵌入的图片中可以明显看出,服务器正在 8761 中寻找已注册和不可用的副本。
将非常感谢对此的任何解释。
spring-boot spring-cloud netflix-eureka spring-cloud-netflix
netflix-eureka ×10
spring-boot ×5
spring-cloud ×5
java ×2
spring ×2
docker ×1
netflix-zuul ×1
unit-testing ×1