spring cloud alibaba实用攻略一 nacos配置

nacos配置

  • 一、 本机yml文件
    • bootstrap.yml
    • bootstrap-dev.yml
  • 二、 常用nacos中心yml文件
    • datasource-dev.yml
    • mybatis-dev.yml
    • pagehelper-dev.yml
    • redis-dev.yml
    • jackson-dev.yml
    • feign-dev.yml
    • async-pool-dev.yml
    • rocketmq-dev.yml
    • ibmmq-dev.yml

今天起总结一年来使用springcloudalibaba整套框架的心得与最佳实践,第一天先总结nacos配置最佳实践

一、 本机yml文件

bootstrap.yml

spring:
  profiles:
    active: dev
    可以多重环境配置,通过后缀来区分(dev/prod/test),
    如开发环境 命名为bootstrap-dev.yml

bootstrap-dev.yml

server:
 port: 5003 #指定服务运行的端口

spring:
 application:
   name: 服务名称

 cloud:
   nacos:
     discovery:
       namespace: 2b671868-e2a3-4ea0-8050-d6fc67706674
       server-addr: #注册中心ip+端口地址
       cluster-name: #服务集群名  ps:Nacos支持集群配置。集群是对指定微服务的一种虚拟分类
       service: ${spring.application.name}
       ip: ${spring.cloud.client.ip-address} #获取服务运行的ip
       port: ${server.port}

     config:
       namespace: 2b671868-e2a3-4ea0-8050-d6fc67706674
       server-addr: #配置中心ip+端口地址
       cluster-name:  #服务集群名
       ext-config[0]: #配置在配置中心的分类配置
         group: ${spring.profiles.active}
         data-id: datasource-${spring.profiles.active}.yml
       ext-config[1]:
         group: ${spring.profiles.active}
         data-id: jackson-${spring.profiles.active}.yml
       ext-config[2]:
         group: ${spring.profiles.active}
         data-id: mybatis-${spring.profiles.active}.yml
       ext-config[3]:
         group: ${spring.profiles.active}
         data-id: pagehelper-${spring.profiles.active}.yml
       ext-config[4]:
         group: ${spring.profiles.active}
         data-id: transport-${spring.profiles.active}.yml
         refresh: true
       ext-config[5]:
         group: ${spring.profiles.active}
         data-id: rocketmq-${spring.profiles.active}.yml
       ext-config[6]:
         group: ${spring.profiles.active}
         data-id: rocketmq-queue-${spring.profiles.active}.yml
       ext-config[7]:
         group: ${spring.profiles.active}
         data-id: feign-${spring.profiles.active}.yml
       ext-config[8]:
         group: ${spring.profiles.active}
         data-id: async-pool-${spring.profiles.active}.yml
       ext-config[9]:
         group: ${spring.profiles.active}
         data-id: redis-${spring.profiles.active}.yml

二、 常用nacos中心yml文件

datasource-dev.yml

mysql版

spring:
  datasource:
    url: jdbc:mysql://ip:3306/mysql_dev?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true&useAffectedRows=true
    username: dev_user
    password: 1qaz!QAZ
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      initial-size: 5
      max-active: 10
      min-idle: 1
      max-wait: 60000
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      validation-query: SELECT 'x'
      test-on-borrow: false
      test-on-return: false
      test-while-idle: true
      timeBetweenEvictionRunsMillis: 60000
      min-evictable-idle-time-millis: 300000
      web-stat-filter:
        enabled: true
        url-pattern: /druid/*
      stat-view-servlet:
        enabled: true
        url-pattern: /druid/*
        reset-enable: true
        login-username: admin
        login-password: admin
        allow:
      filter:
        stat:
          enabled: true
          mergeSql: true
          log-slow-sql: true
          slow-sql-millis: 2000
        wall:
          enabled: true
          config:
            multi-statement-allow: false
        slf4j:
          statement-executable-sql-log-enable: true

oracle版

spring:
  datasource:
    url: jdbc:oracle:thin:@ip:1521:XE
    username: DEV_V3
    password: 1qaz!QAZ
    driver-class-name: oracle.jdbc.OracleDriver
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      initial-size: 5
      max-active: 10
      min-idle: 1
      max-wait: 60000
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      validation-query: SELECT 'x' FROM DUAL
      test-on-borrow: false
      test-on-return: false
      test-while-idle: true
      timeBetweenEvictionRunsMillis: 60000
      min-evictable-idle-time-millis: 300000
      web-stat-filter:
        enabled: true
        url-pattern: /druid/*
      stat-view-servlet:
        enabled: true
        url-pattern: /druid/*
        reset-enable: true
        login-username: admin
        login-password: admin
        allow:
      filter:
        stat:
          enabled: true
          mergeSql: true
          log-slow-sql: true
          slow-sql-millis: 2000
        wall:
          enabled: true
          config:
            multi-statement-allow: false
        slf4j:
          statement-executable-sql-log-enable: true

mybatis-dev.yml

mybatis:
  configuration:
    cache-enabled: true
    lazy-loading-enabled: true
    lazy-load-trigger-methods: equals,clone,hashCode,toString
    multiple-result-sets-enabled: true
    use-column-label: true
    use-generated-keys: false
    default-executor-type: simple
    default-statement-timeout: 6000
    safe-row-bounds-enabled: false
    map-underscore-to-camel-case: true
    local-cache-scope: session
    jdbc-type-for-null: other
  mapper-locations: classpath*:mybatis/mapper/*.xml

pagehelper-dev.yml

mysql版

pagehelper:
  helper-dialect: mysql
  reasonable: true
  params: count=countSql
  offset-as-page-num: true
  row-bounds-with-count: true
  support-methods-arguments: true

oracle版

pagehelper:
  helper-dialect: oracle
  reasonable: true
  params: count=countSql
  offset-as-page-num: true
  row-bounds-with-count: true
  support-methods-arguments: true

redis-dev.yml

spring:
  redis:
    host: 192.168.0.21
    port: 6377
    timeout: 3000ms
    jedis:
      pool:
        max-active: 8
        max-idle: 8
        min-idle: 1
        max-wait: -1ms

jackson-dev.yml

spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8

feign-dev.yml

spring.cloud.loadbalancer.retry.enabled: false
#feign.sentinel.enabled: true
feign.hystrix.enabled: true
feign.httpclient.enabled: false
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 10000
ribbon:ConnectTimeout: 9000
ribbon.ReadTimeout: 9000
ribbon.OkToRetryOnAllOperations: false
ribbon.MaxAutoRetriesNextServer: 0
ribbon.MaxAutoRetries: 0
ribbon.okhttp.enabled: true
management.endpoints.web.exposure.include: "*"

async-pool-dev.yml

用于支持默认线程池操作@Async

config:
  async:
    enabled: true
    core-pool-size: 2
    maximum-pool-size: 5
    queue-size: 1

rocketmq-dev.yml

rocketmq:
  name-server: ip:9876
  producer:
    group: ${spring.application.name}
    sendMessageTimeout: 3000
    compressMessageBodyThreshold: 4096
    retryTimesWhenSendFailed: 0
    retryTimesWhenSendAsyncFailed: 0
    retryNextServer: false
    maxMessageSize: 4194304

ibmmq-dev.yml

ibmmq:
  server:
    host: ip
    port: 1529
    username: MUSR_MQADMIN
    password: MUSR_MQADMIN
    queueManager: V3_QM
    channel: DATACENTER.SVC.CH
    receiveTimeout: 3000

你可能感兴趣的:(知识总结)