Springboot Kafka Module Skill logo

Springboot Kafka Module Skill

Community
jiushiwon
springboot-kafka-module-skill

Spring Kafka 模块快速集成技能。面向已拥有 Spring Boot 项目骨架的开发者,提供 Kafka 生产者、消费者、消息订阅、事件驱动等能力的快速集成。触发词:"Spring Kafka"、"Spring Boot Kafka"、"Kafka 集成"、"kafka producer"、"kafka consumer"、"kafka 消息"、"kafka 事件"、"kafka 队列"。

Overview

Publisherjiushiwon
Repositorywg-skills
Skill namespringboot-kafka-module-skill
Stars
123
Forks
38
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by jiushiwon on GitHub. Read the source before you install it.

Installation

Install the Springboot Kafka Module Skill AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/jiushiwon/wg-skills/tree/main/vibeCoding/backend/java/springboot-module/springboot-kafka-module-skill
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/jiushiwon/wg-skills.git /tmp/wg-skills
mkdir -p .claude/skills
cp -r /tmp/wg-skills/vibeCoding/backend/java/springboot-module/springboot-kafka-module-skill .claude/skills/springboot-kafka-module-skill
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Springboot Kafka Module Skill in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Springboot Kafka Module Skill on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Springboot Kafka Module Skill is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Spring Kafka Module Skill

面向已有 Spring Boot 项目的开发者,快速集成 Kafka 能力。

能力清单

能力说明
生产者同步/异步发送消息、消息分区、消息key
消费者消费监听、消息重试、消费者组
消息序列化JSON/Avro/ProtoBuf
事务消息Kafka 事务
拦截器消息发送/消费拦截
** Streams**Kafka Streams 流处理

触发场景

用户说"帮我加 Kafka"或"集成 Kafka"时触发。

依赖配置

xml
<!-- pom.xml 添加 -->
<dependency>
    <groupId>org.springframework.kafka</groupId>
    <artifactId>spring-kafka</artifactId>
</dependency>

默认方法封装

1. 生产者

java
@Service
public class KafkaProducerService {
    
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    
    /**
     * 发送消息(同步)
     */
    public SendResult<String, String> send(String topic, String key, String message) {
        ListenableFuture<SendResult<String, String>> future = 
            kafkaTemplate.send(topic, key, message);
        try {
            return future.get(10, TimeUnit.SECONDS);
        } catch (Exception e) {
            throw new RuntimeException("发送消息失败", e);
        }
    }
    
    /**
     * 发送消息(异步)
     */
    public void sendAsync(String topic, String key, String message, SendCallback callback) {
        kafkaTemplate.send(topic, key, message).addCallback(callback);
    }
    
    /**
     * 发送 JSON 消息
     */
    public void sendJson(String topic, String key, Object object) {
        String json = JSON.toJSONString(object);
        kafkaTemplate.send(topic, key, json);
    }
    
    /**
     * 发送带回调的消息
     */
    public void sendWithCallback(String topic, String key, String message) {
        kafkaTemplate.send(topic, key, message).addCallback(
            success -> {
                // 成功
                String topic = success.getRecordMetadata().topic();
                int partition = success.getRecordMetadata().partition();
                long offset = success.getRecordMetadata().offset();
                log.info("消息发送成功: topic={}, partition={}, offset={}", topic, partition, offset);
            },
            failure -> {
                // 失败
                log.error("消息发送失败: {}", failure.getMessage());
            }
        );
    }
}

2. 消费者

java
@Service
public class KafkaConsumerService {
    
    /**
     * 简单消费
     */
    @KafkaListener(topics = "my-topic", groupId = "my-group")
    public void consume(ConsumerRecord<String, String> record) {
        log.info("收到消息: key={}, value={}, partition={}, offset={}", 
            record.key(), record.value(), record.partition(), record.offset());
        
        // 业务处理
        String message = record.value();
        // ...
    }
    
    /**
     * 消费 JSON 消息
     */
    @KafkaListener(topics = "user-events", groupId = "user-group", containerFactory = "jsonKafkaListenerContainerFactory")
    public void consumeJson(UserEvent event) {
        log.info("收到用户事件: {}", event);
        // 业务处理
    }
    
    /**
     * 批量消费
     */
    @KafkaListener(topics = "batch-topic", groupId = "batch-group", containerFactory = "batchKafkaListenerContainerFactory")
    public void consumeBatch(List<ConsumerRecord<String, String>> records) {
        log.info("批量收到 {} 条消息", records.size());
        for (ConsumerRecord<String, String> record : records) {
            // 处理每条消息
        }
    }
    
    /**
     * 带错误处理的消费
     */
    @KafkaListener(topics = "error-topic", groupId = "error-group", errorHandler = "kafkaErrorHandler")
    public void consumeWithError(ConsumerRecord<String, String> record) {
        // 业务处理
    }
}

3. 事务消息

