Add cloud-stream module: Spring Cloud Stream 5.1 on Boot 4.2 with Kafka and RabbitMQ binders
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5uEyg58znuchZ8C8i
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
e54cf840fd
commit
e2c42dc268
@@ -0,0 +1,61 @@
|
||||
# cloud-stream — Spring Cloud Stream on Boot 4.2: functional Kafka and RabbitMQ binders
|
||||
|
||||
Companion code for the ankurm.com article *Spring Cloud Stream on Boot 4: Functional Kafka and RabbitMQ Binders*.
|
||||
One application, three `java.util.function` beans (`Supplier`, `Function`, `Consumer`), run on Kafka and on RabbitMQ by
|
||||
changing one Spring profile. Every number in the article comes from a file in [`output/`](output), written by the test
|
||||
suite against real brokers started by Testcontainers, or by the two broker-run scripts.
|
||||
|
||||
| Piece | Version | Where it was read from |
|
||||
|---|---|---|
|
||||
| Spring Boot | 4.2.0 (GA 19 Nov 2026) | `maven-metadata.xml` |
|
||||
| Spring Cloud release train | 2026.0.0 | `maven-metadata.xml`; its pom sets `spring-boot.version` to 4.2.0 |
|
||||
| Spring Cloud Stream / Function | 5.1.0 | `spring-cloud-dependencies` 2026.0.0 pom, startup banner |
|
||||
| Kafka binder dependencies | spring-kafka 4.2.0, kafka-clients 4.4.0, spring-integration-kafka 7.2.0 | `mvn dependency:tree` |
|
||||
| Rabbit binder dependencies | spring-rabbit / spring-amqp 4.2.0, amqp-client 5.37.1 | `mvn dependency:tree` |
|
||||
| Kafka broker | `apache/kafka:4.4.0` (4.4.0) | `kafka-topics.sh --version` in the image |
|
||||
| RabbitMQ broker | `rabbitmq:4-management` (4.4.1) | `rabbitmqctl --version` in the image |
|
||||
| Testcontainers | 2.0.5 | Boot's BOM |
|
||||
| JDK | Temurin 25.0.5.1 | |
|
||||
|
||||
## The application
|
||||
|
||||
```
|
||||
orderSource (Supplier) --> orders --> priceOrder (Function) --> invoices --> bill (Consumer)
|
||||
```
|
||||
|
||||
* [`Pipeline.java`](src/main/java/com/ankurm/cloudstream/Pipeline.java): the three beans. No binder import anywhere.
|
||||
* [`application.yml`](src/main/resources/application.yml): destinations, groups, partitioning and retry, valid for any binder.
|
||||
* [`application-kafka.yml`](src/main/resources/application-kafka.yml) and [`application-rabbit.yml`](src/main/resources/application-rabbit.yml):
|
||||
everything that is specific to one broker, including the dead-letter settings.
|
||||
|
||||
## Run it
|
||||
|
||||
```bash
|
||||
export JAVA_HOME=/path/to/jdk-25
|
||||
./scripts/run-all.sh # needs Docker; regenerates every file in output/
|
||||
```
|
||||
|
||||
Against a broker of your own (defaults: Kafka on `localhost:9092`, RabbitMQ on `localhost:5672`):
|
||||
|
||||
```bash
|
||||
mvn -q package -DskipTests
|
||||
java -jar target/cloud-stream-demo-1.0.jar --spring.profiles.active=kafka --demo.max-orders=8
|
||||
java -jar target/cloud-stream-demo-1.0.jar --spring.profiles.active=rabbit --demo.max-orders=8
|
||||
```
|
||||
|
||||
## What the tests show
|
||||
|
||||
| Test | Transcript | What it demonstrates |
|
||||
|---|---|---|
|
||||
| `Test01TestBinderTest` | `01`, `02`, `03` | The test binder: all three function types and the retry count of a failing consumer, with no broker |
|
||||
| `Test02KafkaPipelineTest` | `04-kafka-pipeline.txt` | The pipeline on Kafka: topics and partitions the binder created, consumer group members, which partition each customer lands in and why |
|
||||
| `Test03KafkaDlqTest` | `05-kafka-dlq.txt` | `enable-dlq`: attempts, the DLQ topic and its headers |
|
||||
| `Test04RabbitPipelineTest` | `06-rabbit-partitions.txt` | One queue per partition, what one instance consumes, `required-groups`, and starting the other two instances |
|
||||
| `Test05RabbitDlqTest` | `07-rabbit-dlq.txt` | `republish-to-dlq` true against false |
|
||||
| `Test06WiringMistakesTest` | `08`, `09`, `10` | Two binders and no default, no function definition, the `PRECONDITION_FAILED` from mismatched queue arguments |
|
||||
| `scripts/run-on-broker.sh` | `11-run-kafka.txt`, `12-run-rabbit.txt` | The packaged jar on a real broker; only the profile differs |
|
||||
| `scripts/binder-free.sh` | `13-binder-free.txt` | The application code names neither broker |
|
||||
| `scripts/webflux-path.sh` | `14-webflux-path.txt` | The Rabbit binder pulls in WebFlux |
|
||||
| `scripts/partition-selector.sh` | `15-partition-selector.txt` | The default partition selector, read from the jar: murmur2, not `hashCode()` |
|
||||
|
||||
There is no `docs/` folder: the explanations live in the article's own collapsible sections.
|
||||
Reference in New Issue
Block a user