MCPInstall

seata-patterns

Seata 分布式事务技能。覆盖 AT/TCC/SAGA/XA 四模式选择决策树、AT模式 undolog 表必备、TCC 模式 useTCCFence 解决幂等/悬挂/空回滚、SAGA 状态机长流程、全局事务超时配置(@GlobalTransactional timeoutMills)、读隔离增强(@GlobalLock + FOR UPDATE)。 纠正 LLM:不知道 AT/TCC/SAGA选哪个、不建 undolog 表、TCC Confirm非幂等、不看门狗处理。

Installs
75
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/full-stack-skills/java-skills --skill seata-patterns
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads seata-patterns automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Seata 分布式事务

来源:https://seata.apache.org/docs/
GitHub:https://github.com/apache/incubator-seata

Capability Boundaries

✅ Strong Suits

  1. AT模式(推荐起始) — 基于数据源代理,零侵入,覆盖80%场景
  2. TCC模式 — 自定义Try/Confirm/Cancel,性能更好,适合高并发核心业务
  3. SAGA模式 — 长流程事务(>10s),状态机驱动,最终一致性
  4. XA模式 — 强一致,标准协议,适合金融核心
  5. undo_log表 — AT模式必须建立(每个业务库)
  6. @GlobalTransactional — 全局事务入口
  7. @GlobalLock — 读隔离增强

❌ Out of Scope

  1. 单数据库事务 → Spring @Transactional
  2. 最终一致性(不要求强一致) → Kafka/RocketMQ 事务消息

四模式选择决策树

需要分布式事务?
├── 需要强一致性(金融核心) → XA模式(性能差)
├── 最终一致即可
│   ├── 事务执行时间 > 10秒 → SAGA模式(状态机)
│   ├── 高并发 + 愿意写Confirm/Cancel → TCC模式
│   └── 80%场景(默认推荐) → AT模式(零侵入)

LLM最常犯的错误

#错误正确做法
1不知道 AT 模式需要 undo_log 表每个业务数据库建 undo_log 表
2AT 模式用非 ACID 数据库AT 依赖本地事务,必须 MySQL/PostgreSQL/Oracle
3全局事务超时不设置(默认60s可能不够)配置 @GlobalTransactional(timeoutMills = 300000)
4TCC 模式 Confirm 失败不处理幂等Confirm 必须幂等(全局唯一ID+去重索引)
5TCC 模式不处理空回滚用 useTCCFence = true(Seata 1.5.1+)
6读隔离不处理(读到全局事务未提交的数据)查询加 FOR UPDATE + @GlobalLock
7SAGA 模式以为会自动回滚SAGA 需手动写补偿逻辑
8全局事务用时过长(锁冲突)设置合理超时(建议15~30秒)

核心模式

模式 1: AT 模式(零侵入,推荐)