java
@Service
public class KafkaTransactionService {
    
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    
    /**
     * 事务操作:在事务内发送多条消息,要么全部成功,要么全部回滚
     */
    @Transactional
    public void sendInTransaction(String topic1, String msg1, String topic2, String msg2) {
        kafkaTemplate.executeInTransaction(operations -> {
            operations.send(topic1, "key1", msg1);
            operations.send(topic2, "key2", msg2);
            return true;
        });
    }
}

4. 配置类

java
@Configuration
public class KafkaConfig {
    
    @Value("${spring.kafka.bootstrap-servers}")
    private String bootstrapServers;
    
    /**
     * 生产者配置
     */
    @Bean
    public ProducerFactory<String, String> producerFactory() {
        Map<String, Object> props = new HashMap<>();
        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        // acks 配置
        props.put(ProducerConfig.ACKS_CONFIG, "all");
        // 重试次数
        props.put(ProducerConfig.RETRIES_CONFIG, 3);
        // 批量大小
        props.put(ProducerConfig.BATCH_SIZE_CONFIG, 16384);
        // 缓冲内存
        props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 33554432);
        return new DefaultKafkaProducerFactory<>(props);
    }
    
    @Bean
    public KafkaTemplate<String, String> kafkaTemplate() {
        return new KafkaTemplate<>(producerFactory());
    }
    
    /**
     * 消费者配置
     */
    @Bean
    public ConsumerFactory<String, String> consumerFactory() {
        Map<String, Object> props = new HashMap<>();
        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
        props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-group");
        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        // 自动提交
        props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
        // 最早/最新偏移量
        props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
        return new DefaultKafkaConsumerFactory<>(props);
    }
    
    @Bean
    public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() {
        ConcurrentKafkaListenerContainerFactory<String, String> factory = 
            new ConcurrentKafkaListenerContainerFactory<>();
        factory.setConsumerFactory(consumerFactory());
        // 并发消费
        factory.setConcurrency(3);
        // 批量消费
        factory.setBatchListener(true);
        return factory;
    }
    
    /**
     * JSON 序列化/反序列化
     */
    @Bean
    public JsonSerializer<Object> jsonSerializer() {
        return new JsonSerializer<>();
    }
    
    @Bean
    public JsonDeserializer<Object> jsonDeserializer() {
        JsonDeserializer<Object> deserializer = new JsonDeserializer<>();
        deserializer.addTrustedPackages("*");
        return deserializer;
    }
}

5. 错误处理

java
@Component
public class KafkaErrorHandler implements ErrorHandler {
    
    @Override
    public void handle(Exception e, ConsumerRecord<String, String> record) {
        log.error("消费消息失败: topic={}, partition={}, offset={}, key={}, value={}, error={}",
            record.topic(), record.partition(), record.offset(), 
            record.key(), record.value(), e.getMessage());
        
        // 可选:发送到死信队列
        // 可以记录到数据库或发送到告警
    }
    
    @Override
    public void handle(List<ConsumerRecord<String, String>> records, Exception e) {
        log.error("批量消费消息失败,数量: {}", records.size(), e);
    }
}

配置模板

application.yml

yaml
spring:
  kafka:
    bootstrap-servers: ${KAFKA_HOST:localhost}:${KAFKA_PORT:9092}
    producer:
      # 生产者配置
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer
      acks: all
      retries: 3
      batch-size: 16384
      buffer-memory: 33554432
      properties:
        linger.ms: 10
        compression.type: snappy
    consumer:
      # 消费者配置
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      group-id: my-group
      auto-offset-reset: earliest
      enable-auto-commit: false
      properties:
        spring.json.trusted.packages: "*"
    listener:
      # 监听器配置
      ack-mode: manual_immediate
      concurrency: 3

不做

  • 不负责安装 Kafka(用户自行安装或使用 Docker)
  • 不处理 Kafka 集群配置(单节点为主)
  • 不提供消息持久化策略
  • 不处理 Kafka Connect 数据同步

Frequently asked questions

What does the Springboot Kafka Module Skill AI skill do?

Spring Kafka 模块快速集成技能。面向已拥有 Spring Boot 项目骨架的开发者,提供 Kafka 生产者、消费者、消息订阅、事件驱动等能力的快速集成。触发词:"Spring Kafka"、"Spring Boot Kafka"、"Kafka 集成"、"kafka producer"、"kafka consumer"、"kafka 消息"、"kafka 事件"、"kafka 队列"。

Why use Springboot Kafka Module Skill on TypingMind?

Because you install it once and use it with any model. Springboot Kafka Module Skill is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Springboot Kafka Module Skill in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/jiushiwon/wg-skills/tree/main/vibeCoding/backend/java/springboot-module/springboot-kafka-module-skill. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Springboot Kafka Module Skill?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Springboot Kafka Module Skill?

As many as you like. As long as a model supports skills, you can use Springboot Kafka Module Skill with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Springboot Kafka Module Skill AI skill free?

Yes. It is published on GitHub by jiushiwon under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