Why not publish straight to the cloud?
The question came from the corporate integration team the week after a drinks company bought a can-making plant. The plant's line controllers publish stoppages, reject counts and shift totals to a broker in the plant's own server room. Corporate runs its messaging on a cloud broker. Why not point the controllers at the cloud and switch the plant's broker off?
The plant manager's answer was the fibre. It runs 60 km to the nearest exchange and fails a few times a year, once for most of a day. The lines have to keep running when it does, and on the plant floor a stoppage message is not a report: it is how the technicians' tablets learn that line 3 has stopped, and why. A broker in another region is no use to a technician standing next to the line. So the plant keeps its broker, corporate keeps its own, and what corporate needs is a copy of some of the plant's messages: maintenance planning wants the stoppages, the quality team wants the reject counts.
A consumer on one side, a producer on the other
A Messaging Bridge connects the two. It is a client of both systems: it consumes from a channel on the plant's broker, through a subscription of its own beside the tablets', and republishes each message to a channel on the corporate broker. Neither broker needs to know the other exists, and the applications on each side keep talking only to their own. The bridge is the integration cousin of the Anti-Corruption Layer: it keeps two ecosystems connected without merging them.
The bridge reads line.stoppages on the plant's broker and republishes each message on plant7.stoppages, a channel on the corporate broker. The two brokers never connect to each other.
Most of the bridge's configuration is a channel mapping: for each channel that crosses, its name on one side and its name on the other. line.stoppages means nothing among the forty plants on the corporate broker, so it arrives there as plant7.stoppages. The mapping is also the list of what crosses, and it should be explicit. The controllers publish an oven temperature every second as well; corporate has no use for it, and copying it would send a message a second across the fibre for nobody to read. A bridge that copies every channel by wildcard copies next year's channels too, including ones that were never meant to leave the plant.
The two sides rarely agree on format either. The controllers send a reason code, R14, where corporate's schema expects a reason such as "die change". That conversion is a Message Translator, inside the bridge or as the step right after it; keeping it separate keeps the bridge's own job, moving messages without losing them, easy to see.
212 stoppages that never crossed
The first version of the bridge took its client library's default and acknowledged each message to the plant's broker as soon as it received it, then published it to the corporate broker. On the night of the first fibre cut, every message the bridge received after the link dropped was acknowledged, failed to publish, and was deleted by the plant's broker. By morning 212 stoppages were missing on the corporate side, and maintenance planning showed line 3 running through a two-hour stoppage.
A bridge is one more hop, and the rule Guaranteed Delivery sets for every hop applies to it: acknowledge on the plant's side only after the corporate broker has confirmed it stored the copy durably. Until then the plant's broker still holds the message, and if the bridge crashes or the confirmation never comes, the message is delivered to the bridge again.
The price is duplicates. If the corporate broker stores a stoppage and the bridge dies before its acknowledgement reaches the plant, the plant delivers that message again and the bridge republishes it, so corporate receives it twice. With one acknowledgement on each side and nothing spanning both brokers, the bridge cannot remove that risk without taking on the opposite one, a loss. What it can do is carry the message's id across unchanged, so that receivers on the corporate side recognise the second copy, the technique Idempotent Consumer describes. A bridge that gives every republished message a new id makes the duplicate look like a second stoppage.
Some messages cannot cross at all: a reason code missing from the translation table, a message the corporate broker rejects as too large. Dropping it hides the failure, because nothing on the corporate side shows a message that never arrived. Retrying it forever, while the bridge sends in order, holds up every message behind it on the channel. The bridge moves it to a Dead Letter Channel, with the reason, on a channel someone watches, and acknowledges the original only once that channel has stored it durably.
Order holds in one lane
Stoppages come in pairs: LineStopped, then LineRestarted forty minutes later. A single bridge consumer that republishes in the order it receives, and waits for each confirmation before sending the next, keeps that order, as far as each channel keeps order itself. In the plant's busiest month the team ran four bridge instances on the same channel, and for line 3 the restart sometimes reached corporate before the stoppage, so planning showed a stopped line that was running. Parallel consumers reorder, and so does redelivery: if the bridge crashes before its acknowledgements reach the plant, messages it already republished can arrive again after newer ones, so corporate receivers should drop a copy they have already seen, as Idempotent Consumer describes, rather than let an old stoppage show the line stopped again. Usually only one line's messages need their order kept, so keep each line in one lane, for example by partitioning on the line id on both sides, with each lane served by one consumer at a time that sends in order as above, and accept that order then holds within a line and not across lines.
When the bridge talks to itself
Six months on, the bridge got a second direction. Corporate planning issues work orders, the technicians' tablets read them from the plant's broker, and the bridge carries them across. Then technicians wanted orders they raised on the floor to reach planning too, and someone added the mapping in the other direction, for the same pair of channels:
- Planning publishes work order WO-5531 on
plant7.work-orders, on the corporate broker. - The bridge copies it to
work-orderson the plant's broker. - The new plant-to-corporate mapping sees a message on
work-ordersand copies it back toplant7.work-orders. - The corporate-to-plant mapping sees a new message there and copies it to the plant again.
Each copy is a new message to each broker, so nothing ends the circle. By morning the plant's broker held tens of thousands of copies of WO-5531, and the tablets had stopped being usable. Two defences, best used together: never map one channel in both directions, so orders raised on the floor go on a channel of their own, work-orders.raised, that crosses only towards corporate; and have the bridge mark everything it republishes with a header naming where it came from, and skip any message that already carries its own mark.
While the bridge is down
The point of the design is that the bridge's failure stays small. When it stops, or the fibre does, each side keeps working with its own broker: the controllers keep publishing, the tablets keep reading, planning keeps issuing orders. Only the crossing stops, and the messages waiting to cross stay on the side they came from, as long as the bridge's subscription there keeps messages for a consumer that is away. How much a broker can hold while a consumer is gone, and what to watch so you notice before it fills, is Message Broker's ground; for the bridge, it means a subscription sized for a day without the fibre, and planning screens that show a day of stoppages arriving in minutes as late data, not as a sudden wave of failures.
The Messaging Endpoints & Broker Challenge does not require a bridge, but its palette has a Messaging Bridge node, so once the required pieces are in place, add one: a Message Channel titled B, standing for a second messaging system, joined to your broker's side through the bridge, with the edge labelled "ack after B confirms". Draw each crossing as its own one-way edge, and if any channel ends up with an edge in each direction, give one direction a channel of its own before the work orders find it.