-- ✅ 每个业务数据库必须建 undo_log 表
CREATE TABLE IF NOT EXISTS undo_log (
    id BIGINT NOT NULL AUTO_INCREMENT,
    branch_id BIGINT NOT NULL,
    xid VARCHAR(128) NOT NULL,
    context VARCHAR(128) NOT NULL,
    rollback_info LONGBLOB NOT NULL,
    log_status INT NOT NULL,
    log_created DATETIME NOT NULL,
    log_modified DATETIME NOT NULL,
    PRIMARY KEY (id),
    UNIQUE KEY ux_undo_log (xid, branch_id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
// ✅ AT 模式:只需注解,零业务侵入
@Service
public class OrderService {
    @GlobalTransactional(timeoutMills = 300000, rollbackFor = Exception.class)
    public void createOrder(OrderDTO dto) {
        orderService.create(dto);           // 远程服务A(本地事务)
        inventoryService.deduct(dto);       // 远程服务B(本地事务)
        accountService.debit(dto);          // 远程服务C(本地事务)
        // 任一失败 → 全部自动回滚(基于 undo_log)
    }
}

模式 2: TCC 模式(高并发核心业务)

@LocalTCC
public interface AccountTccAction {
    @TwoPhaseBusinessAction(
        name = "accountTcc",
        commitMethod = "confirm",
        rollbackMethod = "cancel",
        useTCCFence = true  // ← Seata 1.5.1+ 自动处理幂等/悬挂/空回滚
    )
    boolean prepare(BusinessActionContext ctx,
        @BusinessActionContextParameter(paramName = "accountDTO") AccountDTO dto);

    // ✅ Confirm 必须幂等(可重复执行不改变结果)
    boolean confirm(BusinessActionContext ctx);

    // ✅ Cancel 必须是幂等补偿(可能先于 Try 执行=空回滚)
    boolean cancel(BusinessActionContext ctx);
}

模式 3: SAGA 模式(长流程状态机)

// SAGA 使用状态机引擎,通过 JSON 配置编排长事务
// 每个步骤有正向(serviceMethod)和补偿(compensateMethod)

// 适用场景:订单履约、审批流、物流追踪
// 补偿顺序必须严格反向执行
// 补偿操作必须幂等且可重试

模式 4: 读隔离增强(@GlobalLock + FOR UPDATE)

@GlobalLock
@Transactional
public Order getOrder(Long orderId) {
    // ✅ FOR UPDATE + @GlobalLock 解决 AT 模式脏读
    return orderMapper.selectForUpdate(orderId);
}
<select id="selectForUpdate" resultMap="BaseResultMap">
    SELECT * FROM orders WHERE id = #{id} FOR UPDATE
</select>

Gotchas

  1. AT 模式不支持非 ACID 数据库 — MySQL/PostgreSQL/Oracle 可,Redis/Mongo 不可
  2. undo_log 表必须和业务表在同一数据库 — 不同库回滚不了
  3. TCC 的 Confirm 必须是幂等的 — 可重复执行不改变结果
  4. TCC 的 Cancel 必须处理空回滚 — Try 未执行但 Cancel 已收到
  5. SAGA 模式没有自动回滚 — 需手动写补偿逻辑(状态机配置)
  6. 全局锁可能导致死锁 — 设置合理的超时时间(timeoutMills)
  7. @GlobalTransactional 默认60s超时 — 超时后自动回滚,长事务手动调整
  8. Seata TC 必须集群部署至少3节点 — 防单点故障
  9. undo_log 表定期清理 — 已完成的undo_log可删除(常驻内存)
  10. 监控全局事务成功率/失败率 — 使用 Seata Dashboard 或 Prometheus

Data Privacy

本技能不收集、存储或传输任何用户数据。

FAQ

What does the seata-patterns skill do?

Seata 分布式事务技能。覆盖 AT/TCC/SAGA/XA 四模式选择决策树、AT模式 undolog 表必备、TCC 模式 useTCCFence 解决幂等/悬挂/空回滚、SAGA 状态机长流程、全局事务超时配置(@GlobalTransactional timeoutMills)、读隔离增强(@GlobalLock + FOR UPDATE)。 纠正 LLM:不知道 AT/TCC/SAGA选哪个、不建 undolog 表、TCC Confirm非幂等、不看门狗处理。

How do I install seata-patterns?

Run npx skills add https://github.com/full-stack-skills/java-skills --skill seata-patterns in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/seata-patterns/ (personal) or .claude/skills/seata-patterns/ (project).

Which AI agents can use seata-patterns?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is seata-patterns safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains seata-patterns?

It is published by full-stack-skills in full-stack-skills/java-skills. It has 75 recorded installs.

More from full-stack-skills/java-skills

View all →

java-development-manual

full-stack-skills/java-skills

Java开发手册规约集合,基于阿里巴巴Java开发手册(嵩山版)。 涵盖7大维度:编程规约、异常日志、单元测试、安全规约、MySQL数据库、工程结构、设计规约。 当用户需要:(1) 编写或审查Java代码 (2) 检查命名/代码规范 (3) 处理异常和日志 (4) 编写单元测试 (5) 安全编码 (6) 数据库设计 (7) 工程架构设计时使用此skill。 触发词:Java规范、阿里规约、代码规范、开发手册、编程规约、异常处理、单元测试、安全、MySQL、工程结构、设计模式。

Backend & APIs119 installs

mybatis-plus-patterns

full-stack-skills/java-skills

Open the skill to read its SKILL.md instructions.

Backend & APIs114 installs

java-code-comments

full-stack-skills/java-skills

Provides comprehensive guidance for adding Java code comments following industry standards and best practices. This skill helps add class-level comments, method-level comments, and field-level comments to Java code. Use when the user wants to add comments to Java code, needs to document Java classes/methods/fields, wants to improve code documentation, or needs to generate JavaDoc comments. This skill covers Controller, Service, ServiceImpl, Mapper, Model, Entity, BO (Business Object), DTO, VO, and other common Java component types. The skill follows a systematic workflow: scan codebase, identify components, create todo list, and add comments in order (class comments → method comments → field comments).

Backend & APIs112 installs

java-conventions

full-stack-skills/java-skills

统一 Java 项目编码规范与注释规范(SLF4J+Lombok 日志、Bean Lombok 注解选择、判空 Objects/Optional、工具类优先级 Spring→Apache Commons→Hutool→Guava、复杂逻辑用设计模式/简单逻辑不拆分、Controller/Service/ServiceImpl/Mapper 注释一致性)。当需要“按 Java 规范重构/Review/补全注释/统一日志/统一工具类使用/补全 JavaDoc”时使用。

Backend & APIs108 installs

mybatis-patterns

full-stack-skills/java-skills

Open the skill to read its SKILL.md instructions.

Backend & APIs102 installs

mapstruct-patterns

full-stack-skills/java-skills

MapStruct 最佳实践模式。从官方 Reference Guide 提炼,覆盖 Mapper 三种定义方式(接口/抽象类/default方法)、Spring 注入策略(CONSTRUCTOR推荐/SETTER解决循环依赖)、嵌套映射模式(显式子方法 dot notation 一次性配置)、@Qualifier @Named 的安全选择、Lombok 集成规则、@MappingComposition 谨慎使用。 纠正 LLM 最常见的错误:用反射 BeanUtils 而非编译期 MapStruct、嵌套映射全写在一个方法、不知 SETTER 解决循环依赖。

Backend & APIs97 installs

Popular backend & apis skills

View category →

find-skills

vercel-labs/skills

Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.

OfficialBackend & APIs4.1M installs

entra-app-registration

microsoft/azure-skills

Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.

OfficialBackend & APIs566.7K installs

This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).

Backend & APIs514.8K installs

embedded-captions

heygen-com/hyperframes

Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.

Backend & APIs453.3K installs

entra-agent-id

microsoft/azure-skills

Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).

OfficialBackend & APIs336.6K installs

neon

neondatabase/agent-skills

Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.

Backend & APIs237.1K installs