当前位置: 首页 > news >正文

厦门市机场建设招投标网站sw网站建设

厦门市机场建设招投标网站,sw网站建设,东莞阳光网官网投诉中心,如果做vr参观网站本教程是关于Spring云Netflix Eureka的。 在这里#xff0c;我们将创建eureka发现服务器和微服务#xff0c;这些服务本身将注册到发现服务器和使用netflix客户端API的客户端中#xff0c;以使用示例示例来发现服务并使用该服务公开的微服务。因此#xff0c;我们将开发每个… 本教程是关于Spring云Netflix Eureka的。 在这里我们将创建eureka发现服务器和微服务这些服务本身将注册到发现服务器和使用netflix客户端API的客户端中以使用示例示例来发现服务并使用该服务公开的微服务。因此我们将开发每个发现服务器服务和客户端的3个不同的spring boot应用程序。此外我们还将研究默认的eureka仪表板和该仪表板中可用的各种有用信息。 Spring Cloud Netflix使用简单的基于注释的配置为Spring Boot应用程序提供Netflix OSS集成。现在是时候创建微服务而不是批量应用程序并将这些微服务部署到云了。 在这种体系结构中服务发现是关键原则之一服务发现可根据需要自动创建多个实例并提供微服务的高可用性这里我们将使用Eureka作为Netflix服务发现服务器和客户端。 Spring Cloud Eureka发现服务器 发现服务器是所有可用服务的注册表。不同的服务可以在此服务器上进行注册和注销。使用spring boot实施eureka发现服务器非常简单。 为此首先我们将创建一个具有start.spring.io以下依赖项的spring boot应用程序并将其导入我们的IDE中。 这带来了以下Maven依赖关系。启用Spring Cloud所需的依赖关系是spring-cloud-dependencies。 pom.xml dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdpring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-eureka-server/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependenciesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring-cloud.version}/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagement 并且我们在application.properties定义了以下属性。在这里spring.application.name提供了此服务的唯一标识符。在启动发现服务器时它将尝试向其对等发现服务器注册以获得我们没有的高可用性本教程。我们没有发现服务器的多个实例。因此eureka.client.register-with-eureka设置为false。 同样我们具有eureka.client.fetch-registry属性该属性指示此客户端是否应从eureka服务器获取eureka注册信息。 并且server.port定义了我们的发现服务器将在其上运行的端口。 spring.application.namediscovery-server eureka.client.register-with-eurekafalse eureka.client.fetch-registryfalse server.port8761 现在让我们定义我们的DiscoveryServerApplication。 EnableEurekaServer将启用eureka服务器配置。 当我们将此类作为Java程序运行时它将在http// localhost8761 / eureka /处添加新的对等节点并且我们的微服务将调用该URL进行自身注册。 DiscoveryServerApplication.java package com.devglan.discoveryserver;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;EnableEurekaServer SpringBootApplication public class DiscoveryServerApplication {public static void main(String[] args) {SpringApplication.run(DiscoveryServerApplication.class, args);} } 发现服务器就是这样。 我们的发现服务器已准备就绪可以接受来自http// localhost8761 / eureka上任何服务的注册请求。 Spring Cloud Eureka服务 发现服务器准备就绪后现在让我们创建微服务 。 同样这将是spring boot app我们将使用spring boot starter下载示例项目。 这是pom文件。 pom.xml dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-eureka/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependenciesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring-cloud.version}/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagement 该模块将充当微服务并在启动时将其自身注册到发现服务器。为此注册我们需要在application.properties配置有关发现服务器的信息。下面是entrys.spring.application.name是唯一标识符对于此服务eureka.client.service-url.defaultZone是服务光盘服务器的URL。 spring.application.nameeureka-service eureka.client.service-url.defaultZonehttp://localhost:8761/eureka server.port8085 要将此应用程序配置为eureka服务和发现服务器的客户端我们需要使用EnableDiscoveryClient注释我们的spring boot应用程序 package com.devglan.eurekaservice;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;EnableDiscoveryClient SpringBootApplication public class EurekaServiceApplication {public static void main(String[] args) {SpringApplication.run(EurekaServiceApplication.class, args);} } 以下是控制器类我们在其中为客户端应用程序公开了微服务。 GreetingController.java package com.devglan.eurekaservice.controller;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;RestController public class GreetingController {GetMapping(/)public String greeting(){return Hello from ;}}Spring Cloud Eureka客户端 现在是时候定义我们的客户了为此我们将再次使用spring starter生成以下项目。 该客户端将与eureka服务发现服务器进行交互并使用eureka客户端发现服务然后使用上面我们的服务实现公开的微服务。以下是示例pom.xml文件。 pom.xml dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-eureka/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependenciesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring-cloud.version}/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagement application.properties文件中需要以下条目。 由于这是一个客户项目因此我们不希望它注册到发现服务器。 但是在某些情况下应用程序既可以是客户端又可以是服务器。在这种情况下eureka.client.register-with-eureka将为真。 application.properties spring.application.nameeureka-client eureka.client.service-url.defaultZonehttp://localhost:8761/eureka eureka.client.register-with-eurekafalse 以下是我们的Application类。 它带有EnableDiscoveryClient注释以将该应用程序注册为发现客户端。 package com.devglan.eurekaclient;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;EnableDiscoveryClient SpringBootApplication public class EurekaClientApplication {public static void main(String[] args) {SpringApplication.run(EurekaClientApplication.class, args);} } 现在我们将定义控制器它将在根级别公开一个API。 这个API将从发现服务器发现服务并调用服务。在这里我们已经自动连接了eureka客户端并且getNextServerFromEureka接受两个参数。 第一个参数是微服务应用程序的服务标识符。 我们上面的服务实现已使用名称为eureka-service的发现客户端注册了自己并且eureka客户端应用程序将使用相同的名称来发现服务。 一旦发现该服务客户端将调用微服务。记住我们在上面的服务实现中公开了一个greeting API并且客户端将调用相同的API。 ClientController.java package com.devglan.eurekaclient.controller;import com.netflix.appinfo.InstanceInfo; import com.netflix.discovery.EurekaClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate;RestController public class ClientController {Autowiredprivate EurekaClient eurekaClient;Autowiredprivate RestTemplateBuilder restTemplateBuilder;GetMapping(/)public String invokeService(){RestTemplate restTemplate restTemplateBuilder.build();InstanceInfo instanceInfo eurekaClient.getNextServerFromEureka(eureka-service, false);String serviceBaseUrl instanceInfo.getHomePageUrl();return restTemplate.getForObject(serviceBaseUrl, String.class);} }测试应用 要测试应用程序请首先启动发现服务器。 为此我们需要将DiscoveryServerApplication.java作为Java应用程序运行。 您可以检查控制台并找到类似的日志如下所示。 您还可以在发现服务器公开的控制台中看到URL http// localhost8761 / eureka / 以注册服务。 现在启动服务将EurekaServiceApplication.java作为Java应用程序运行。 您还可以运行该服务的多个实例。所有实例都将在发现服务器中注册。成功注册该服务后您将从发现客户端获得204响应。 现在以类似的方式通过将EurekaClientApplication.java作为Java应用程序运行EurekaClientApplication.java启动客户端。 现在从URL上输入URL http// localhost8080 从eureka服务应用程序中以Hello的形式检查字符串响应。 Spring Cloud Eureka仪表板 您可能已经在发现服务器实现中的application.properties文件中注意到我们配置的端口为8761。在该端口上Spring cloud eureka提供了一个默认启用的仪表板该仪表板显示有用的元数据和服务状态。在这里我们可以检查关于发现服务器副本的信息在本例中为1该副本在localhost上运行。类似地我们还具有关于发现服务器的注册服务的信息以及当前状态。 结论 在本教程中我们了解了Spring Cloud netflix eureka的实现。 我们实现了发现服务器应用程序服务和应用程序客户端。可以从此处下载源。如果您有任何要添加或共享的内容请在下面的评论部分中共享。 翻译自: https://www.javacodegeeks.com/2018/03/spring-cloud-netflix-eureka.html
http://www.zqtcl.cn/news/967205/

