分布式微服务的配置

1、提供者(接口实现方)

server:
    #端口
    port: 8070
    timeout: 30000 #超时时间,毫秒。默认30秒
    tomcat:
        uri-encoding: UTF-8 #默认编码
        max-threads: 400 #同时处理的任务个数,默认值为200
        accept-count: 800 #当同时处理的任务个数达到max-threads后,允许的排队个数
        max-connections: 10000 #tomcat允许建立的socket连接数,默认10000

spring:
    application:
        #应用名称,对用注册中心的serviceId
        name: simple-provider
   #数据源
    datasource:
        name: ${spring.application.name}
        url: jdbc:mysql://135.32.32.42:3306/example?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&useSSL=false
        username: root
        password: root
        #Mysql驱动
        driver-class-name: com.mysql.jdbc.Driver
        #下面是阿里开源数据库连接池的配置:
        #初始化连接池数量
        initialSize: 5
        #最小连接池数量
        minIdle: 5
        #最大连接池数量
        maxActive: 10
        #获取连接时最大等待时间,单位毫秒。配置了maxWait之后,缺省启用公平锁,并发效率会有所下降, 
        #如果需要可以通过配置useUnfairLock属性为true使用非公平锁。
        maxWait: 30000
        #多久检查一次空闲连接,如果空闲时间超过minEvictableIdleTimeMillis就销毁
        timeBetweenEvictionRunsMillis: 600000
        #池中的连接空闲多久后被回收,单位是毫秒
        minEvictableIdleTimeMillis: 1800000
        #用来检测连接是否有效的sql,要求是一个查询语句。
        #如果validationQuery为null,testOnBorrow、testOnReturn、 
        #testWhileIdle都不会起作用。
        validationQuery: select 1
        #建议配置为true,不影响性能,并且保证安全性。
        #申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis, 
        #就执行validationQuery检测连接是否有效。如果检测失败,则连接将被从池中去除
        testWhileIdle: true
        #false表示每次从连接池中取出连接时,不需要执行validationQuery进行测试
        #若配置为true,对性能有非常大的影响,性能会下降7-10倍
        testOnBorrow: false
        #归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
        testOnReturn: false
        #是否缓存preparedStatement,也就是PSCache。 
        #PSCache对支持游标的数据库性能提升巨大,比如说oracle。
        #在mysql5.5以下的版本中没有PSCache功能,建议关闭掉。
        #作者在5.5版本中使用PSCache,通过监控界面发现PSCache有缓存命中率记录,
        #该应该是支持PSCache。
        poolPreparedStatements: true
        #要启用PSCache,必须配置大于0,当大于0时
        #poolPreparedStatements自动触发修改为true。 
        #在Druid中, 不会存在Oracle下PSCache占用内存过多的问题, 
        #可以把这个数值配置大一些,比如说100
        maxOpenPreparedStatements: 100
        #属性类型是字符串,通过别名的方式配置扩展插件, 
        #常用的插件有: 监控统计用的filter:stat、日志用的filter:log4j、防御sql注入的filter:wall
        filters: stat

    #json格式,处理日期类型
    jackson:
        date-format: yyyy-MM-dd HH:mm:ss
        time-zone: GMT+8

    #日志收集集成ELK
    logstash:
        #logstash地址
        destination: 136.35.52.42:4569

#服务治理
eureka:
    #客户端
    client:
        #健康检查
        healthcheck:
            #是否开启健康检查
            enabled: true
        #注册中心地址
        serviceUrl:
            #默认地址
            defaultZone: http://registry-local.dasd.io/eureka/
    #实例配置
    instance:
        #发呆时间,即服务续约到期时间(缺省为90s)
        #Eureka服务器在接收到实例的最后一次发出的心跳后,需要等待多久才可以将此实例删除
        lease-expiration-duration-in-seconds: 9
        #表示eureka client发送心跳给server端的频率,默认为30 秒
        #如果在lease-expiration-duration-in-seconds后, server端没有收到client的心跳,则将摘除该instance
        #除此之外,如果该instance实现了HealthCheckCallback,并决定让自己unavailable的话,则该instance也不会接收到流量
        lease-renewal-interval-in-seconds: 3
        #指定用ip访问而不是用主机名
        prefer-ip-address: true
        #指定真实的ip地址
        ip-address: ${spring.cloud.client.ipAddress}
        #指定在注册中心Status列显示的信息
        instance-id: ${eureka.instance.ip-address}:${server.port}:${spring.application.name}

