标签: netflix-eureka

使用 Spring boot 和 eureka 的 Resttemplate

我使用 spring-boot 和 eureka 客户端创建一个项目(我的 eureka 服务器中注册了另外 2 个项目),因此要访问我在应用程序中创建的其他 2 个项目,需要创建一个 RestTemplate,如下所示:

@Bean
@LoadBalanced
public RestTemplate restTemplate() {
    return new RestTemplate();
}
Run Code Online (Sandbox Code Playgroud)

所以,现在当我尝试访问我的一个项目时,我只输入“ http://my-project1/ ”或“ http://my-project2/ ”的url,然后尤里卡服务器为我解析该url。

但现在我需要从我的范围之外调用休息(例如邮政编码服务),所以如果我输入:

return restTemplate.getForObject("https://viacep.com.br/ws/11380120/json", String.class);
Run Code Online (Sandbox Code Playgroud)

不起作用,因为 viacep.com 不在我的范围内,可以解决这个问题吗?

spring-boot netflix-eureka

1
推荐指数
1
解决办法
7247
查看次数

中间层负载均衡是什么意思?

当我遇到这个术语时,我正在阅读关于 Eureka 的文章https://github.com/Netflix/eureka/wiki/Eureka-at-a-glance#how- Different-is-eureka-from-aws-elb 。也很困惑该段落的含义(EC2 classic 和 AWS 安全组)。它说

AWS Elastic Load Balancer 是一种负载均衡解决方案,适用于暴露给最终用户 Web 流量的边缘服务。Eureka 满足了中间层负载均衡的需求。虽然理论上您可以将中间层服务放在 AWS ELB 后面,但在 EC2 classic 中,您将它们暴露给外界,从而失去了 AWS 安全组的所有用处。

我对微服务架构完全陌生,并且从我能找到的来源阅读文章。任何帮助都会有帮助!

amazon-web-services microservices netflix-eureka

1
推荐指数
1
解决办法
893
查看次数

使用 Spring Boot 和 Eureka Server 时如何修复错误 java.net.UnknownHostException?

我有一个名为“documents-microservice”的 Spring Boot 微服务,它在 Eureka Server 中注册。我尝试使用 URL 中的名称和 with 来访问此微服务RestTemplate,如下所示:

ResponseEntity<String> response =    restTemplate.exchange("http://documents-microservice/document-name", HttpMethod.POST, entity, String.class);
Run Code Online (Sandbox Code Playgroud)

尽管我确信该服务名称在运行在端口 8761 上的 Eureka Server 上可用(见下图),但我仍然收到以下错误:

尤里卡服务器运行

错误:

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://documents-microservice/document-name": documents-microservice; nested exception is java.net.UnknownHostException: documents-microservice
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:674)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:621)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:539)
    at ae.gov.adm.saeed.web.controller.util.CircularsControllerUtil.circularListView(CircularsControllerUtil.java:196)
    at ae.gov.adm.saeed.web.controller.CircularsController.viewCircularList(CircularsController.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) …
Run Code Online (Sandbox Code Playgroud)

java post resttemplate spring-boot netflix-eureka

1
推荐指数
1
解决办法
2万
查看次数

如何解决 Spring Boot 3.2.0 和 java 17 中的 netflix eureka 客户端错误

我正在尝试使用 java 17 在新的 spring boot 3.2.0 应用程序中配置 eureka 客户端,并在运行时出现以下错误。

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Unsatisfied dependency expressed through method 'eurekaClient' parameter 3: No qualifying bean of type 'com.netflix.discovery.shared.transport.jersey.TransportClientFactories<?>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我正在使用下面的 Maven 依赖项,没有其他配置。

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
   <version>4.1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

请注意,如果我删除此依赖项,我不会看到任何错误。\

主班

@SpringBootApplication
public class SpringBoot3Java17Application {

