Message Properties
A message is more than its body
Section titled “A message is more than its body”When you publish, the body — the actual bytes — is only half the story. Every AMQP message also carries a set of properties: metadata that RabbitMQ and your consumers can act on without parsing the body. Some are just informational; a couple genuinely change delivery behaviour.
The property that changes behaviour: delivery_mode
Section titled “The property that changes behaviour: delivery_mode”The one property that affects reliability is delivery_mode (also called “persistent”):
delivery_mode = 2(persistent) — RabbitMQ writes the message to disk, so it can survive a broker restart.delivery_mode = 1(transient, the default in raw AMQP) — the message lives in memory and is lost on restart.
Pair this with a durable queue (last lesson). The rule is worth memorising: durable queue + persistent message = survives a restart. Miss either half and the data is at risk.
Persistence isn’t free — writing to disk costs throughput. That’s a real trade-off you’ll weigh in the reliability module.
The informational properties
Section titled “The informational properties”The rest describe the message so consumers (and tooling) can handle it correctly:
| Property | Purpose |
|---|---|
content_type | e.g. application/json — how to interpret the body |
content_encoding | e.g. gzip |
headers | Arbitrary key/value metadata (also used by the headers exchange) |
correlation_id | Match a reply to its request (the RPC pattern) |
reply_to | The queue a reply should be sent to |
message_id | A unique id — handy for idempotency and deduplication |
timestamp | When the message was created |
priority | Higher-priority messages jump the queue (needs a priority queue) |
expiration | Per-message TTL in milliseconds |
Publishing with properties
Section titled “Publishing with properties”channel.publish('orders', 'order.created', Buffer.from(JSON.stringify(order)), { persistent: true, // delivery_mode = 2 contentType: 'application/json', messageId: order.id, timestamp: Date.now(), headers: { source: 'checkout' },});channel.basic_publish( exchange="orders", routing_key="order.created", body=json.dumps(order), properties=pika.BasicProperties( delivery_mode=2, # persistent content_type="application/json", message_id=order["id"], headers={"source": "checkout"}, ),)ch.PublishWithContext(ctx, "orders", "order.created", false, false, amqp.Publishing{ DeliveryMode: amqp.Persistent, // delivery_mode = 2 ContentType: "application/json", MessageId: order.ID, Timestamp: time.Now(), Headers: amqp.Table{"source": "checkout"}, Body: body, },)