Wi注册中心eureka技术站分享

2018-03-14
  • 1152
  • 0

1、config 配置文件

2、Controlle层为该原子服务层提供给聚合服务层调用的接口,不编写而任何业务逻辑代码。

 

3、job 定时任务

4、master 核心业务代码,原子业务逻辑模块(以下简称原子逻辑模块,举例User模块):

service:服务层,类名以Service为结尾(UserService),处理原子业务逻辑。

repository: jpa数据访问层,类名以Repository结尾(UserRepository),提供访问数据库的相关操作。

dao jdbctemplate 数据访问层

entity:持久化对象,类名以Entity结尾(UserEntity),继承BaseEntity。不建议在持久化对象进行数据处理,持久化对象不应该包含任何与数据库无关的属性和方法。

vo:视图对象,类名以VO结尾(UserVO),用作对外的vo对象。也称作视图对象。可以通过继承持久化对象拥有持久化对象的相关属性。

dto:数据传输对象,类名以DTO结尾(UserDTO),用作数据传输的对象。

bo:业务逻辑对象,类名以BO结尾(UserVO),封装相关业务逻辑,保证其对象的高内聚

query:查询条件对象,类名以Query结尾(UserQuery),封装相关查询条件的对象

constant:常量类,类名以Constant结尾(UserConstant)。

utils:工具类,类名以Utils结尾(UserUtils)。

 

 

依赖工具包 cloud-common ,cloud-database,cloud-grant

 

eureka服务治理是微服务架构中最为核心和基础的模块,它主要用来实现各个微服务实例的自动化注册和发现。Spring Cloud EurekaSpring Cloud Netflix微服套件中的一部分,它基于Netflix Eureka做了二次封装。主要负责完成微服架构中的服治理功能。

相关配置如下

spring:
    application:
        name: wi-eureka


server:
  port: 8761 #启动端口
  context-path: /
  tomcat.max-threads: 0
  tomcat.uri-encoding: UTF-8

# 安全认证的配置
security:
  basic:
    enabled: true # 开启基于HTTP basic的认证
  user:
    name: wi  # 配置登录的账号
    password: wi #配置登录的密码

#注册中心
eureka:
  datacenter: WI-Cloud   # 修改 http://localhost:8761 地址 Eureka 首页上面 System Status Data center 显示信息
  environment: dev         # 修改 http://localhost:8761 地址 Eureka 首页上面 System Status Environment 显示信息
  instance:
      hostname: 127.0.0.1
      #注册时使用ip而不是主机名
      preferIpAddress: true
      instance-id: ${spring.cloud.client.ipAddress}:${server.port}
#      注册服务慢的问题,修改心跳时间,便可解决此问题
      lease-renewal-interval-in-seconds: 5      # 心跳时间,即服务续约间隔时间(缺省为30s
      lease-expiration-duration-in-seconds: 15  # 发呆时间,即服务续约到期时间(缺省为90s
      metadata-map:
        instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}} #eureka instance 标识,需要唯一,如果不配置,多个节点最终只会有一个生效

  server:
        enable-self-preservation: false           # 关闭自我保护模式(缺省为打开)
        eviction-interval-timer-in-ms: 1000       # 续期时间,即扫描失效服务的间隔时间(缺省为60*1000ms
  client:
      registerWithEureka: false #当前服务(EurekaServer)不注册到Eureka
      fetchRegistry: false #此客户端是否从eureka注册表里读取注册表信息,默认为false
      serviceUrl:
#        defaultZone: http://${security.user.name}:${security.user.password}@127.0.0.1:${server.port}/eureka
        defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      healthcheck:
          enabled: true #使用health端点来代替心跳表明服务是否可用,反应到eureka server ui上服务的UP还是DOWN (依赖spring-boot-starter-actuator

 

zuul网关控制

spring:
    application:
        name: wi-zuul

server:
  port: 8769 #启动端口
  context-path: /
  tomcat.max-threads: 0
  tomcat.uri-encoding: UTF-8



zuul:
  host:
    connect-timeout-millis: 10000   # 与微服务通信的时间
    socket-timeout-millis: 6000
  routes:                           #  如果有 ignored-services: '*'配置,那么这就是指定的微服务了
    microserver-consumer-movie-ribbon-hystrix: /movie/**  # 这样设置microserver-consumer-movie-ribbon-hystrix就会被映射到 /movie/**路径下
    wi-eureka:                     # 只是给定一个路由名称而已,可以任意起
#      service-id: wi-eureka
      path: /eureka/**                # service-id对应的路径
      url: http://wi:wi@127.0.0.1:8761/



#注册中心
eureka:
  instance:
      #注册时使用ip而不是主机名
      preferIpAddress: true
      instance-id: ${spring.cloud.client.ipAddress}:${server.port}
#      注册服务慢的问题,修改心跳时间,便可解决此问题
      lease-renewal-interval-in-seconds: 5      # 心跳时间,即服务续约间隔时间(缺省为30s
      lease-expiration-duration-in-seconds: 15  # 发呆时间,即服务续约到期时间(缺省为90s
      metadata-map:
        instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}} #eureka instance 标识,需要唯一,如果不配置,多个节点最终只会有一个生效
  client:
#      registerWithEureka: false #当前服务(EurekaServer)不注册到Eureka
#      fetchRegistry: false #此客户端是否从eureka注册表里读取注册表信息,默认为false
      serviceUrl:
        defaultZone: http://wi:wi@127.0.0.1:8761/eureka/
      healthcheck:
          enabled: true #使用health端点来代替心跳表明服务是否可用,反应到eureka server ui上服务的UP还是DOWN (依赖spring-boot-starter-actuator

 

搭建之后用服务化调用,集群方式管理,后端监控,消息通知,