我正在使用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) 我想控制在Eureka服务器上运行的微服务.我使用spring-boot-admin,但是我在访问Trace,Log等信息时遇到错误...
我得到的错误是
错误:{"timestamp":1489052472862,"status":401,"error":"Unauthorized","message":"访问此资源需要完全身份验证.","path":"/ metrics"}
我的依赖是
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.4.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并且以下属性均无效
endpoints.info.id=information
endpoints.info.sensitive=false
endpoints.info.enabled=true
information.app.name=Actuator Example
information.app.description=Actuator Example
information.app.version=1.0.0
Run Code Online (Sandbox Code Playgroud)
所有的终点都发生了同样的事情,如映射,环境和所有接受健康
spring spring-boot microservices netflix-eureka spring-boot-admin
当我将它添加到我的项目父 pom 时:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
项目运行失败,如下所示:
2019-11-11 00:12:56.158 INFO 78547 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-11-11 00:12:56.421 INFO 78547 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$684316fc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-11 00:12:56.436 WARN 78547 --- [ restartedMain] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with …Run Code Online (Sandbox Code Playgroud) 我正在使用Ribbon Load Balancer处理Spring Boot Eureka客户端应用程序.
我有两个服务器在Eureka注册,名称为"TEST".在客户端,我有以下代码从Eureka获取服务器.
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableEurekaClient
@RestController
public class EurekaConsumerApplication {
@Autowired
DiscoveryClient discoveryClient;
@Autowired
RestTemplate restTemplate;
@RequestMapping(value = "/",method = RequestMethod.GET)
String consumer(){
InstanceInfo instance = discoveryClient.getNextServerFromEureka("TEST", false);
URI uri = UriComponentsBuilder.fromUriString(instance.getHomePageUrl() + "baseDir")
.build()
.toUri();
String baseDir = restTemplate.getForObject(uri, String.class);
return baseDir;
}
public static void main(String[] args) {
SpringApplication.run(EurekaConsumerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
application.yml
spring:
application:
name: consumer
info:
component: Consumer to fetch configuration
server:
port: 8090
eureka:
instance:
leaseRenewalIntervalInSeconds: 3
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}} …Run Code Online (Sandbox Code Playgroud) resttemplate spring-boot spring-cloud netflix-eureka netflix-ribbon
使用Eureka Server运行配置服务器时,建议的配置是什么?Config Server应该是Eureka的客户吗?或者Eureka是否应该依赖Config Server属性进行配置?或者两个都好吗?
我正在使用spring cloud的eureka并假装在一些服务之间进行通信(比方说A和B).现在我喜欢单一测试单个服务的服务层(A).问题是,该服务(A)正在使用假装客户端来请求其他服务的一些信息(B).
在没有任何特殊配置的情况下运行unittes会引发以下异常:java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available server for client: service-b=>但我不希望任何服务器运行.
我的问题是:有没有办法嘲笑假装客户端,所以我可以在不运行eureka实例和服务(B)的情况下对我的服务(A)进行单元测试?
编辑:我最终为假装客户端创建了一个存根.存根被标记为主要组件,以强制spring在我的测试中实例化存根.
这是我提出的解决方案.
//the feign client
@FeignClient("user")
public interface UserClient {
UserEntity getUser();
}
//the implementation i use for the tests
@Component
@Primary //mark as primary implementation
public class UserClientTestImpl implements UserClient {
@Override public UserEntity getUser() {
return someKindOfUser;
}
}
Run Code Online (Sandbox Code Playgroud) 当我试图meeting通过Zuul网关到达服务时,Zuul无法将请求转发给相应的服务.以下错误是我面临的问题:
- nettflix.zuul.exception.ZuulException:转发错误
- 引起:com.netflix.client.ClientException:负载均衡器没有可用于客户端的服务器:会议
让我分享服务,eureka和zuul网关的application.yml.
EurekaClient:
Application.yml
server:
port: 8761
eureka:
instance:
hostname: localhost
lease-renewal-interval-in-seconds: 300
client:
register-with-eureka: false
fetch-registry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Run Code Online (Sandbox Code Playgroud)
ZuulGateWay:
application.yml
server:
port: 8085
spring:
application:
name: gatekeeper
zuul:
routes:
meeting: /meeting/**
serviceId: meeting
ribbon:
eureka:
enabled: false
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Run Code Online (Sandbox Code Playgroud)
ZuulGateWay: SpringBootApplication
package com.sagarp.gatekeeper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
public class MeetingApplication {
public static void main(String[] args) {
SpringApplication.run(MeetingApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我的服务类(会议): Application.yml …
如果Eureka客户端没有通过设置eureka: client: registerWithEureka: false向eureka服务器注册自己,为什么fetchRegistry属性也需要设置为false?
在过去的两天里,我一直试图找到一个奇怪的重定向问题,但没有成功.
基于spring-cloud示例项目,我已经配置了Eureka,Zuul以及在Zuul后面运行的基本服务.
我有以下方法;
@RequestMapping(method = RequestMethod.POST, value = "/register")
public String registerDevice(Principal principal, String response) {
// ...
return "redirect:/account";
}
Run Code Online (Sandbox Code Playgroud)
表单设置为发布到代理URL,如下所示;
POST https://localhost:8443/service/register
Run Code Online (Sandbox Code Playgroud)
(Zuul在localhost上运行:8443).
本地服务的URL(非代理)将是; HTTP://本地主机:9001 /寄存器
POST调用正确代理到上述方法,但是发送到浏览器的重定向位置是服务的非代理URL; HTTP://本地主机:9001 /帐户
Zuul代理肯定会发送正确的x-forwarded-*头文件,所以我希望Spring中的视图解析器能够根据x-forwarded值构建正确的重定向.
为了证明标头被正确发送,我重新配置了如下方法;
@RequestMapping(method = RequestMethod.POST, value = "/register")
public void registerDevice(Principal, String response, HttpServletResponse response) {
// ...
String rUrl = ServletUriComponentsBuilder.fromCurrentContextPath().path("/account").build().toUriString();
servletResponse.sendRedirect(rUrl);
}
Run Code Online (Sandbox Code Playgroud)
这正确地将浏览器重定向到代理位置; https://开头本地主机:8443 /服务/帐户
这是一个错误,还是预期的行为?我认为使用"redirect:"是为了纪念从代理传递的前向头.
spring-mvc spring-boot spring-cloud netflix-eureka netflix-zuul
DiscoveryClient_xxx:111-222:8080 - 无法刷新其缓存!状态 = 无法在任何已知服务器上执行请求:
我在我的本地主机上运行一个 spring 云应用程序。我用本地主机 eureka 注册。但是我得到了以下输出:
Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused
at
017-07-01 13:13:41 [DiscoveryClient-CacheRefreshExecutor-0] (DiscoveryClient.java:937) - Disable delta property : false
2017-07-01 13:13:41 [DiscoveryClient-CacheRefreshExecutor-0] (DiscoveryClient.java:938) - Single vip registry refresh property : null
2017-07-01 13:13:41 [DiscoveryClient-CacheRefreshExecutor-0] (DiscoveryClient.java:939) - Force full registry fetch : false
2017-07-01 13:13:41 [DiscoveryClient-CacheRefreshExecutor-0] (DiscoveryClient.java:940) - Application is null : false
2017-07-01 13:13:41 [DiscoveryClient-CacheRefreshExecutor-0] (DiscoveryClient.java:941) - Registered Applications size is zero : true
2017-07-01 13:13:41 [DiscoveryClient-CacheRefreshExecutor-0] (DiscoveryClient.java:943) - Application version …Run Code Online (Sandbox Code Playgroud) netflix-eureka ×10
spring-boot ×5
spring-cloud ×5
java ×4
netflix-zuul ×3
spring ×3
resttemplate ×1
spring-mvc ×1
unit-testing ×1