相关文章:

  • 域名和网站一样吗自己开发小程序要多少钱
  • 咨询公司网站源码手机优化软件哪个好用
  • 行业网站模板小型影视网站源码
  • 湖北网站建站系统哪家好微信小程序怎么注销账号
  • 温州网站推广公司沈阳网站建设服务电话
  • 2019年的阜南县建设修路网站洛阳哪里有做网站的
  • 家里电脑可以做网站服务器吗佛山网络公司哪家最好
  • 做网站属于无形资产还是费用网站制作二维码
  • ps为什么做不了视频网站最近做网站开发有前途没
  • 平面设计师参考网站做网站建设推广好做吗
  • 网站被别的域名绑定泰安做网站网络公司
  • 建设部网站业绩如何录入免费素材图片下载
  • 佛山美容网站建设如何有效的推广宣传
  • 网站全屏轮播怎么做nginx 代理 wordpress
  • 海淀公司网站搭建二级目录怎么做网站
  • 石家庄定制网站建设凡科建站做的网站收录慢吗
  • 海口企业自助建站品牌建设三年行动方案
  • 网站建设流程平台域名分析网站
  • 旅游类网站如何做推广随机网站生成器
  • 竖导航网站做网站被坑
  • 散文古诗网站建设目标做公司网站要钱吗
  • 营销网站建设规划小浪底水利枢纽建设管理局网站
  • 建站的目的网站的月度流量统计报告怎么做
  • 网站备案添加域名拼多多代运营公司十大排名
  • 网站访客qq获取系统 报价客户管理系统入口
  • 院网站建设情况报告怎么在虚拟主机上建网站
  • 厦门网站建设系统鞍山百度网站怎么制作
  • html5建设网站app开发公司不退款该怎么投诉
  • 南昌网站建设公务手工制作代加工接单网
  • 排名好的手机网站建设你知道吗 网站