    public static void main(String[] args) {
        SpringApplication.run(CommissionManagerApplication.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)

application.properties:(并且还需要应用程序如何跟踪本地运行的尤里卡服务器的帮助)

eureka.client.service-url.defaultZone=http://admin:alined@localhost:8761/eureka/
Run Code Online (Sandbox Code Playgroud)

应用程序已启动但未向 Eureka …

java spring-boot netflix-eureka

1
推荐指数
1
解决办法
1225
查看次数

使用eureka服务时的Zuul路由

我有一个相当简单的Spring Cloud Netflix设置.我们使用Zuul作为反向代理,使用Eureka进行服务发现和注册.我们有遗留服务,我们正在慢慢窒息.我们有许多简单的服务,其端点配置如下:

{host}:{port}/{service-name}/**
Run Code Online (Sandbox Code Playgroud)

所以现在当每个服务都在eureka注册,并且随后有一条添加到Zuul的路由时,zuul端点如下所示:

{zuul-host}:{zuul-port}/{service-name}/{service-name}/**
Run Code Online (Sandbox Code Playgroud)

我想阻止Zuul从eureka服务的路由URI中删除前缀,以便我的zuul端点看起来像这样:

{zuul-host}:{zuul-port}/{service-name}/**
Run Code Online (Sandbox Code Playgroud)

并转发到:

{zuul-host}:{zuul-port}/{service-name}/** 
Run Code Online (Sandbox Code Playgroud)

我希望这样做,以便我不必为每个服务添加配置.

我本以为zuul.strip-prefix可以做到这一点,但事实并非如此.

当前Zuul application.yml:

zuul:
  routes:
    oldservice:
      path: /oldservice/**
      url: http://oldservice-host:9080/api/v1/oldservice
  strip-prefix: false
eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-host:8761/eureka/
Run Code Online (Sandbox Code Playgroud)

有人建议我如何以这种方式配置zuul?

routing spring-boot netflix-eureka netflix-zuul spring-cloud-netflix

0
推荐指数
1
解决办法
4199
查看次数

当 Eureka Client 与 Spring Cloud 中启用 SSL 的 Eureka Server 连接时,PKIX 路径构建失败

我正在使用 spring boot 构建基于云的微服务架构。我们只使用嵌入式容器,它是用于 spring boot 的 tomcat。此外,我们还向 jvm 密钥库添加了证书。

为了使它更简单,我只创建了两个 Spring Boot 应用程序。

1) Spring boot Eureka Server
2) Spring boot Eureka client

两者都具有与上述相同的配置,当我在 https 上启动 Eureka 服务器时,它成功启动而没有任何问题,之后我启动了 Eureka 客户端,运行良好,直到它请求注册到 Eureka 服务器,然后它开始失败。

有趣的是,当我将 Eureka 服务器保持在非安全端口上,即保持在 http 上时,我所有启用 ssl 的 eureka 客户端都可以毫无问题地连接,但我的架构中并不真正需要它,因为我也使用 zuul 作为单个入口点我所有的微服务。

当它是 http 时一切正常,但在启用 https 和 SSL 时它开始失败。

这是我的 Eureka 服务器配置。

eureka.instance.hostname= localhost
eureka.client.registerWithEureka= false
eureka.client.fetchRegistry= false
server.port= 8761

server.ssl.enabled = true
server.ssl.key-store=classpath:ssl.keystore
server.ssl.key-store-password=changeit

and my Eureka Client Configuration.
server.port=8181
spring.application.name=my-client
eureka.instance.hostname=localhost
eureka.instance.securePort = 8181
eureka.instance.securePortEnabled = …
Run Code Online (Sandbox Code Playgroud)

ssl-certificate spring-boot spring-cloud netflix-eureka spring-cloud-netflix

0
推荐指数
1
解决办法
2293
查看次数

使用 feign 客户端调用 rest 失败时不会调用回退方法

我正在尝试使用 Feign 客户端实现回退,但没有成功。这是一个最简单的代码,请在下面找到。

主类

@SpringBootApplication
@EnableDiscoveryClient
@RestController
@EnableFeignClients
public class EurekaClient1Application {

    @Autowired
    public DiscoveryClient discoveryClient;

    public static void main(String[] args) {
        SpringApplication.run(EurekaClient1Application.class, args);
    }

    @Autowired 
    FeingInterface feingInterface;




    @GetMapping("/hi/{name}")
    public String test(@PathVariable String name)
    {
        String h = feingInterface.test(name);

        return h;
    }
}
Run Code Online (Sandbox Code Playgroud)

Feign 接口

@FeignClient(name="client22",fallback=FallBack.class)
public interface FeingInterface {

    @GetMapping("/hiname/{name}")
    public String test(@PathVariable("name") String name);

}
Run Code Online (Sandbox Code Playgroud)

回退类

@Component
class FallBack implements FeingInterface{

    @Override
    public String test(String name) {
        // TODO Auto-generated method stub
        return "fall back methord being called"; …
Run Code Online (Sandbox Code Playgroud)

microservices netflix-feign netflix-eureka spring-cloud-feign feign

0
推荐指数
1
解决办法
1705
查看次数

WebServerException:无法启动嵌入式Tomcat | Spring Boot Eureka Server

在使用spring学习spring MVC的同时,我尝试使用教程创建一个Eureka客户端和服务器,它是一个简单的教程,带有客户端和服务器主类,只需注释并添加应用程序属性.但即使遵循教程,应用程序也不会运行tomcat.我仍然可以在本地服务器上使用tomcat运行我在spring boot中完成的其他项目.我遵循的教程是, https://dzone.com/articles/microservice-spring-cloud-eureka-server-configurat


2018-08-06 18:18:33.710  INFO 17919 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2018-08-06 18:18:33.810  INFO 17919 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2018-08-06 18:18:33.810  WARN 17919 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/tuto-server/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
2018-08-06 18:18:33.811  INFO 17919 …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-boot netflix-eureka

0
推荐指数
1
解决办法
3434
查看次数

使用Zuul和Eureka自动配置路由

通过阅读各种书籍/教程,似乎可以在将Zuul与Eureka服务发现结合使用时自动配置Zuul中的路由。这意味着我不必显式添加到Zull的application.properties的路由。

所以我理解正确吗?还是我仍然需要显式添加路由到Zuul才能使其充当网关?

我希望它根据在Eureka中注册的应用程序名称自动创建路由。这可能吗?

(注意:我实际上已经尝试过了,但是当我转到http:// localhost:8762 / routes时,我只会看到一个错误页面。)

spring-boot netflix-eureka netflix-zuul

0
推荐指数
1
解决办法
1346
查看次数

Netflix尤里卡客户端微服务未注册尤里卡服务器

我正在尝试向尤里卡服务器注册我的微服务。但它显示浏览器中没有可用的实例。我在控制台中没有收到任何错误。请帮我解决这个问题。

我已经通过在谷歌上搜索尝试了多种选择。尽管如此,我还是无法解决这个问题。

微服务应用程序.properties

  spring.application.name=jecreations-core
  eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
  eureka.client.register-with-eureka=true
Run Code Online (Sandbox Code Playgroud)

客户端主类

 @EnableEurekaClient
 @SpringBootApplication
 @EnableConfigurationProperties(ImageProperties.class)
 public class JecreationsApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
    SpringApplication.run(JecreationsApplication.class, args);
}
 }
Run Code Online (Sandbox Code Playgroud)

Eureka Server application.properties

   eureka.client.register-with-eureka=false
   eureka.client.fetch-registry=false
   server.port=8761
   spring.application.name=DiscoveryServer
Run Code Online (Sandbox Code Playgroud)

Eureka 服务器主类。

 @SpringBootApplication
 @EnableEurekaServer
 public class JeeurekaApplication extends SpringBootServletInitializer{

public static void main(String[] args) {
    SpringApplication.run(JeeurekaApplication.class, args);
}

}
Run Code Online (Sandbox Code Playgroud)

java spring-boot netflix-eureka

0
推荐指数
1
解决办法
3792
查看次数