在上一篇《从0到1 手把手搭建spring cloud alibaba 微服务大型应用框架(五) SEATA分布式事务篇(下)应用整合shardingsphere集成seata完整代码及订单-库存完整模拟案例》中许多小伙伴和我说,都集成后,seata 和应用服务在同一机器上的情况下没问题
但是Seata 和应用服务不在统一机器时,会报连不上127.0.0.1 8091 ,命名已经改成了连接其他seata 的ip
为什么还会连接127.0.0.1 8091 这个本机seata 服务呢
问题排查
我翻看了seata 连接源码,发现它在连接寻找seata 服务时时找的本地的配置文件
application.properties 或者application.yml ,然后里面指定file.conf的文件名称
发现了问题原因,那么我们就添加一个application.yml 就可以了
问题解决
新添加application.yml 如下:
application.yml
seata: enabled: true application-id: mini-cloud-simulate-goods-biz tx-service-group: mini-cloud-simulate-goods_tx_group enable-auto-data-source-proxy: true data-source-proxy-mode: AT use-jdk-proxy: false client: rm: async-commit-buffer-limit: 1000 report-retry-count: 5 table-meta-check-enable: false report-success-enable: false saga-branch-register-enable: false saga-json-parser: fastjson lock: retry-interval: 10 retry-times: 30 retry-policy-branch-rollback-on-conflict: true tm: commit-retry-count: 5 rollback-retry-count: 5 default-global-transaction-timeout: 60000 degrade-check: false degrade-check-period: 2000 degrade-check-allow-times: 10 undo: data-validation: true log-serialization: jackson log-table: undo_log only-care-update-columns: true log: exceptionRate: 100 service: vgroup-mapping: etuo-busi-customer-biz_tx_group: default grouplist: default: 192.168.1.32:8091 enable-degrade: false disable-global-transaction: false transport: shutdown: wait: 3 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 worker-thread-size: default boss-thread-size: 1 type: TCP server: NIO heartbeat: true serialization: seata compressor: none enable-client-batch-send-request: true config: type: nacos consul: server-addr: 127.0.0.1:8500 apollo: apollo-meta: http://192.168.1.204:8801 app-id: seata-server namespace: application apollo-accesskey-secret: "" etcd3: server-addr: http://localhost:2379 nacos: namespace: serverAddr: 192.168.1.45:8848 group: SEATA_GROUP username: "" password: "" zk: server-addr: 127.0.0.1:2181 session-timeout: 6000 connect-timeout: 2000 username: "" password: "" custom: name: "" registry: type: file load-balance: RandomLoadBalance load-balance-virtual-nodes: 10 file: name: file.conf consul: server-addr: 127.0.0.1:8500 etcd3: serverAddr: http://localhost:2379 eureka: weight: 1 service-url: http://localhost:8761/eureka nacos: application: seata-server server-addr: 127.0.0.1:8848 group : "SEATA_GROUP" namespace: username: "" password: "" redis: server-addr: localhost:6379 db: 0 password: timeout: 0 sofa: server-addr: 127.0.0.1:9603 region: DEFAULT_ZONE datacenter: DefaultDataCenter group: SEATA_GROUP addressWaitTime: 3000 application: default zk: server-addr: 127.0.0.1:2181 session-timeout: 6000 connect-timeout: 2000 username: "" password: "" custom: name: ""
关键点: