AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified Apache-2.0 Self-run

Seata Xugudb Adapter

skill-kourou25-xugudb-dev-skills-seata-xugudb-adapter · by kourou25

Seata 分布式事务适配虚谷数据库(XuguDB)的完整指南。当用户需要将基于 Seata 的分布式事务解决方案配置或适配到虚谷数据库时使用此技能,包括 Seata Server 配置、客户端配置、数据源代理配置、事务模式配置等。适用于从 MySQL/Oracle 迁移或新建虚谷数据库项目。

— No reviews yet
0 installs
40 views
0.0% view→install

Install

$ agentstack add skill-kourou25-xugudb-dev-skills-seata-xugudb-adapter

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • ✓ Prompt-injection patterns
  • ✓ Secret / credential exfiltration
  • ✓ Dangerous shell & filesystem operations
  • ✓ Untrusted network calls
  • ✓ Known-malicious package signatures

What it can access

  • ✓ Network access No
  • ✓ Filesystem access No
  • ✓ Shell / process execution No
  • ✓ Environment & secrets No
  • ✓ Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-kourou25-xugudb-dev-skills-seata-xugudb-adapter)

Reliability & compatibility

✓ Security review passed
0 installs to date
— no reviews yet
● 3mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Seata Xugudb Adapter? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Seata 分布式事务虚谷数据库适配指南

概述

本技能提供 Seata 分布式事务适配虚谷数据库(XuguDB)的完整流程。Seata 是阿里巴巴开源的分布式事务解决方案,支持 AT、TCC、Saga 和 XA 事务模式,通过适配虚谷数据库,可以实现微服务架构中的分布式事务管理。

适配流程

在开始适配前,按以下顺序检查和修改:

1. 依赖配置 → 2. 数据库初始化 → 3. Seata Server 配置 → 4. 客户端配置 → 5. 功能验证 → 6. 性能优化

第一步:配置依赖

Maven 依赖配置


    io.seata
    seata-spring-boot-starter
    1.7.0

    com.xugudb
    xugu-jdbc
    12.3.4

    com.alibaba
    druid-spring-boot-starter
    1.2.6

第二步:数据库初始化

创建 Seata 所需的表结构

在虚谷数据库中执行以下 SQL 创建 Seata 所需的表:

-- 创建 Seata 全局事务表
CREATE TABLE global_table (
    xid VARCHAR(128) NOT NULL,
    transaction_id BIGINT,
    status TINYINT NOT NULL,
    application_id VARCHAR(32),
    transaction_service_group VARCHAR(32),
    transaction_name VARCHAR(128),
    timeout INT,
    begin_time BIGINT,
    application_data VARCHAR(2000),
    gmt_create DATETIME,
    gmt_modified DATETIME,
    PRIMARY KEY (xid),
    INDEX idx_gmt_modified_status (gmt_modified, status),
    INDEX idx_transaction_id (transaction_id)
);

-- 创建 Seata 分支事务表
CREATE TABLE branch_table (
    branch_id BIGINT NOT NULL,
    xid VARCHAR(128) NOT NULL,
    transaction_id BIGINT,
    resource_group_id VARCHAR(32),
    resource_id VARCHAR(256),
    branch_type VARCHAR(8),
    status TINYINT,
    client_id VARCHAR(64),
    application_data VARCHAR(2000),
    gmt_create DATETIME,
    gmt_modified DATETIME,
    PRIMARY KEY (branch_id),
    INDEX idx_xid (xid)
);

-- 创建 Seata 全局锁表
CREATE TABLE lock_table (
    row_key VARCHAR(128) NOT NULL,
    xid VARCHAR(128),
    transaction_id BIGINT,
    branch_id BIGINT NOT NULL,
    resource_id VARCHAR(256),
    table_name VARCHAR(32),
    pk VARCHAR(36),
    gmt_create DATETIME,
    gmt_modified DATETIME,
    PRIMARY KEY (row_key),
    INDEX idx_branch_id (branch_id)
);

第三步:配置 Seata Server

application.yml 配置

server:
  port: 7091

spring:
  application:
    name: seata-server
  datasource:
    driver-class-name: com.xugu.cloudjdbc.Driver
    url: jdbc:xugu://127.0.0.1:5138/SYSTEM?current_schema=seata&CHAR_SET=UTF8&COMPATIBLE_MODE=MYSQL
    username: SYSDBA
    password: SYSDBA
    type: com.alibaba.druid.pool.DruidDataSource

seata:
  config:
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      namespace:
      group: SEATA_GROUP
      username: nacos
      password: nacos
  registry:
    type: nacos
    nacos:
      application: seata-server
      server-addr: 127.0.0.1:8848
      group: SEATA_GROUP
      namespace:
      username: nacos
      password: nacos
  store:
    mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.xugu.cloudjdbc.Driver
      url: jdbc:xugu://127.0.0.1:5138/SYSTEM?current_schema=seata&CHAR_SET=UTF8&COMPATIBLE_MODE=MYSQL
      username: SYSDBA
      password: SYSDBA
      min-conn: 5
      max-conn: 30
      global-table: global_table
      branch-table: branch_table
      lock-table: lock_table
      distributed-lock-table: distributed_lock
      query-limit: 100