# 纯提供方不使用统一异常处理,有异常就跑出去,让消费方处理
#exception:
#    center:
#        open: true

#feign配置
feign:
    hystrix:
        #feign开启服务监控,容错保护
        enabled: true

#服务保护配置
hystrix:  
    command:
        default:
            execution:
                isolation:
                    thread:
                        #调用服务超时时间, 毫秒
                        timeoutInMilliseconds: ${server.timeout}

#客户端负载均衡调用配置
ribbon:
    #读取超时时间, 毫秒
    ReadTimeout: ${server.timeout}
    #调用服务超时时间, 毫秒
    ConnectTimeout: ${server.timeout}

2、消费者(接口调用方)

server:
    #端口
    port: 8071
    timeout: 30000 #超时时间,毫秒。默认30秒
    tomcat:
        uri-encoding: UTF-8 #默认编码
        max-threads: 400 #同时处理的任务个数,默认值为200
        accept-count: 800 #当同时处理的任务个数达到max-threads后,允许的排队个数
        max-connections: 10000 #tomcat允许建立的socket连接数,默认10000

spring:
    application:
        #应用名称,对用注册中心的serviceId
        name: simple-consumer
    #日志收集集成ELK
    logstash:
        #logstash地址
        destination: 136.35.52.42:4569
    #json格式,处理日期类型
    jackson:
        date-format: yyyy-MM-dd HH:mm:ss
        time-zone: GMT+8
#服务治理
eureka:
    #客户端
    client:
        #健康检查
        healthcheck:
            #是否开启健康检查
            enabled: true
        #注册中心地址
        serviceUrl:
            #默认地址
            defaultZone: http://registry-local.dads.io/eureka/
    #实例配置
    instance:
        #发呆时间,即服务续约到期时间(缺省为90s)
        #Eureka服务器在接收到实例的最后一次发出的心跳后,需要等待多久才可以将此实例删除
        lease-expiration-duration-in-seconds: 9
        #表示eureka client发送心跳给server端的频率,默认为30 秒
        #如果在lease-expiration-duration-in-seconds后, server端没有收到client的心跳,则将摘除该instance
        #除此之外,如果该instance实现了HealthCheckCallback,并决定让自己unavailable的话,则该instance也不会接收到流量
        lease-renewal-interval-in-seconds: 3
        #指定用ip访问而不是用主机名
        prefer-ip-address: true
        #指定真实的ip地址
        ip-address: ${spring.cloud.client.ipAddress}
        #指定在注册中心Status列显示的信息
        instance-id: ${eureka.instance.ip-address}:${server.port}:${spring.application.name}

#开启异常中心记录异常信息
exception:
    center:
        open: true

#feign配置
feign:
    hystrix:
        #feign开启服务监控,容错保护
        enabled: true

#服务保护配置
hystrix:  
    command:
        default:
            execution:
                isolation:
                    thread:
                        #调用服务超时时间, 毫秒
                        timeoutInMilliseconds: ${server.timeout}

#客户端负载均衡调用配置
ribbon:
    #读取超时时间, 毫秒
    ReadTimeout: ${server.timeout}
    #调用服务超时时间, 毫秒
    ConnectTimeout: ${server.timeout}

  

posted @ 2019-02-15 11:11  Andrew_F  阅读(858)  评论(0编辑  收藏  举报