spring-cloud 组件简单使用

原文地址: https://blog.csdn.net/qq_36666651/article/details/82728336

本文主要简单讲述了spring cloud组件简单集成的配置及代码(只有简单使用方法,没有原理之类的讲解)。

代码github地址:https://github.com/wkcaeser/spring-cloud-demo/tree/master

Netflix-eureka

eureka server

eureka server主要提供服务注册和发现的功能 
依赖:

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

配置文件:

spring:
  application:
    name: eurekaserver1
  profiles: peer1   # profiles名称, 启动时可通过spring.profiles.active=peer1来指定该配置文件
server:
  port: 8000
eureka:
  instance:
    hostname: peer1
    #Eureka实例的状态页面和健康指示器默认情况下分别用"/info"和"/health"代表
    statuspageUrlPath: ${management.context-path}/info}
    healthCheckUrlPath: ${management.context-path}/health}
  client:
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
    fetch-registry: true          # 是否从eureka server获取注册信息, 默认 true
    register-with-eureka: true    # 是否将自己注册到eureka server, 默认 true  

启动类上加上@EnableEurekaServer注解:

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}

------------------------------------------------------------------------------------------------------------

eureka-client

依赖:

 <dependency>
	<groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
 </dependency>

配置:

spring.application.name=eureka-client

server.port=9091

# 对外访问地址
eureka.instance.hostname=www.wk02.com
# 服务注册地址
eureka.client.service-url.defaultZone=http://www.wk01.com:9081/eureka/

------------------------------------------------------------------------------------------------------------

netflix-ribbon

 

------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# springcloud-zone #### 项目介绍 项目为学习用途搭建,主要包括以下模块: springcloud-register:服务注册中心 (eureka-server),提供服务注册与发现功能。 springcloud-config:远程配置中心,分为git与native两个版本,为producer提供远程配置。 springcloud-connect:数据连接中心,包含DB、Redis、MQ、Mail等组件的配置入口,只需其他模块在pom中添加依赖并提供相关配置即可快速接入。 springcloud-producer:服务提供者,包含具体的业务逻辑实现等。 springcloud-consumer:服务消费者,从eureka server中获取producer提供的服务。 springcloud-gateway:网关接口,暴露给调用方调用,包含负载均衡、重试、熔断等功能。 springcloud-zipkin:链路跟踪工具,监控并就持久化微服务集群中调用链路的通畅情况,采用rabbitmq异步传输、elasticsearch负责持久化的方式集成。 #### 软件架构 1、JDK:jdk-8u181-windows-x64。 2、MAVEN:apache-maven-3.5.4 3、IDE:spring-tool-suite-3.9.3.RELEASE-e4.7.3-win32-x86_64 4、springboot:1.5.10.RELEASE。 5、springcloud:Edgware.SR2版本 #### 安装教程 需要提前安装如下程序: 1、ActiveMQ。 2、RabbitMQ。 3、Redis 4、Elasticsearch。 5、Elasticsearch-head。 6、MYSQL(执行springcloud-producer目录src/main/resources/templates/datasource.text中的建表语句) #### 使用说明 项目运行顺序: 1、 springcloud-register, 2、 springcloud-config-native或者springcloud-config-git: 启动git远程配置中心需要修改springcloud-producer项目的bootstrap.yml配置文件,并将配置配件上传到git上。 3、springcloud-zipkin。 4、 springcloud-producer。 5、springcloud-consumer。 6、springcloud-gateway. 注: 在测试gateway负载均衡时可以启动单个项目的多个实例,具体方式如下: 1、项目启动类右键run as->run configurations..,打开配置框。 2、java application右键new,打开新建窗口。 3、顶部tab选中Main,在name中填写启动类名称,project中填写项目名称,main class中填写启动类详细路径+类名。 4、顶部tab选中Arguments,在VM arguments中填写-Dserver.port=端口号,比如-Dserver.port=8080 5、点击run即可以配置的端口号启动多个项目实例了。 #### 参与贡献 ningchongqing

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值