# Xxl Job Xugudb Adapter

> XXL-JOB 分布式任务调度框架与虚谷数据库（XuguDB）集成适配指南。当用户需要在 Spring Boot 项目中使用 XXL-JOB 连接 XuguDB 时使用此技能，包括任务调度配置、数据源设置、执行器配置、任务处理器编写、路由策略、分片任务等。适用于定时任务、批量数据处理、分布式计算、工作流编排等场景。

- **Type:** Skill
- **Install:** `agentstack add skill-kourou25-xugudb-dev-skills-xxl-job-xugudb-adapter`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [kourou25](https://agentstack.voostack.com/s/kourou25)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [kourou25](https://github.com/kourou25)
- **Source:** https://github.com/kourou25/xugudb-dev-skills/tree/master/skills/xugudb-ecosystem/adapters/xxl-job-xugudb-adapter

## Install

```sh
agentstack add skill-kourou25-xugudb-dev-skills-xxl-job-xugudb-adapter
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# XXL-JOB 分布式任务调度 XuguDB 适配指南

## 概述

本指南详细介绍如何将 XXL-JOB 分布式任务调度框架与虚谷数据库（XuguDB）集成，包括完整的配置流程、使用示例和最佳实践。XXL-JOB 是一个轻量级分布式任务调度框架，支持动态任务管理、多种路由策略和故障转移。

## 快速开始

### 1. 获取适配版 XXL-JOB

由于官方 XXL-JOB 不支持 XuguDB，需要使用虚谷提供的适配版本：

```bash
# 下载适配版 XXL-JOB
# 访问：https://help.xugudb.com/content/ecosystem/orm/java/xxl-job
```

### 2. 初始化数据库

在 XuguDB 中创建数据库：

```sql
CREATE DATABASE `xxl_job` CHARACTER SET 'utf8_bin' TIME ZONE 'GMT+08:00';
USE xxl_job;
CREATE USER `xxl_job` IDENTIFIED BY 'xxl_job';
GRANT DBA IN SCHEMA `xxl_job' TO 'xxl_job';
```

执行适配版提供的 SQL 初始化脚本 `tables_xxl_job_xugu.sql`。

### 3. 配置数据源

在 `application.properties` 中配置：

```properties
spring.datasource.driver-class-name=com.xugudb.jdbc.Driver
spring.datasource.url=jdbc:xugu://127.0.0.1:5138/xxl_job
spring.datasource.username=xxl_job
spring.datasource.password=xxl_job
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=20

xxl.job.accessToken=default_token
```

### 4. 启动 XXL-JOB Admin

```bash
java -jar xxl-job-admin-2.3.1.jar --spring.config.location=file:./application.properties
```

### 5. 访问管理界面

- **地址**：`http://localhost:8080/xxl-job-admin/toLogin`
- **默认账号**：`admin`
- **默认密码**：`123456`

## 配置详解

### 数据源配置参数

| 参数 | 说明 | 推荐值 |
|------|------|--------|
| `driver-class-name` | XuguDB JDBC 驱动类 | `com.xugudb.jdbc.Driver` |
| `url` | 数据库连接 URL | `jdbc:xugu://host:port/db` |
| `accessToken` | 通信令牌 | `default_token`（建议修改） |

### 连接池配置

```properties
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.max-lifetime=1800000
```

## 执行器集成

### 1. 添加 Maven 依赖

```xml

    
    
        com.xuxueli
        xxl-job-core
        2.3.1
    
    
    
    
        com.xugudb
        xugu-jdbc
        12.3.4
    

```

### 2. 配置执行器

在 `application.yml` 中配置：

```yaml
xxl:
  job:
    admin:
      addresses: http://127.0.0.1:8080/xxl-job-admin
    executor:
      appname: my-executor
      port: 9999
      logpath: /data/applogs/xxl-job/jobhandler
      logretentiondays: 30
    accessToken: default_token
```

### 3. 配置执行器 Bean

```java
@Configuration
public class XxlJobConfig {
    
    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;
    
    @Value("${xxl.job.accessToken}")
    private String accessToken;
    
    @Value("${xxl.job.executor.appname}")
    private String appname;
    
    @Value("${xxl.job.executor.port}")
    private int port;
    
    @Value("${xxl.job.executor.logpath}")
    private String logpath;
    
    @Value("${xxl.job.executor.logretentiondays}")
    private int logretentiondays;
    
    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        XxlJobSpringExecutor executor = new XxlJobSpringExecutor();
        executor.setAdminAddresses(adminAddresses);
        executor.setAppname(appname);
        executor.setPort(port);
        executor.setLogPath(logpath);
        executor.setLogRetentionDays(logretentiondays);
        executor.setAccessToken(accessToken);
        return executor;
    }
}
```

## 任务处理器

### Bean 模式任务处理器

```java
@Component
public class MyJobHandler {
    
    @XxlJob("myJobHandler")
    public void myJobHandler() throws Exception {
        String jobParam = XxlJobHelper.getJobParam();
        XxlJobHelper.log("执行任务，参数：" + jobParam);
        XxlJobHelper.handleSuccess("任务执行成功");
    }
}
```

### 分片任务处理器

```java
@Component
public class ShardingJobHandler {
    
    @XxlJob("shardingJobHandler")
    public void shardingJobHandler() throws Exception {
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        
        XxlJobHelper.log("分片参数：当前分片={}, 总分片={}", shardIndex, shardTotal);
        
        // 处理分片任务
        List items = getItemList();
        for (int i = 0; i 

```

## 最佳实践

1. 使用清晰的任务描述
2. 合理设置路由策略
3. 避免任务执行时间过长
4. 部署多个调度中心节点实现高可用
5. 使用 Nginx 进行负载均衡
6. 监控集群状态和任务执行情况
7. 定期备份数据库

## 资源

- **示例项目**：https://github.com/xuxueli/xxl-job
- **官方文档**：https://help.xugudb.com/content/ecosystem/orm/java/xxl-job
- **XXL-JOB 官网**：http://www.xuxueli.com/xxl-job/

---

**注意**：本指南基于 XXL-JOB v2.3.1 适配版本，确保使用正确的版本以避免兼容性问题。必须使用虚谷提供的适配版 XXL-JOB 和专用 SQL 初始化脚本。

## Source & license

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

- **Author:** [kourou25](https://github.com/kourou25)
- **Source:** [kourou25/xugudb-dev-skills](https://github.com/kourou25/xugudb-dev-skills)
- **License:** Apache-2.0

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

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-kourou25-xugudb-dev-skills-xxl-job-xugudb-adapter
- Seller: https://agentstack.voostack.com/s/kourou25
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
