Queues
Decouple the sender from the receiver: the broker holds the work, and what cannot be done lands in a dead letter queue.
The CityScript
This is all there is to it. Change it in the editor and the city redraws.
%% Q · Queues
%% Producers publish to an exchange; the exchange routes to queues; consumers take work at their own speed.
city 48x32
district producers "Producers" 3,3..13,12
district broker "RabbitMQ" 18,3..33,14
district consumers "Consumers" 38,3..46,17
building web factory in producers "Web app"
floor web.f "Publisher"
room web.pub service "Order publisher"
building exchange tower in broker "Exchange"
floor exchange.f "Routing"
room exchange.topic proxy "orders exchange" port=5672
building queues warehouse in broker "Queues"
floor queues.f "Queues"
room queues.orders queue "orders" port=5672
room queues.emails queue "emails" port=5672
room queues.dead queue "dead letters" port=5672
building billing factory in consumers "Billing"
floor billing.f "Consumer"
room billing.worker worker "Invoice worker"
building mailer factory in consumers "Mailer"
floor mailer.f "Consumer"
room mailer.worker worker "Email worker"
link web.pub -> exchange.topic "publish" variant=emphasis
link exchange.topic -> queues.orders "route: orders" variant=emphasis
link queues.orders -> billing.worker "consume" variant=emphasis
link exchange.topic -> queues.emails "route: emails"
link queues.emails -> mailer.worker "consume"
link queues.orders -> queues.dead "failed" variant=dashed