Skip to content
Back to skills

Messaging Patterns

ASecurity

Kafka and RabbitMQ patterns for Spring Boot 3.x — producer reliability, consumer groups, exactly-once semantics, dead letter topics/queues, Schema Registry with Avro, Spring Cloud Stream, and reactive messaging. Use when writing @KafkaListener consumers, KafkaTemplate producers, RabbitMQ listeners, configuring DLQ/DLT, implementing event-driven microservices, or setting up message serialization with Avro/JSON schemas.

  • 4 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 26, 2026
developmentjavareactspringtestingsecurity

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned May 27, 2026

npx -y skills add taipt1504/agent-skills --skill messaging-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Messaging Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Messaging Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/taipt1504-messaging-patterns/badge)](https://www.skillsdirectory.com/skills/taipt1504-messaging-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: messaging-patterns
description: >
  Kafka and RabbitMQ patterns for Spring Boot 3.x — producer reliability, consumer groups,
  exactly-once semantics, dead letter topics/queues, Schema Registry with Avro, Spring Cloud
  Stream, and reactive messaging. Use when writing @KafkaListener consumers, KafkaTemplate
  producers, RabbitMQ listeners, configuring DLQ/DLT, implementing event-driven microservices,
  or setting up message serialization with Avro/JSON schemas.
triggers:
  natural: ["kafka consumer", "message queue", "event streaming", "rabbitmq", "dead letter"]
  code: ["@KafkaListener", "KafkaTemplate", "@RabbitListener", "RabbitTemplate"]
applicability:
  always: false
  triggers:
    files_match: ["**/*KafkaListener*.java", "**/*Consumer*.java", "**/*Producer*.java", "**/*EventPublisher*.java", "**/*Outbox*.java"]
    code_patterns: ["@KafkaListener", "KafkaTemplate", "@RabbitListener", "RabbitTemplate", "OutboxService", "AbstractKafkaMessageHandler"]
    task_keywords: ["Kafka", "RabbitMQ", "event", "outbox", "consumer", "producer", "DLQ", "DLT", "idempotency", "saga"]
    related_rules:
      - rules/java/security.md
      - rules/java/observability.md
relevance_assessment: |
  HIGH 80%+: new consumer/producer OR new event type OR outbox table OR DLQ config
  MEDIUM 40-79%: existing handler modification, retry/DLQ tuning
  LOW 1-39%: caller emits event but handler in other service
  ZERO: project has neither Kafka nor RabbitMQ (verify build.gradle)
---

# Messaging Patterns for Spring Boot

## Decision Table: Kafka vs RabbitMQ

| Criteria | Kafka | RabbitMQ |
|----------|-------|----------|
| Throughput | Millions msg/s, append-only log | Tens of thousands msg/s |
| Ordering | Per-partition guaranteed | Per-queue (single consumer) |
| Replay | Yes -- consumers re-read by offset | No -- consumed messages removed |
| Routing | Topic-based (partitions) | Exchange-based (direct/topic/fanout/headers) |
| Delivery | At-least-once; exactly-once with EOS | At-least-once; no native EOS |
| Use when | Event streaming, log aggregation, high-volume CQRS | Task queues, RPC, complex routing, low-latency request/reply |
| Protocol | Custom binary | AMQP 0-9-1 |

**Rule:** Event log/replay needed → Kafka. Complex routing/task dispatch → RabbitMQ.

## Shared Patterns

### Producer Reliability
1. **Idempotent sends** — Kafka: `enable.idempotence=true`; RabbitMQ: publisher confirms
2. **Persistent delivery** — Kafka: `acks=all`; RabbitMQ: `PERSISTENT` delivery mode
3. **Transactional** — Kafka: `executeInTransaction`; RabbitMQ: `rabbitTemplate.invoke`
4. **Serialization** — Explicit (JSON/Avro); never rely on defaults

### Consumer Error Handling
1. **Manual ACK** — both brokers; never auto-ack in production
2. **Retry + dead letter** — Kafka: `DefaultErrorHandler` + `DeadLetterPublishingRecoverer`; RabbitMQ: `RetryInterceptorBuilder` + DLX/DLQ
3. **Non-retryable exceptions** — skip retry for `DeserializationException`, `ValidationException`
4. **DLQ consumer** — persist failed messages, always ACK DLQ to prevent loops

## Critical Config

Full producer/consumer config: see `references/kafka.md` or `references/rabbitmq.md`.

## Verification Checklist

- [ ] Producer uses idempotent/confirmed mode
- [ ] Consumer ACK is manual (not auto)
- [ ] Dead letter configured (DLT for Kafka, DLX+DLQ for RabbitMQ)
- [ ] Retry with backoff before dead-lettering
- [ ] Non-retryable exceptions bypass retry
- [ ] Serializer/deserializer explicitly configured
- [ ] Testcontainers round-trip test for producer-consumer
- [ ] DLQ consumer or monitoring in place
- [ ] Consumer lag (Kafka) or queue depth (RabbitMQ) monitored
- [ ] Health indicator registered

## References

Load as needed:

- **[references/kafka.md](references/kafka.md)** -- Kafka producer/consumer patterns, DLT, topic config, exactly-once semantics, reactive Kafka, Schema Registry/Avro, anti-patterns
- **[references/rabbitmq.md](references/rabbitmq.md)** -- RabbitMQ exchange topology, producer confirms, consumer manual ACK, retry+DLQ with x-death, reactor-rabbitmq, production config, anti-patterns
- **[references/testing-monitoring.md](references/testing-monitoring.md)** -- EmbeddedKafka, Testcontainers (Kafka + RabbitMQ), Awaitility, consumer lag monitoring, health indicators, Micrometer metrics
- **[references/event-architecture.md](references/event-architecture.md)** -- Saga (choreography + orchestration), transactional outbox, event sourcing, schema evolution, idempotency

## Related Skills

- **summer-data** — OutboxService transactional outbox pattern publishes to Kafka/RabbitMQ
- **architecture** — Event-driven bounded context communication, CQRS event sourcing
- **testing-workflow** — Testcontainers for Kafka/RabbitMQ integration tests
- **observability-patterns** — Consumer lag monitoring, Micrometer metrics for messaging

Files in this skill

  • SKILL.md4.8 KB
  • references/event-architecture.md5.7 KB
  • references/kafka.md19.4 KB
  • references/rabbitmq.md13.6 KB
  • references/testing-monitoring.md17.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.