liveBook · Manning

Message properties

As explained in Spring in Action, Sixth Edition

MessageProperties is a Spring AMQP object containing metadata and headers associated with a Message.

MessageProperties is a Spring AMQP object that carries metadata and headers with a Message. Create it when converting an object to a message; use an empty instance when no properties are needed. section 9.2.2

Adding an order-source header

A message can carry application-specific metadata by setting a header before sending it: create MessageProperties, call setHeader("X_ORDER_SOURCE", "WEB"), convert the order with those properties, and pass the resulting Message to RabbitTemplate.send(). section 9.2.2

public void sendOrder(TacoOrder order) {
  MessageConverter converter = rabbit.getMessageConverter();
  MessageProperties props = new MessageProperties();
  props.setHeader("X_ORDER_SOURCE", "WEB");
  Message message = converter.toMessage(order, props);
  rabbit.send("tacocloud.order", message);
}

Inspect the complete pattern for attaching a custom header during message creation. section 9.2.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines creation and header assignment, but stops short of detailing the full metadata model.
Examples
Uses an order message with an X_ORDER_SOURCE header set to WEB.
What it assumes
Assumes familiarity with RabbitTemplate and message conversion while introducing MessageProperties usage directly.
What you can do after
Build messages with custom headers by using MessageProperties before RabbitTemplate.send().
How it connects
Connects message conversion, Message, MessageConverter, RabbitTemplate, and MessagePostProcessor.

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.