搭建完成服务注册中心,下一步可以创建服务提供者并向注册中心注册服务。

接下来我们创建Spring Boot 应用将其加入Eureka服务治理体系中去。

直接使用签名章节创建hello服务项目改造:

1. 添加Eureka服务治理依赖配置

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

2. 改造RestController服务接口的/hello服务

/**
* Created by Administrator on 2017/5/9.
*/ @RestController
public class HelloController { private final Logger log = Logger.getLogger(getClass()); @Autowired
private DiscoveryClient client; @RequestMapping(value = "/hello", method = RequestMethod.GET)
public String index(){ ServiceInstance instance = client.getLocalServiceInstance(); log.info("/hello, host:" + instance.getHost() + ", service_id:" + instance.getServiceId()); return "Hello World !";
} }

3. 激活Eureka 的DiscoveryClient实现,添加 @EnableDiscoveryClient 注解

@EnableDiscoveryClient
@SpringBootApplication
@ComponentScan("com.net263")
public class HelloworldApplication { public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
}

4. 配置application.properties 关键参数

# 指定应用名称
spring.application.name= hello-service # 构建服务中心的地址
eureka.client.serviceUrl.defaultZone= http://localhost:1111/eureka/

改造完毕,下面我们分别启动注册中心服务和提供服务者程序。启动成功后会打印如下日志信息说明注册服务成功。

也可以去服务注册中心信息面板去查看。

通过访问:http://wmlocal.263.net:8888/hello 向服务发起请求,在控制台中可以看到如下输出

Spring cloud Eureka 服务治理(注册服务提供者)的更多相关文章

  1. Spring cloud Eureka 服务治理(搭建服务注册中心)

    服务之类是微服务架构中最为核心的基础模块,它主要用来实现各个微服务实例的自动化注册和发现. 1. 服务注册 在服务治理框架中,通常会构建一个注册中心,每个服务单元向注册中心登记自己提供的服务,将主机. ...

  2. 1 Spring Cloud Eureka服务治理

    注:此随笔为读书笔记.<Spring Cloud微服务实战> 什么是微服务? 微服务是将一个原本独立的系统拆分成若干个小型服务(一般按照功能模块拆分),这些小型服务都在各自独立的进程中运行 ...

  3. 笔记:Spring Cloud Eureka 服务治理

    Spring Cloud Eureka 是 Spring Cloud Netflix 微服务套件的一部分,基于 Netflix Eureka 做了二次封装,主要负责完成微服务架构中的服务治理功能,服务 ...

  4. Spring Cloud Eureka 服务治理

    Spring Cloud Eureka 是 Spring Cloud Netflix 微服务套件的一部分,基于 Netflix Eureka 做了二次封装,主要负责完成微服务架构中的服务治理功能,服务 ...

  5. 1 Spring Cloud Eureka服务治理(上)

    注:此随笔为读书笔记.<Spring Cloud微服务实战>,想学习Spring Cloud的同伴们可以去看看此书,里面对源码有详细的解读. 什么是微服务? 微服务是将一个原本独立的系统拆 ...

  6. 1 Spring Cloud Eureka服务治理(下)

    注:此随笔为读书笔记.<Spring Cloud微服务实战> 上篇主要介绍了什么是微服务以及微服务治理的简单实现,如微服务注册中心的实现.微服务注册的实现.微服务的发现和消费的实现.微服务 ...

  7. Spring Cloud Eureka 服务治理机制

     服务提供者         服务提供者在启动的时候会通过发送REST请求的方式将自己注册到Eureka Server上,同时带上了自身服务的一些元数据信息.Eureka Server 接收到这个RE ...

  8. Spring cloud Eureka 服务治理(高可用服务中心)

    在微服务的架构中,我们考虑发生故障的情况,所以在生产环境中我们需要对服务中各个组件进行高可用部署. Eureka Server 的高可用实际上就是将自己作为服务想其它服务注册中心注册自己,这样就形成了 ...

  9. Spring Cloud (1) 服务的注册与发现(Eureka)

    Spring Cloud简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全 ...

随机推荐

  1. Add lombok to IntelliJ IDEA

    Lombok study link: https://www.jianshu.com/p/365ea41b3573 Add below dependency code to pom.xml <d ...

  2. Learning Python 006 list(列表) 和 tuple(元组)

    Python list(列表) 和 tuple(元组) list 列表 Python内置的一种数据结构.list:一种有序的集合,可以随时添加和删除其中的元素. list的用法 定义list > ...

  3. R: 关于 table 函数的应用

    ################################################### 问题:关于 table 函数   18.5.9 来一个关于 table 函数的例子,说明tabl ...

  4. 11.Weblogic-SSRF漏洞复现

    应为这一阵正好在学习SSRF漏洞,又苦于本人太菜没有挖到SSRF,只能复现... 先贴出很早之前央视网SSRF可窥探内网(Weblogic SSRF案例):https://www.secpulse.c ...

  5. vue中computed与methods的异同

    在vue.js中,有methods和computed两种方式来动态当作方法来用的 如下: 两种方式在这种情况下的结果是一样的 写法上的区别是computed计算属性的方式在用属性时不用加(),而met ...

  6. Go语言——没有对象的面向对象编程

    本文译自Steve Francia在OSCON 2014的一个PPT,原作请前往:https://spf13.com/presentation/go-for-object-oriented-progr ...

  7. filter、map、reduce区别

    1.filter filter(function,sequence)-->list,tuple or string 1)       参数func是自定义的过滤函数,在函数func(item)中 ...

  8. Linux中常用压缩命令

    .zip格式压缩 zip 压缩文件名 源文件 压缩文件 zip -r 压缩文件名 源目录 压缩目录 .zip格式解压缩 unzip 压缩文件 解压.zip文件 .gz格式压缩 gzip 源文件 压缩为 ...

  9. VS连接SQL Server数据库,增删改查详细教程(C#代码)_转载

    工具: 1.Visual Studio (我使用的是vs2013) 2.SQL Server  (我使用的是sql server2008) 操作: 1.打开SQL Server,打开后会看到数据库的初 ...

  10. ffmpeg转码多路输出(二)

    ffmpeg转码多路输出(二)本程序支持一路输入多路输出,可根据map配置自行添加,第1路为纯拷贝,其他2路经过编解码,格式转换缩放和重采样,纯拷贝方面不同格式适应方面还没做全,以后补充.本程序适合多 ...