5 Part IV — Rewind
Steps 28 to 34 go back to one JVM on purpose. With no replication delay and no five-terminal setup, the only thing that can change is who knows whom — so the idea can be tried in seconds instead of in a distributed debugging session.
5.1 The obvious shortcut, and its trap
If the first mediator only copies messages, delete it and let ROT13 read the source itself:
listen("consoleIn.outbox");The mediator is gone. But ask the recurring question: ROT13 now contains the name of ConsoleIn’s mailbox. The topology moved out of the mediator and into the service. As the material puts it: “We removed the mediator… and put topology back into the service. Oops.”
5.2 Capability is not topology
ROT13 may know two things: I can transform text, and I am capable of listening for compatible text messages. It may not know my input always comes from consoleIn.outbox — that is deployment topology.
So the name is not compiled in; it arrives at runtime:
TOPIC consoleIn.outbox
ROT13 learns its wiring from data. Note who sends it: in DynamicQueueRot13.java it is main() that publishes both TOPIC messages — a configurator, outside the data path, in the role the orchestrator played before. It cannot be ConsoleIn: if ConsoleIn told ROT13 what to subscribe to, ConsoleIn would have to know ROT13 exists, and the topology would simply have moved into a different capability.
5.3 What changes in the code
listen(...) is nothing exotic: a virtual thread that repeatedly calls take() on one of the same queues. subscribe(...) starts one such thread per subscribed name. The consequence is visible in the mailboxes:
- ROT13 takes straight from
consoleIn.outbox— the name it was told; rot13.inboxis no longer a payload mailbox. It carries control messages, and ROT13’s loop reads it to decide whether a message is aTOPICto act on.
Nothing writes into rot13.inbox to move data anymore. The mailbox did not disappear; it changed job, from carrying payload to carrying Intent.
One observation from running it: after Ctrl+D, output stops but the program stays up. Nothing was interrupted — runConsoleIn returns on end of input, so the producer is gone, while both subscriber threads sit blocked in take() on sources that will never publish again. The JVM stays alive because main ends with Thread.currentThread().join(). “The flow stopped” always has to be traced to which participant stopped.
5.4 ROUTE and TOPIC are Intent
Apply two tests to TOPIC consoleIn.outbox. Does it describe something that happened? No. Something currently true? No. It says please begin listening here — desired behaviour, which is Intent. The mediator’s ROUTE is the same kind of message: please forward from here to there.
One trap worth naming, because it is tempting in a defence: publishing an Intent is of course something that happened. Classification follows what the message says, not the fact that it exists.
And one condition, which returns later: the dynamic version is not automatically superior. It makes sense only if the consumer actually understands the producer’s message contract.
STATIC MEDIATED DYNAMIC DIRECT
Producer → Mediator → Consumer Intent → (Producer ──► Consumer)