liveBook · Manning

Exchange

As explained in Spring in Action, Sixth Edition

An exchange is an AMQP message-routing component that accepts messages and routes them to queues according to exchange type, bindings, and routing keys.

An exchange is a RabbitMQ message-routing component. Producers send messages to an exchange with a routing key; the exchange then sends them to one or more queues according to its type and bindings. section 9.2

Figure 9.2 Messages sent to a RabbitMQ exchange are routed to one or more queues, based on routing keys and bindings.

This diagram shows the essential path: messages enter an exchange, then reach queues through bindings and routing-key decisions. section 9.2

Choose the exchange type according to the routing behavior you need:

  • Default routes a message to the queue whose name matches its routing key; RabbitMQ automatically binds every queue to it. section 9.2
  • Direct routes to queues whose binding key exactly matches the message’s routing key. section 9.2
  • Topic routes to one or more queues when binding keys, including wildcard patterns, match the routing key. section 9.2
  • Fanout sends messages to every bound queue without considering routing or binding keys. section 9.2
  • Headers routes according to message-header values, while dead-letter exchanges collect undeliverable messages. section 9.2

Spring applications send through RabbitTemplate using an exchange and routing key rather than a queue destination. Methods without an exchange use the default exchange; methods without a routing key use a default routing key. section 9.2.2

Sending a taco order

A messaging service can send an order object through the named exchange with rabbit.convertAndSend("tacocloud.order", order). RabbitTemplate converts the object into a message before handing it to RabbitMQ. A configured exchange and routing key can also be supplied through Spring configuration. section 9.2.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains routing relationships and exchange types, then demonstrates Spring sending without detailing broker configuration internals.
Examples
Uses default, direct, topic, fanout, headers, and dead-letter exchanges plus RabbitTemplate-based taco-order messages.
What you can do after
Apply it via RabbitTemplate to send converted objects or raw messages through exchanges and routing keys.
How it connects
Connects AMQP messages with RabbitMQ, queues, routing keys, bindings, and RabbitTemplate.

Also explained in

Compare how 3 books explain exchange →

Related concepts

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.