---
title: "Spring Boot and BabelQueue over RabbitMQ"
description: "Wire the canonical envelope into a Spring Boot app: one MessageConverter, an injectable publisher, and @RabbitListener consumers that interoperate with every other SDK."
source: https://babelqueue.com/blog/spring-boot-babelqueue-rabbitmq/
pubDate: 2026-11-11T00:00:00.000Z
---
Spring AMQP already gives you `RabbitTemplate` and `@RabbitListener`. BabelQueue adds one `MessageConverter` so the bytes those move are the canonical envelope — readable by every other SDK, not a Java-only blob. You publish by URN, you consume a typed `Envelope`, and a Python or Go service on the same queue sees exactly the same message.
This guide wires the Spring Boot adapter end to end: install, configure, produce, and consume. Every code path uses the real adapter API from the [Spring Boot adapter docs](/docs/babelqueue-java/1.x/spring/).
## Add the dependency
`com.babelqueue:babelqueue-spring` plugs the Java core into Spring AMQP. The core (`babelqueue-core`) comes transitively. You need **Spring Boot 3**, **Java 17+**, and RabbitMQ.
Maven:
```xml
com.babelqueue
babelqueue-spring
1.1.0
```
Gradle (Kotlin DSL):
```kotlin
implementation("com.babelqueue:babelqueue-spring:1.1.0")
implementation("org.springframework.boot:spring-boot-starter-amqp")
```
## One converter, wired both ways
The adapter's auto-configuration registers a single `MessageConverter` bean (`BabelQueueMessageConverter`) and a `BabelQueuePublisher`. Boot's RabbitMQ auto-config then injects that one converter into the `RabbitTemplate` (producing) and the default listener container factory (consuming). The same encode/decode rules govern both directions, so a message you send and a message you receive obey one contract.
Both beans **back off** if your app already defines its own. That means you keep your custom `RabbitTemplate` or converter if you have one, and the adapter steps aside.
Configuration is one property:
```yaml
# application.yaml
babelqueue:
default-queue: orders # written to meta.queue; used when no queue is given
```
`default-queue` sets the queue recorded in `meta.queue` and the target used when a publish call omits the queue. Set it once and your common path needs no per-call routing.
## Produce by URN
Inject `BabelQueuePublisher` and call `publish`. The method returns the message's `meta.id`, so you can log or store it for correlation. Identity is the URN — `urn:babel::` — never a class name.
```java
import com.babelqueue.spring.BabelQueuePublisher;
import java.util.Map;
import org.springframework.stereotype.Service;
@Service
class Orders {
private final BabelQueuePublisher babelQueue;
Orders(BabelQueuePublisher babelQueue) {
this.babelQueue = babelQueue;
}
void create() {
babelQueue.publish("urn:babel:orders:created", Map.of("order_id", 1042L), "orders");
}
}
```
The `data` argument is a plain map — pure JSON, no Java serialization on the wire. The overloads cover the common shapes:
- `publish(urn, data)` — uses `default-queue`.
- `publish(urn, data, queue)` — explicit queue.
- `publish(urn, data, queue, traceId)` — when you carry a `trace_id` in from an upstream hop.
If you model a message as a type implementing `com.babelqueue.PolyglotMessage`, two more overloads take the object directly: `publish(message)` and `publish(message, queue)`. The type supplies its own URN and data, so a producer that owns the schema can hand the publisher a domain object instead of a loose map.
## What lands on the broker
The converter writes the [canonical envelope](/docs/spec/1.x/envelope/) as the AMQP body and mirrors the contract fields into AMQP properties, so broker-native tools and other SDKs can route without parsing the body:
- `type` = the URN
- `correlationId` = `trace_id`
- `messageId` = `meta.id`
- `x-attempts`, `x-schema-version`, and `x-source-lang` headers
- `application/json` content type and persistent delivery
The body itself is the frozen envelope at `schema_version: 1`:
```json
{
"job": "urn:babel:orders:created",
"trace_id": "7b3f9c2a-e41d-4f88-9b2a-1c0d5e6f7a8b",
"data": { "order_id": 1042 },
"meta": { "id": "01J…", "queue": "orders", "lang": "java", "schema_version": 1, "created_at": 1762819200000 },
"attempts": 0
}
```
The only field that changes when a different SDK produces this is `meta.lang`. There is no `serialize()`, no `timestamp`, and no `meta.source` — the body is the same shape any `v1` consumer reads.
## Consume a decoded envelope
A normal `@RabbitListener` receives a decoded core `Envelope`. Route on the URN with `EnvelopeCodec.urn(...)`, then read `data` and `traceId` off the envelope:
```java
import com.babelqueue.Envelope;
import com.babelqueue.EnvelopeCodec;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Component
class OrderListener {
@RabbitListener(queues = "orders")
void onMessage(Envelope envelope) {
if ("urn:babel:orders:created".equals(EnvelopeCodec.urn(envelope))) {
var orderId = envelope.data().get("order_id");
// ... use envelope.traceId(), envelope.data()
}
}
}
```
`envelope.traceId()` is the same `trace_id` the producer set, carried unchanged across the hop — so a trace that starts in your Spring service stays joinable in whatever consumes next.
The converter rejects non-conformant messages before your listener runs: a missing URN, an unsupported `meta.schema_version`, a blank `trace_id`, or missing `data`. Send those to a dead-letter exchange the usual Spring AMQP way, and your handler only ever sees a valid `Envelope`.
## Why this interoperates
The body on the queue is the canonical envelope, and that is the whole point. A message your Spring listener consumes may have been produced by the PHP, Python, Go, Node, or .NET SDK, and a message you publish from Spring is consumable by any of them. All six SDKs are at 1.0 (GA) and vendor the same cross-SDK conformance fixtures, so two SDKs producing the same logical message emit byte-comparable envelopes — the URN routes, the `trace_id` correlates, and `data` stays pure JSON across the boundary.
Concretely: a Python service can `publish` `urn:babel:orders:created` to the `orders` queue, and the Spring listener above handles it without knowing or caring that Python sent it. The reverse holds too.
## Takeaway
The Spring Boot adapter is one converter and one publisher: add `com.babelqueue:babelqueue-spring`, set `babelqueue.default-queue`, inject `BabelQueuePublisher` to send by URN, and accept an `Envelope` in your `@RabbitListener` to receive. Everything on the wire is the frozen `schema_version: 1` envelope, so your Spring app shares queues with every other BabelQueue SDK over the RabbitMQ you already run.
Next: the [Spring Boot adapter reference](/docs/babelqueue-java/1.x/spring/) and the [wire contract](/docs/spec/1.x/envelope/).