springcloud整合nacos、seata1.0.0踩坑之路

此博文不讨论业务出现问题,通过DEBUG自行处理,这里只发表配置问题


// 末尾含 undo_log.sql

1、io.seata.common.exception.FrameworkException: register error,role:RMROLE,err:cost 30008 ms

建议检查file.confconfig.DataSourceConfiguration类
这里提供两个文件的参考

# file.conf
transport {
  # tcp udt unix-domain-socket
  type = "TCP"
  #NIO NATIVE
  server = "NIO"
  #enable heartbeat
  heartbeat = true
  #thread factory for netty
  thread-factory {
    boss-thread-prefix = "NettyBoss"
    worker-thread-prefix = "NettyServerNIOWorker"
    server-executor-thread-prefix = "NettyServerBizHandler"
    share-boss-worker = false
    client-selector-thread-prefix = "NettyClientSelector"
    client-selector-thread-size = 1
    client-worker-thread-prefix = "NettyClientWorkerThread"
    # netty boss thread size,will not be used for UDT
    boss-thread-size = 1
    #auto default pin or 8
    worker-thread-size = 8
  }
  shutdown {
    # when destroy server, wait seconds
    wait = 3
  }
  serialization = "seata"
  compressor = "none"
}
service {
  #vgroup->rgroup
  ## 此处的my_tx_group 要与配置文件application.yml中的tx-service-group一致
  # spring:
  #  cloud:
  #    alibaba:
  #      seata:
   #        tx-service-group: my_tx_group
  vgroup_mapping.my_tx_group= "default"
  #only support single node
  default.grouplist = "127.0.0.1:8091"
  #degrade current not support
  enableDegrade = false
  #disable
  disable = false

  disableGlobalTransaction = false
  #unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent
  max.commit.retry.timeout = "-1"
  max.rollback.retry.timeout = "-1"
}

client {
  async.commit.buffer.limit = 10000
  lock {
    retry.internal = 10
    retry.times = 30
  }
  report.retry.count = 5
}

## transaction log store
store {
  ## store mode: file、db
  mode = "db"

  ## file store
  file {
    dir = "sessionStore"

    # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
    max-branch-session-size = 16384
    # globe session size , if exceeded throws exceptions
    max-global-session-size = 512
    # file buffer size , if exceeded allocate new buffer
    file-write-buffer-cache-size = 16384
    # when recover batch read size
    session.reload.read_size = 100
    # async, sync
    flush-disk-mode = async
  }

  ## database store
  db {
    ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
    datasource = "dbcp"
    ## mysql/oracle/h2/oceanbase etc.
    db-type = "mysql"
    url = "jdbc:mysql://localhost:3306/seata"
    user = "root"
    password = "password"
    min-conn = 1
    max-conn = 300
    global.table = "global_table"
    branch.table = "branch_table"
    lock-table = "lock_table"
    query-limit = 100
  }
}
lock {
  ## the lock store mode: local、remote
  mode = "remote"

  local {
    ## store locks in user's database
  }

  remote {
    ## store locks in the seata's server
  }
}
recovery {
  committing-retry-delay = 30
  asyn-committing-retry-delay = 30
  rollbacking-retry-delay = 30
  timeout-retry-delay = 30
}

transaction {
  undo.data.validation = true
  undo.log.serialization = "jackson"
}

## metrics settings
metrics {
  enabled = false
  registry-type = "compact"
  # multi exporters use comma divided
  exporter-list = "prometheus"
  exporter-prometheus-port = 9898
}


config {
  nacos.group = "default"
}
@Configuration
public class DataSourceConfiguration {
    @Bean
    @Primary
    public DataSourceProxy dataSourceProxy(DataSourceProperties properties){
        HikariDataSource dataSource = properties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
        return new DataSourceProxy(dataSource);
    }
}

2、timed-out and no fallback available,failed and no fallback available

这个错误基本是出现在Hystrix熔断器
可以 禁用feign的hystrix

# 由于hystrix超时后会抛出异常
feign.hystrix.enabled: false

但是这样不能解决根本问题,Feign调用远程服务时,默认为8秒超时时间,超时同样会跳转到熔断器进行处理。所以要从请求超时时间入手

ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=60000

以上参考博文,文末列出

如果本地测试,多次请求后同样可以请求成功

3、undo_log.sql

-- ----------------------------
-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(100) NOT NULL,
  `context` varchar(128) NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int(11) NOT NULL,
  `log_created` datetime NOT NULL,
  `log_modified` datetime NOT NULL,
  `ext` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

4、参考文献

感谢他们的提供
[1]: https://seata.io/zh-cn/docs/ops/deploy-guide-beginner.html
[2]: https://gitee.com/zengdw/springcloud-seata/blob/master/order/src/main/java/com/zengdw/order/configure/DataSoucreConfigure.java
[3]: https://www.cnblogs.com/EasonJim/p/7722372.html
[4]: https://segmentfault.com/a/1190000022032144?utm_source=tag-newest

如果其他问题,欢迎在评论区留下问题,乐意共同探讨

你可能感兴趣的:(JAVA,java,spring,boot,spring,后端)