简体   繁体   English

如何设置 Eureka 命名服务而不是 RestTemplate?

[英]How to setup Eureka naming Service instead of RestTemplate?

I have developed 2 microservices in Spring:我在 Spring 中开发了 2 个微服务:

  • a UI-service一个 UI 服务
  • a Login-service, which also has UI (html-form) for testing一个登录服务,它也有用于测试的 UI (html-form)

The UI-service is consuming the Login-service using the below uri, now i want not to give the url but to use Eureka naming server here UI 服务正在使用以下 uri 使用登录服务,现在我不想提供 url 而是在这里使用 Eureka 命名服务器

UI-service (code) UI服务(代码)

  @RequestMapping("/log")
  public String abc(HttpServletRequest request) {
        final String uri = "http://localhost:8093/accounts/login"; 
       // want to use Eureka discovery instead of directly consuming this service.

         RestTemplate restTemplate = new RestTemplate();
         String result = restTemplate.getForObject(uri, String.class);

         return result;
        //request.setAttribute("mode", "MODE_LOGIN");
   }

initialise the Eureka client and fetch the registered apps:初始化 Eureka 客户端并获取注册的应用程序:

List<Application> applications = eurekaClient.getApplications().getRegisteredApplications();

    applications.stream()
            .forEach(application -> {
                application.getInstances().stream()
                        .forEach(instanceInfo -> {
              // get instanceInfo.getHostName() instanceInfo.getPort()
                        });
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Cloud Eureka - 如何模拟 RestTemplate 以避免对第二个服务的请求 - Spring Cloud Eureka - How to mock RestTemplate in order to avoid request to a second service 如何在OAuth2RestTemplate中使用Eureka名称 - How to use Eureka Names with OAuth2RestTemplate Eureka RestTemplate和SSL - Eureka RestTemplate and SSL 在 Ribbon Eureka 应用程序中使用 Java HTTP 客户端而不是 RestTemplate 发出 HTTP 请求 - Make HTTP request using Java HTTP client instead of RestTemplate in a Ribbon Eureka application 使用 RestTemplate 的尤里卡客户端的 UnknownHostException - UnknownHostException for Eureka Client using RestTemplate 如何配置 Eureka Client 和 Service 属性? - How to configure Eureka Client and Service properties? 如何使用Spring RestTemplate代替Apache Httpclient? - How to use Spring RestTemplate instead of Apache Httpclient? 如何在具有不同端口的反向代理后面设置尤里卡客户端? - How to setup eureka clients behind reverse proxy with different port? 如何为多个基本 URL 创建 RestTemplate 服务 - How to create RestTemplate service for multiple base URLs 如何设置域类以从RestTemplate获得我的答复? - How to setup a domain class to get my response from RestTemplate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM