apache / incubator-seata

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
https://seata.apache.org/
Apache License 2.0
25.31k stars 8.78k forks source link

seata客户端使用Apollo作为配置中心连接不上 #6693

Open caoxingsheng opened 3 months ago

caoxingsheng commented 3 months ago

组件版本

Apollo2.2.0 seata1.5.2 jdk11 spring cloud alibaba 2.2.9.RELEASE spring cloud Hoxton.SR12 spring boot 2.3.12.RELEASE

seata服务端配置

server:
  port: 7091

spring:
  application:
    name: seata-server

logging:
  config: classpath:logback-spring.xml
  file:
    path: ${user.home}/logs/seata
  extend:
    logstash-appender:
      destination: 127.0.0.1:4560
    kafka-appender:
      bootstrap-servers: 127.0.0.1:9092
      topic: logback_to_logstash

console:
  user:
    username: seata
    password: seata

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: apollo
    apollo:
      appId: seata-server
      apollo-meta: http://localhost:8080
      apollo-config-service: http://localhost:8080
      namespace: application
      apollo-access-key-secret:
      cluster: default    
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: eureka
    eureka:
      service-url: http://localhost:10086/eureka
      application: default
      weight: 1       
#  store:
#    # support: file 、 db 、 redis
#    mode: file
#  server:
#    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

服务端是可以成功注册到eureka的 image

apollo上传config.txt配置

transport.type = TCP
transport.server = NIO
transport.heartbeat = true
transport.enableTmClientBatchSendRequest = false
transport.enableRmClientBatchSendRequest = true
transport.enableTcServerBatchSendResponse = false
transport.rpcRmRequestTimeout = 30000
transport.rpcTmRequestTimeout = 30000
transport.rpcTcRequestTimeout = 30000
transport.threadFactory.bossThreadPrefix = NettyBoss
transport.threadFactory.workerThreadPrefix = NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix = NettyServerBizHandler
transport.threadFactory.shareBossWorker = false
transport.threadFactory.clientSelectorThreadPrefix = NettyClientSelector
transport.threadFactory.clientSelectorThreadSize = 1
transport.threadFactory.clientWorkerThreadPrefix = NettyClientWorkerThread
transport.threadFactory.bossThreadSize = 1
transport.threadFactory.workerThreadSize = default
transport.shutdown.wait = 3
transport.serialization = seata
transport.compressor = none
service.vgroupMapping.default_tx_group = default
service.default.grouplist = 127.0.0.1:8091
service.enableDegrade = false
service.disableGlobalTransaction = false
client.rm.asyncCommitBufferLimit = 10000
client.rm.lock.retryInterval = 10
client.rm.lock.retryTimes = 30
client.rm.lock.retryPolicyBranchRollbackOnConflict = true
client.rm.reportRetryCount = 5
client.rm.tableMetaCheckEnable = true
client.rm.tableMetaCheckerInterval = 60000
client.rm.sqlParserType = druid
client.rm.reportSuccessEnable = false
client.rm.sagaBranchRegisterEnable = false
client.rm.sagaJsonParser = fastjson
client.rm.tccActionInterceptorOrder = -2147482648
client.tm.commitRetryCount = 5
client.tm.rollbackRetryCount = 5
client.tm.defaultGlobalTransactionTimeout = 60000
client.tm.degradeCheck = false
client.tm.degradeCheckAllowTimes = 10
client.tm.degradeCheckPeriod = 2000
client.tm.interceptorOrder = -2147482648
client.undo.dataValidation = true
client.undo.logSerialization = jackson
client.undo.onlyCareUpdateColumns = true
server.undo.logSaveDays = 7
server.undo.logDeletePeriod = 86400000
client.undo.logTable = undo_log
client.undo.compress.enable = true
client.undo.compress.type = zip
client.undo.compress.threshold = 64k
tcc.fence.logTableName = tcc_fence_log
tcc.fence.cleanPeriod = 1h
log.exceptionRate = 100
store.mode = db
store.lock.mode = db
store.session.mode = db
store.publicKey = 
store.file.dir = file_store/data
store.file.maxBranchSessionSize = 16384
store.file.maxGlobalSessionSize = 512
store.file.fileWriteBufferCacheSize = 16384
store.file.flushDiskMode = async
store.file.sessionReloadReadSize = 100
store.db.datasource = druid
store.db.dbType = mysql
store.db.driverClassName = com.mysql.cj.jdbc.Driver
store.db.url = jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
store.db.user = root
store.db.password = root
store.db.minConn = 5
store.db.maxConn = 30
store.db.globalTable = global_table
store.db.branchTable = branch_table
store.db.distributedLockTable = distributed_lock
store.db.queryLimit = 100
store.db.lockTable = lock_table
store.db.maxWait = 5000
store.redis.mode = single
store.redis.single.host = 127.0.0.1
store.redis.single.port = 6379
store.redis.sentinel.masterName = 
store.redis.sentinel.sentinelHosts = 
store.redis.maxConn = 10
store.redis.minConn = 1
store.redis.maxTotal = 100
store.redis.database = 0
store.redis.password = 
store.redis.queryLimit = 100
server.recovery.committingRetryPeriod = 1000
server.recovery.asynCommittingRetryPeriod = 1000
server.recovery.rollbackingRetryPeriod = 1000
server.recovery.timeoutRetryPeriod = 1000
server.maxCommitRetryTimeout = -1
server.maxRollbackRetryTimeout = -1
server.rollbackRetryTimeoutUnlockEnable = false
server.distributedLockExpireTime = 10000
server.xaerNotaRetryTimeout = 60000
server.session.branchAsyncQueueSize = 5000
server.session.enableBranchAsyncRemove = false
server.enableParallelRequestHandle = false
metrics.enabled = false
metrics.registryType = compact
metrics.exporterList = prometheus
metrics.exporterPrometheusPort = 9898

image

springboot集成seata客户端

app:
  id: xxxx
apollo:
  meta: http://localhost:8080
  config-service: http://localhost:8080
  cache-dir: c:/opt/data
  bootstrap:
    enabled: true
    namespaces: application
  cluster: default

seata:
  enabled: true
  application-id: ${spring.application.name}
  tx-service-group: default_tx_group
  config:
    type: apollo
#    type: file
    apollo:
      apollo-meta: http://127.0.0.1:8080
      apollo-config-service: http://127.0.0.1:8080
      app-id: seata-server
      namespace: application
      apollo-accesskey-secret:
      cluster: default
    file:
      name: file.conf
  registry:
    type: eureka
    eureka:
      weight: 1
      application: default
      service-url: http://localhost:10086/eureka/
  service:
    vgroup-mapping:
      default_tx_group: default

启动项目报错 image

上传config.type如果改为file的话就不会报错“can not get cluster name in registry config 'service.vgroupMapping.default_tx_group', please make sure registry config correct”,可以成功访问seata,但是config.type为apollo,里面的配置怎么改都会报错

file.conf文件内容

transport {
  # tcp, unix-domain-socket
  type = "TCP"
  #NIO, NATIVE
  server = "NIO"
  #enable heartbeat
  heartbeat = true
  # the tm client batch send request enable
  enableTmClientBatchSendRequest = false
  # the rm client batch send request enable
  enableRmClientBatchSendRequest = true
   # the rm client rpc request timeout
  rpcRmRequestTimeout = 2000
  # the tm client rpc request timeout
  rpcTmRequestTimeout = 10000
  #thread factory for netty
  threadFactory {
    bossThreadPrefix = "NettyBoss"
    workerThreadPrefix = "NettyServerNIOWorker"
    serverExecutorThread-prefix = "NettyServerBizHandler"
    shareBossWorker = false
    clientSelectorThreadPrefix = "NettyClientSelector"
    clientSelectorThreadSize = 1
    clientWorkerThreadPrefix = "NettyClientWorkerThread"
    # netty boss thread size
    bossThreadSize = 1
    #auto default pin or 8
    workerThreadSize = "default"
  }
  shutdown {
    # when destroy server, wait seconds
    wait = 3
  }
  serialization = "seata"
  compressor = "none"
}
service {
  #transaction service group mapping
  vgroupMapping.default_tx_group = "default"
  #only support when registry.type=file, please don't set multiple addresses
  default.grouplist = "127.0.0.1:8091"
  #degrade, current not support
  enableDegrade = false
  #disable seata
  disableGlobalTransaction = false
}

client {
  rm {
    asyncCommitBufferLimit = 10000
    lock {
      retryInterval = 10
      retryTimes = 30
      retryPolicyBranchRollbackOnConflict = true
    }
    reportRetryCount = 5
    tableMetaCheckEnable = false
    tableMetaCheckerInterval = 60000
    reportSuccessEnable = false
    sagaBranchRegisterEnable = false
    sagaJsonParser = "fastjson"
    sagaRetryPersistModeUpdate = false
    sagaCompensatePersistModeUpdate = false
    tccActionInterceptorOrder = -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000
    sqlParserType = "druid"
    branchExecutionTimeoutXA = 60000
    connectionTwoPhaseHoldTimeoutXA = 10000
  }
  tm {
    commitRetryCount = 5
    rollbackRetryCount = 5
    defaultGlobalTransactionTimeout = 60000
    degradeCheck = false
    degradeCheckPeriod = 2000
    degradeCheckAllowTimes = 10
    interceptorOrder = -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000
  }
  undo {
    dataValidation = true
    onlyCareUpdateColumns = true
    logSerialization = "jackson"
    logTable = "undo_log"
    compress {
      enable = true
      # allow zip, gzip, deflater, 7z, lz4, bzip2, zstd default is zip
      type = zip
      # if rollback info size > threshold, then will be compress
      # allow k m g t
      threshold = 64k
    }
  }
  loadBalance {
      type = "RandomLoadBalance"
      virtualNodes = 10
  }
}
log {
  exceptionRate = 100
}
tcc {
  fence {
    # tcc fence log table name
    logTableName = tcc_fence_log
    # tcc fence log clean period
    cleanPeriod = 1h
  }
}
funky-eyes commented 3 months ago

service.vgroupMapping.default_tx_group 配置了没?

funky-eyes commented 3 months ago

我说的是在apollo上配置了没,这个错误是在apollo上没读到这个配置项

caoxingsheng commented 3 months ago

我说的是在apollo上配置了没,这个错误是在apollo上没读到这个配置项

配置了的,上面config.txt就是了。感觉就是连不上Apollo的样子。 image

leizhiyuan commented 2 months ago

最前面应该还有别的日志,可以把完整的seata server日志发出来。

caoxingsheng commented 1 month ago

最前面应该还有别的日志,可以把完整的seata server日志发出来。

image image image image image image image

funky-eyes commented 1 month ago

你client依赖的是seata-spring-boot-starter还是seata-all? Is your client dependency seata-spring-boot-starter or seata-all?

caoxingsheng commented 1 month ago

`

com.alibaba.cloud spring-cloud-starter-alibaba-seata

`

测试代码在这里,https://github.com/caoxingsheng/seatademo