启动 Seata Server

# 启动 Seata Server
sh seata-server.sh -p 7091 -h 127.0.0.1

第四步:配置客户端

客户端配置文件

spring:
  datasource:
    driver-class-name: com.xugu.cloudjdbc.Driver
    url: jdbc:xugu://127.0.0.1:5138/SYSTEM?current_schema=ry&CHAR_SET=UTF8&COMPATIBLE_MODE=MYSQL
    username: SYSDBA
    password: SYSDBA
    type: com.alibaba.druid.pool.DruidDataSource

seata:
  enabled: true
  application-id: ${spring.application.name}
  tx-service-group: my_tx_group
  service:
    vgroup-mapping:
      my_tx_group: default
    grouplist:
      default: 127.0.0.1:8091
  config:
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      group: SEATA_GROUP
      username: nacos
      password: nacos
  registry:
    type: nacos
    nacos:
      application: seata-server
      server-addr: 127.0.0.1:8848
      group: SEATA_GROUP
      username: nacos
      password: nacos

数据源代理配置

import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Bean
    @Primary
    public DataSource dataSource(DataSourceProperties dataSourceProperties) {
        DataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().build();
        return new DataSourceProxy(dataSource);
    }
}

第五步:功能验证

验证基本功能

  1. 全局事务:测试 @GlobalTransactional 注解功能
  2. 分支事务:测试分支事务注册和提交
  3. 事务回滚:测试事务回滚功能
  4. 事务超时:测试事务超时处理
  5. 并发事务:测试并发事务处理

验证高级功能

  1. AT 模式:测试 AT 模式分布式事务
  2. TCC 模式:测试 TCC 模式分布式事务
  3. Saga 模式:测试 Saga 模式分布式事务
  4. XA 模式:测试 XA 模式分布式事务
  5. 高可用:测试 Seata Server 集群

第六步:性能优化

事务配置优化

seata:
  client:
    rm:
      report-success-enable: false
      sql-parser-type: druid
    tm:
      commit-retry-count: 5
      rollback-retry-count: 5
  service:
    vgroup-mapping:
      my_tx_group: default
    grouplist:
      default: 127.0.0.1:8091
  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
      boss-thread-size: 1
      worker-thread-size: 8

数据库优化

  1. 索引优化:为全局事务表和分支事务表创建合适的索引
  2. 连接池优化:合理配置数据库连接池参数
  3. SQL 优化:优化事务相关 SQL 语句
  4. 定期清理:定期清理已完成的事务记录

常见问题排查

1. 驱动类找不到

现象: 启动时报错 Driver class not found

原因: JDBC 驱动未正确引入

解决: 确保 xugu-jdbc 依赖已正确配置

2. 连接 URL 错误

现象: 连接时报错 Invalid connection URL

原因: URL 参数错误

解决: 确保使用正确的 URL 格式,并包含 current_schema=模式名

3. 全局事务表不存在

现象: 启动时报错 Table 'global_table' doesn't exist

原因: Seata 数据库表未初始化

解决: 执行 Seata 数据库初始化脚本

4. 分支事务注册失败

现象: 分支事务注册失败

原因: 数据源代理配置不正确

解决:

  • 确保使用 DataSourceProxy 包装数据源
  • 检查 @GlobalTransactional 注解是否正确使用

5. 全局锁获取失败

现象: 获取全局锁失败

原因: 并发冲突或锁表数据异常

解决:

  • 检查 lock_table 表数据
  • 调整事务超时时间
  • 优化业务逻辑减少锁冲突

6. 事务回滚失败

现象: 事务回滚失败

原因: 回滚逻辑执行异常

解决:

  • 检查回滚 SQL 是否正确
  • 检查数据库连接是否正常
  • 查看 Seata Server 日志

最佳实践

1. 版本管理

  • 始终保持 Seata 版本与虚谷数据库版本兼容
  • 定期检查 Seata 官方发布的更新

2. 配置管理

  • 使用 Nacos 作为配置中心
  • 为不同环境使用不同配置
  • 敏感信息使用环境变量或加密存储

3. 性能优化

  • 合理配置事务超时时间
  • 使用异步提交提高性能
  • 避免长事务
  • 优化 SQL 减少锁冲突

4. 安全性

  • 使用最小权限原则配置数据库用户
  • 定期更换数据库密码
  • 启用 SSL 加密连接

5. 监控与日志

  • 启用 Seata 监控
  • 配置日志级别
  • 定期检查日志文件
  • 监控全局事务状态

参考文档

详细的配置指南和故障排除请参考:

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.