Skip to Content
Go Realm v1 is released 🎉
RabbitMQDay 4: Exchange Types

Day 4

Exchange Types: Direct, Fanout, Topic, Headers

RabbitMQ routing power āφāϏ⧇ exchange āĻĨ⧇āϕ⧇āĨ¤ āφāϜāϕ⧇āϰ lesson-āĻāϰ āωāĻĻā§āĻĻ⧇āĻļā§āϝ āĻšāϞ⧋ āϕ⧋āύ use case-āĻ āϕ⧋āύ exchange type āϏāĻŦāĻšā§‡ā§Ÿā§‡ sensible āϤāĻž reason āĻ•āϰāĻžāĨ¤

Exchange Routing

Exchange Comparison

ExchangeRouting basisBest forMental model
Directexact routing keycommand-like routingstrict switchboard
Fanoutno routing key match neededbroadcastloudspeaker
Topicwildcard patternevent familiessmart router
Headersmetadata headersniche routingpolicy gate
err := ch.ExchangeDeclare( "events.topic", "topic", true, false, false, false, nil, ) if err != nil { log.Fatal(err) }

Routing Decision

Situation: āĻ•āĻŋāϛ⧁ consumer āĻļ⧁āϧ⧁ `order.*`, āĻ•āĻŋāϛ⧁ `payment.#` family āĻļ⧁āύāĻŦ⧇āĨ¤

Goal: āĻāĻ•āϟāĻŋ exchange type āύāĻŋāĻ°ā§āĻŦāĻžāϚāύ āĻ•āϰāĻžāĨ¤

What to think about:

  • event name hierarchy already āφāϛ⧇
  • future routing expand āĻšāϤ⧇ āĻĒāĻžāϰ⧇
  • broadcast āύāĻž, filtered subscription āĻĻāϰāĻ•āĻžāϰ
āϏāĻŽā§āĻ­āĻžāĻŦā§āϝ āϏāĻŽāĻžāϧāĻžāύ āĻĻ⧇āϖ⧁āύ

Topic exchange best fitāĨ¤ `order.*`, `payment.#` pattern āĻĻāĻŋā§Ÿā§‡ clean subscription āĻ•āϰāĻž āϝāĻžāĻŦ⧇ āĻāĻŦāĻ‚ future hierarchy extend āĻ•āϰāĻžāĻ“ āϏāĻšāϜ āĻšāĻŦ⧇āĨ¤

Headers exchange āĻ•āĻŦ⧇ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻŦ⧇?

Checkpoint

āύāĻŋāĻœā§‡āϰ āĻ­āĻžāώāĻžā§Ÿ direct āφāϰ topic-āĻāϰ āĻĒāĻžāĻ°ā§āĻĨāĻ•ā§āϝ explain āĻ•āϰ⧋āĨ¤

  • Direct exact match āϚāĻžā§Ÿ
  • Topic pattern match āϚāĻžā§Ÿ
  • Topic future growth-āĻāϰ āϜāĻ¨ā§āϝ āĻŦ⧇āĻļāĻŋ flexible