diff --git a/08-part-ix-mqtt.qmd b/08-part-ix-mqtt.qmd index 393a366..8fe95ca 100644 --- a/08-part-ix-mqtt.qmd +++ b/08-part-ix-mqtt.qmd @@ -140,7 +140,7 @@ Abonnieren kostet ein Paket, und **der Broker führt die Abonnementliste**. Es g ```yaml subscribe: - topic: Tutorial/ConsoleIn/U/alice/E/text + topic: Demo/ConsoleIn/U/alice/E/text ``` Only then does a serialisation library have a clear job. `JsonTools` keeps **two** mappers, and the asymmetry is deliberate: @@ -156,7 +156,7 @@ Tolerant in, strict out. A single shared mapper would have to give up one of tho ```yaml subscribe: - topic: Tutorial/ConsoleIn/U/alice/E/text + topic: Demo/ConsoleIn/U/alice/E/text ``` C'est seulement là qu'une bibliothèque de sérialisation a une tâche claire. `JsonTools` garde **deux** mappeurs, et l'asymétrie est voulue : @@ -172,7 +172,7 @@ Tolérant en entrée, strict en sortie. Un mappeur unique devrait renoncer à l' ```yaml subscribe: - topic: Tutorial/ConsoleIn/U/alice/E/text + topic: Demo/ConsoleIn/U/alice/E/text ``` Erst dann hat eine Serialisierungsbibliothek eine klare Aufgabe. `JsonTools` hält **zwei** Mapper, und die Asymmetrie ist Absicht: @@ -189,12 +189,12 @@ Tolerant hinein, streng hinaus. Ein einziger Mapper müsste auf eines davon verz The naming scheme finally gets its name: **D**escription (what contracts this service understands and publishes), **U**nit (which instance), **I**ntent (requested behaviour), **S**tatus (what is true now), **E**vent (what happened). ```text -Tutorial/ROT13/U/alice/{I, S/online, S/subscriptions/text, E/crypted} +Demo/ROT13/U/alice/{I, S/online, S/subscriptions/text, E/crypted} ``` `U/` is what the filesystem never needed: each machine had its own replica of the same relative path, so instance identity was implicit. MQTT has one shared namespace, so a topic must say *which* copy. Hard-coding `U/alice` in a capability is therefore worse than hard-coding `consoleIn.outbox` ever was: it binds the build to one deployment. Configured by Intent, **one build serves everyone** — which is why `MqttConfigure` takes three unit names as arguments. The unit names *are* the topology. -Rewiring, observed on a running system: publish a new Intent naming a different source topic, and the service unsubscribes from the old one, subscribes to the new one, and republishes `S/subscriptions` to match. No restart, no edit. Send an invalid filter instead — `Tutorial/#/E/text`, where `#` is not the last level — and `MqttTools.isValidFilter` rejects it; the old subscription stands and the Status still tells the truth. +Rewiring, observed on a running system: publish a new Intent naming a different source topic, and the service unsubscribes from the old one, subscribes to the new one, and republishes `S/subscriptions` to match. No restart, no edit. Send an invalid filter instead — `Demo/#/E/text`, where `#` is not the last level — and `MqttTools.isValidFilter` rejects it; the old subscription stands and the Status still tells the truth. That rejection exposes a real gap, worth naming rather than hiding: it is logged locally only. The configurator cannot tell whether its Intent was applied or refused, and a monitor cannot distinguish "refused" from "not yet processed". In this design a sender learns the outcome by reading Status and comparing it with what it asked for. Publishing refusals as an Event, or a last-error Status, would close that gap; neither is in the material, so it is a design decision to justify. ::: @@ -203,12 +203,12 @@ That rejection exposes a real gap, worth naming rather than hiding: it is logged Le schéma de nommage reçoit enfin son nom : **D**escription (quels contrats ce service comprend et publie), **U**nit (quelle instance), **I**ntent (comportement demandé), **S**tatus (ce qui est vrai maintenant), **E**vent (ce qui est arrivé). ```text -Tutorial/ROT13/U/alice/{I, S/online, S/subscriptions/text, E/crypted} +Demo/ROT13/U/alice/{I, S/online, S/subscriptions/text, E/crypted} ``` `U/` est ce dont le système de fichiers n'avait pas besoin : chaque machine avait sa réplique du même chemin relatif, l'identité d'instance était implicite. MQTT a un espace de noms partagé : un sujet doit donc dire *quelle* copie. Coder en dur `U/alice` dans une capacité est donc pire que de coder en dur `consoleIn.outbox` : cela lie la compilation à un déploiement. Configuré par Intent, **une seule compilation sert tout le monde** — d'où les trois noms d'unité en arguments de `MqttConfigure`. Les noms d'unité *sont* la topologie. -Recâblage observé sur un système en marche : publiez un nouvel Intent nommant une autre source, et le service se désabonne de l'ancienne, s'abonne à la nouvelle et republie `S/subscriptions` en conséquence. Sans redémarrage, sans édition. Envoyez au contraire un filtre invalide — `Tutorial/#/E/text`, où `#` n'est pas le dernier niveau — et `MqttTools.isValidFilter` le rejette ; l'ancien abonnement demeure et le Status continue de dire vrai. +Recâblage observé sur un système en marche : publiez un nouvel Intent nommant une autre source, et le service se désabonne de l'ancienne, s'abonne à la nouvelle et republie `S/subscriptions` en conséquence. Sans redémarrage, sans édition. Envoyez au contraire un filtre invalide — `Demo/#/E/text`, où `#` n'est pas le dernier niveau — et `MqttTools.isValidFilter` le rejette ; l'ancien abonnement demeure et le Status continue de dire vrai. Ce rejet révèle une vraie lacune, à nommer plutôt qu'à cacher : il n'est journalisé que localement. Le configurateur ne peut savoir si son Intent a été appliqué ou refusé, et un moniteur ne peut distinguer « refusé » de « pas encore traité ». Dans cette conception, l'émetteur apprend le résultat en lisant le Status et en le comparant à sa demande. Publier les refus comme Event, ou un Status de dernière erreur, combleraient la lacune ; ni l'un ni l'autre n'est dans le matériel : c'est une décision de conception à justifier. ::: @@ -217,12 +217,12 @@ Ce rejet révèle une vraie lacune, à nommer plutôt qu'à cacher : il n'est jo Das Namensschema erhält endlich seinen Namen: **D**escription (welche Verträge dieser Dienst versteht und veröffentlicht), **U**nit (welche Instanz), **I**ntent (gewünschtes Verhalten), **S**tatus (was jetzt gilt), **E**vent (was geschehen ist). ```text -Tutorial/ROT13/U/alice/{I, S/online, S/subscriptions/text, E/crypted} +Demo/ROT13/U/alice/{I, S/online, S/subscriptions/text, E/crypted} ``` `U/` brauchte das Dateisystem nie: jede Maschine hatte ihr eigenes Replikat desselben relativen Pfades, Instanzidentität war implizit. MQTT hat einen gemeinsamen Namensraum, ein Topic muss also sagen, *welche* Kopie. `U/alice` in einer Fähigkeit festzuschreiben ist daher schlimmer, als `consoleIn.outbox` es je war: es bindet das Build an ein Deployment. Per Intent konfiguriert, **dient ein Build allen** — daher die drei Unit-Namen als Argumente von `MqttConfigure`. Die Unit-Namen *sind* die Topologie. -Umverdrahten, am laufenden System beobachtet: einen neuen Intent mit anderer Quelle veröffentlichen, und der Dienst kündigt die alte, abonniert die neue und veröffentlicht `S/subscriptions` passend neu. Kein Neustart, keine Änderung. Schickt man stattdessen einen ungültigen Filter — `Tutorial/#/E/text`, wo `#` nicht die letzte Ebene ist — weist `MqttTools.isValidFilter` ihn ab; das alte Abonnement bleibt, und der Status sagt weiter die Wahrheit. +Umverdrahten, am laufenden System beobachtet: einen neuen Intent mit anderer Quelle veröffentlichen, und der Dienst kündigt die alte, abonniert die neue und veröffentlicht `S/subscriptions` passend neu. Kein Neustart, keine Änderung. Schickt man stattdessen einen ungültigen Filter — `Demo/#/E/text`, wo `#` nicht die letzte Ebene ist — weist `MqttTools.isValidFilter` ihn ab; das alte Abonnement bleibt, und der Status sagt weiter die Wahrheit. Diese Abweisung legt eine echte Lücke offen, die man benennen und nicht verstecken sollte: sie wird nur lokal protokolliert. Der Konfigurator erfährt nicht, ob sein Intent angewandt oder abgelehnt wurde, und ein Monitor kann „abgelehnt" nicht von „noch nicht verarbeitet" unterscheiden. In diesem Entwurf erfährt ein Sender das Ergebnis, indem er den Status liest und mit seiner Anfrage vergleicht. Abweisungen als Event zu veröffentlichen oder ein Letzter-Fehler-Status würden die Lücke schliessen; beides steht nicht im Material — es ist eine zu begründende Entwurfsentscheidung. ::: @@ -230,13 +230,13 @@ Diese Abweisung legt eine echte Lücke offen, die man benennen und nicht verstec ## [What a new subscriber learns, and what a dead one admits]{.en}[Ce qu'un nouvel abonné apprend, et ce qu'un mort avoue]{.fr}[Was ein neuer Abonnent erfährt und was ein Toter zugibt]{.de} {#sec-retained-and-will} ::: {.en} -Subscribing to `Tutorial/#` for three seconds, with nothing being published, returns this: +Subscribing to `Demo/#` for three seconds, with nothing being published, returns this: ```text -Tutorial/ROT13/U/nitro5/S/online {"value":true} -Tutorial/ROT13/U/nitro5/S/subscriptions/text "Tutorial/ConsoleIn/U/nitro5/E/text" -Tutorial/ConsoleOut/U/nitro5/S/online {"value":true} -Tutorial/ConsoleOut/U/nitro5/S/subscriptions/text "Tutorial/ROT13/U/nitro5/E/crypted" +Demo/ROT13/U/nitro5/S/online {"value":true} +Demo/ROT13/U/nitro5/S/subscriptions/text "Demo/ConsoleIn/U/nitro5/E/text" +Demo/ConsoleOut/U/nitro5/S/online {"value":true} +Demo/ConsoleOut/U/nitro5/S/subscriptions/text "Demo/ROT13/U/nitro5/E/crypted" ``` A late arrival learns the entire current wiring of the system, instantly, without asking anyone and without any component knowing a monitor exists. That is retained **Status**. No Events arrive, because Events are published non-retained — "retained State, non-retained Events". It is also the proper answer to the instinct of *asking* a service what it is doing: nobody asks; the service states it, once, and the broker keeps it for whoever turns up. @@ -252,13 +252,13 @@ The will is **retained**, so when the broker publishes it on the client's behalf ::: ::: {.fr} -S'abonner à `Tutorial/#` pendant trois secondes, sans que rien ne soit publié, renvoie ceci : +S'abonner à `Demo/#` pendant trois secondes, sans que rien ne soit publié, renvoie ceci : ```text -Tutorial/ROT13/U/nitro5/S/online {"value":true} -Tutorial/ROT13/U/nitro5/S/subscriptions/text "Tutorial/ConsoleIn/U/nitro5/E/text" -Tutorial/ConsoleOut/U/nitro5/S/online {"value":true} -Tutorial/ConsoleOut/U/nitro5/S/subscriptions/text "Tutorial/ROT13/U/nitro5/E/crypted" +Demo/ROT13/U/nitro5/S/online {"value":true} +Demo/ROT13/U/nitro5/S/subscriptions/text "Demo/ConsoleIn/U/nitro5/E/text" +Demo/ConsoleOut/U/nitro5/S/online {"value":true} +Demo/ConsoleOut/U/nitro5/S/subscriptions/text "Demo/ROT13/U/nitro5/E/crypted" ``` Un arrivant tardif apprend instantanément tout le câblage actuel du système, sans rien demander et sans qu'aucun composant sache qu'un moniteur existe. C'est le **Status** retenu. Aucun Event n'arrive, car les Events sont publiés non retenus — « State retenu, Events non retenus ». C'est aussi la bonne réponse à l'instinct de *demander* à un service ce qu'il fait : personne ne demande ; le service le déclare, une fois, et le courtier le garde pour quiconque se présente. @@ -274,13 +274,13 @@ Elle est **retenue** : quand le courtier la publie au nom du client, elle rempla ::: ::: {.de} -Drei Sekunden `Tutorial/#` abonnieren, ohne dass etwas veröffentlicht wird, ergibt dies: +Drei Sekunden `Demo/#` abonnieren, ohne dass etwas veröffentlicht wird, ergibt dies: ```text -Tutorial/ROT13/U/nitro5/S/online {"value":true} -Tutorial/ROT13/U/nitro5/S/subscriptions/text "Tutorial/ConsoleIn/U/nitro5/E/text" -Tutorial/ConsoleOut/U/nitro5/S/online {"value":true} -Tutorial/ConsoleOut/U/nitro5/S/subscriptions/text "Tutorial/ROT13/U/nitro5/E/crypted" +Demo/ROT13/U/nitro5/S/online {"value":true} +Demo/ROT13/U/nitro5/S/subscriptions/text "Demo/ConsoleIn/U/nitro5/E/text" +Demo/ConsoleOut/U/nitro5/S/online {"value":true} +Demo/ConsoleOut/U/nitro5/S/subscriptions/text "Demo/ROT13/U/nitro5/E/crypted" ``` Ein Spätankömmling erfährt augenblicklich die gesamte aktuelle Verdrahtung des Systems, ohne jemanden zu fragen und ohne dass eine Komponente von einem Monitor weiss. Das ist retained **Status**. Keine Events kommen an, denn Events werden nicht retained veröffentlicht — „retained State, nicht retained Events". Es ist auch die richtige Antwort auf den Reflex, einen Dienst zu *fragen*, was er tut: niemand fragt; der Dienst erklärt es einmal, und der Broker bewahrt es für jeden, der kommt. diff --git a/_book/00-orientation.html b/_book/00-orientation.html index bb07332..0eed7bc 100644 --- a/_book/00-orientation.html +++ b/_book/00-orientation.html @@ -52,19 +52,19 @@ ul.task-list li input[type="checkbox"] { - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + - + @@ -87,19 +87,19 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + +
+ + + +
+ + +
+
+

6  Part V — Replay the dynamic idea across processes

+
+ + + +
+ + + + +
+ + + +
+ + + +

Steps 35 to 38 take the subscription idea out of the single JVM. The services become separate programs again, but instead of mediators copying files, each service watches the mailbox it was told to watch. One assumption of the first filesystem helper does not survive the move, and fixing it is what this part is really about.

+
+

6.1 One blocking watch is not enough

+

FileMessageBoard.watch(topic, receiver) registers one directory and blocks forever. That was enough while every process watched one fixed mailbox. A dynamically wired service needs more:

+
always watch its own control inbox
+AND
+add a watched directory at runtime
+AND
+possibly remove it later
+

The old signature cannot express that, and the consequence was already visible earlier: the configurable mediator accepted exactly one ROUTE, because the moment it began watching its source it went deaf to its own control inbox. The limitation was never whose directory — it was one, fixed, forever.

+
+
+

6.2 The helper: FileSubscriptions

+

One WatchService can serve many directories. register(...) returns a WatchKey identifying one of them, watcher.take() returns whichever key has events, and key.cancel() deregisters it. The helper keeps both directions, name → key and key → name, so an event can be traced back to the mailbox it came from.

+

Events do not reach a callback directly. They go onto a queue, read with take(), carrying

+
record IncomingMessage(String mailbox, Message message) {}
+

Two reasons, and order of arrival is only the third. First, the observing thread must stay responsive for every subscribed directory: a callback that transformed, published or blocked would stall the observation of all the others. Second, the mailbox name travels with the message, so one loop in the service can decide what a message means — control inbox, so this is Intent to act on; subscribed source, so this is data to transform — and that same loop is free to add or remove subscriptions, because it is not sitting inside a callback.

+
+
+

6.3 Two publications instead of four

+

Run SensorService, DynamicProcessorService and DynamicActuatorService — and no mediators — then let Configure.java publish the two TOPIC messages. A line typed afterwards leaves exactly two application publications in the board:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
mailboxcontentwhat it is
consoleIn/outboxTEXT hellothe input
rot13/outboxTEXT uryybthe result
rot13/inboxTOPIC consoleIn/outboxIntent, published once
consoleOut/inboxTOPIC rot13/outboxIntent, published once
+

consoleOut/inbox holds no payload at all: ConsoleOut takes straight from rot13/outbox. Its inbox changed job, from carrying messages to carrying wiring.

+

A line typed before Configure.java ran stays in consoleIn/outbox forever. A subscription that does not exist yet misses what came before it — exactly what the restarted mediator showed when it delivered nothing.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
versionapplication publicationsprocesses in the data path
mediated (step 18)45
configurable mediator (step 27)45
dynamic (step 38)23
+ + +
+ +
+ + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/_book/06-part-vi-vocabulary.html b/_book/06-part-vi-vocabulary.html new file mode 100644 index 0000000..50dc117 --- /dev/null +++ b/_book/06-part-vi-vocabulary.html @@ -0,0 +1,1324 @@ + + + + + + + + + +7  Part VI — Replay it over Syncthing, and name the messages – Process Control + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + +
+ + + +
+ + +
+
+

7  Part VI — Replay it over Syncthing, and name the messages

+
+ + + +
+ + + + +
+ + + +
+ + + +

Steps 39 to 47 distribute the dynamic version across two machines, say precisely what “direct” means, and then — only now, after the ideas have been used — give the three kinds of message their names: Intent, Status, Event.

+
+

7.1 The distributed dynamic run

+

Sensor on one machine, ROT13 and the actuator on the other, no mediator anywhere. After the two TOPIC Intents had replicated, a typed line produced the result on the other machine — and the board shows what that cost:

+
    +
  • consoleIn/outbox: the input;
  • +
  • rot13/outbox: the result, written by the service that produced it;
  • +
  • consoleOut/inbox: Intent only, where the mediated version held a full copy of every message.
  • +
+

The timing was the interesting part. The input was published at 02:35:12 and the results appeared on the first machine at 04:11:28.797 and .893 — 96 ms apart, long after the input. Syncthing had been saturated overnight, so the batch arrived when the queue drained. The chain was correct throughout; the transport’s latency is simply not something the architecture controls. Compare 24 ms for the same chain on one machine.

+
+
+

7.2 What “direct” means, exactly

+

Two hops that look alike are architecturally opposite:

+
    +
  • a transport hop — Syncthing on each side, possibly a relay in between — adds no participant that knows the topology and nothing reacts to it. If the packets detoured through another continent, no claim here would be contradicted.
  • +
  • an architectural hop — a mediator copying consoleIn/outbox → rot13/inbox — adds a component that must know both names, sits in the availability chain, and republishes the message.
  • +
+

So the defensible claim is: ROT13 reacts to ConsoleIn’s publication with no component of ours in between, and without containing ConsoleIn’s identity. Not: the data goes straight from A to B. The architecture controls which messages a service reacts to, not the transport’s routing.

+
+
+

7.3 Intent, Status, Event

+

Three kinds of message, named only after being used:

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
saysour examples
E — Eventsomething happenedTEXT hello as ConsoleIn/E/text; TEXT uryyb as ROT13/E/crypted
S — Status/Statesomething is currently trueROT13/S/subscriptions — not published by our system yet
I — Intentwhat should happenTOPIC consoleIn/outbox, ROUTE … …
+

Past tense is a useful hint for Events. For Intent the test is two questions: does the message report something that happened? No. Something currently true? No. Then it requests behaviour.

+

One trap: publishing an Intent is naturally something that happened. Classify by what the message says, not by the fact that it exists — otherwise every message becomes an Event and the vocabulary stops being useful.

+

Status deserves its own note, because the instinct is to ask for it: “what are your subscriptions?” But asking is a call, and a call needs the asker to know the component, to know it is up, and to wait. Status is published: ROT13 publishes ROT13/S/subscriptions whenever its wiring changes, and anyone interested reads it. The reader then needs a topic, not a component, and ROT13 never learns who audits it. Each kind answers a different question:

+
    +
  • an Event is only useful if you were listening — our stranded messages, three times over;
  • +
  • a Status is what a newcomer needs: the current value, without replaying history;
  • +
  • an Intent asks for a change.
  • +
+

And commands are not forbidden. Sending ROT13/I with ACTION Hello is command-like, and the material’s verdict is “Fine.” The component performs its capability and publishes its Events and its Status. The flow it endorses is Intent → component → State + Events.

+
+
+

7.4 The one-writer rule

+
+

Every writable resource has exactly one writer authority.

+
+

Do not confuse that with the UUID in a message filename. The UUID prevents two publications from choosing the same physical name; writer authority says which component owns a logical Event or Status resource. Two writers never collide on a filename, and that is exactly why the problem is easy to miss.

+

What a second writer costs: the mailbox name was the only provenance marker, so rot13/outbox stops meaning “ROT13 transformed this” and a subscriber can no longer trust the contract it built on. For Status it is worse — two components each claiming to publish the current value of one fact simply contradict each other, with no ordering guarantee across machines to break the tie. For append-only Events many publications coexist by design; the question is semantic ownership, not collision. When two authorities appear, ask why there are two rather than reaching for a lock.

+ + +
+ +
+ + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/_book/07-part-vii-mediation.html b/_book/07-part-vii-mediation.html new file mode 100644 index 0000000..30e2c6e --- /dev/null +++ b/_book/07-part-vii-mediation.html @@ -0,0 +1,1312 @@ + + + + + + + + + +8  Part VII — Now merge the two architectural ideas – Process Control + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + +
+ + + +
+ + +
+
+

8  Part VII — Now merge the two architectural ideas

+
+ + + +
+ + + + +
+ + + +
+ + + +

Two mediators were removed and the gain was measured. Steps 48 to 52 answer the obvious next question: does that make mediation wrong? No — and the distinction that decides it is sharp enough to apply to a design you have never seen.

+
+

8.1 A transformer earns its existence

+

What was removed was a mediator computing A → A: an expensive identity function, in the availability chain, copying every message without adding meaning.

+

Now take a producer publishing {"value":"Hello"} and a consumer expecting a display structure. A TextToDisplayTransformer between them contributes schema transformation, semantic adaptation, possibly unit conversion, possibly aggregation. That is work neither side should own: ROT13 is not meant to decide terminal colours, and the console is not meant to understand ROT13’s payload shape.

+

The line is drawn by contract compatibility, not by whether something is added. A mediator converting Celsius to Fahrenheit changes rather than adds and has earned its place; one appending a timestamp to a message the consumer already understands has added something and is still suspicious. The question is always: could the consumer read the producer’s message as it stands?

+
+

If a consumer semantically understands a producer’s publication, direct subscription is often sufficient. If the contracts are incompatible, introduce a transformer that performs an actual adaptation.

+

A mediator that merely forwards compatible data is suspicious. A mediator that adds necessary semantics has earned its existence.

+
+
+
+

8.2 The transformer is egoistic too

+

Inserted into the chain, the transformer subscribes to rot13/outbox and publishes to its own outbox; ConsoleOut then subscribes to the transformer’s outbox instead of ROT13’s. Note what that costs in code: nothing. ConsoleOut receives a different Intent — TOPIC display/outbox rather than TOPIC rot13/outbox — and the chain is rewired. ROT13 never learns the transformer exists; the transformer never learns ConsoleOut exists.

+

Why not let it publish straight into consoleOut/inbox, saving a mailbox? Four reasons:

+
    +
  • knowledge — it would contain ConsoleOut’s name, which is topology inside a service, the relapse of step 28;
  • +
  • ownership — that inbox is ConsoleOut’s control channel, written by the configurator; payload from the transformer would give it two authorities;
  • +
  • reach — its own outbox can be read by a logger, a web view or a second display at no cost, while one inbox serves exactly one consumer;
  • +
  • mutability — an aggregator can later be inserted after it by sending one different Intent, with no component edited.
  • +
+
+
+

8.3 The complete filesystem architecture

+

Every mailbox with exactly one writer:

+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
mailboxsingle writer
consoleIn/outboxSensorService
rot13/outboxProcessorService
display/outboxthe transformer
every control inboxthe configurator — the one designated Intent authority
the terminalActuatorService, which writes no mailbox at all
+

Egoistic capabilities, Intent from one authority, a transformer only where contracts differ, one writer per resource, and the topology nowhere in the capabilities. That is the design the filesystem was good enough to teach — and the next part asks what the filesystem itself is no longer good enough for.

+ + +
+ +
+ + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/_book/08-part-ix-mqtt.html b/_book/08-part-ix-mqtt.html new file mode 100644 index 0000000..88e958c --- /dev/null +++ b/_book/08-part-ix-mqtt.html @@ -0,0 +1,1547 @@ + + + + + + + + + +9  Part IX — MQTT – Process Control + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + +
+ + + +
+ + +
+
+

9  Part IX — MQTT

+
+ + + +
+ + + + +
+ + + +
+ + + +
+

9.1 What the filesystem taught, and what it is not for

+

The filesystem taught publication boundaries, directories as addresses, observation, independent processes, independent languages, synchronisation latency, runtime wiring, State, Intent, Events, mediator costs, service ownership and transformer services. It was a good teacher and it is not an elegant message broker: by the end the architecture was clean and the transport was a pile of .tmp files, atomic moves, rescanning, shared paths and replication delay.

+

The conclusion is not “files bad, MQTT good”. The filesystem has an advantage MQTT cannot match — it routinely stores gigabytes or terabytes, while brokers and clients are built for small messages, and chunking a huge payload over MQTT means inventing a file-transfer protocol inside a message protocol. So:

+
+

Use messages for coordination and events. Use an appropriate file or object store for large data. A message can carry the location, identity and metadata of that data instead of the terabytes themselves.

+
+

A replicated filesystem also gives every machine a local copy, which is a genuine strength — though replication is not a backup: deletion and corruption replicate too, unless versioning preserves older copies.

+
+
+

9.2 MQTT should look familiar

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
filesystem / SyncthingMQTT
synchronised message-board rootbroker / namespace
directory pathtopic
.msg filepublication
file contentspayload
WatchServicesubscription
dynamic directorytopic / filter
control directoryI
state directoryS/…
event directoryE/…
+

The reaction the material is after: “Oh. We already know this architecture.” MQTT is a transport change, not an architectural claim.

+

Two things a directory could not do, both visible in a minute at the command line. A publication made before a subscriber exists never reaches it — the stranded-message problem for the third time, now with an answer the filesystem never had. And a filter like test/# matches test/a and test/a/b/c but not testing/x, because # works on levels, not string prefixes; test/+ would match only one level down.

+

The deeper correction: a topic is not a container. There is no object called test/a on the broker. A topic is a routing key carried by each publication and matched against the filters of whoever is subscribed at that instant. Directories hold messages; topics match them. One subscription therefore covers topics that do not exist yet — where a message board needed a new directory and a new registration.

+
+
+

9.3 The library, the client id and the broker address

+

Java has no MQTT client in its standard library, so Paho arrives now — after the need, like the mediator in step 7 and Jackson in step 64. Four things are needed from it: connect, publish, subscribe, callback. Connecting is deliberately anticlimactic: “Nothing architectural happened here. We merely attached our process to the transport.”

+

Two details of connecting carry weight:

+
    +
  • the client id is not merely a uniqueness token. The broker recognises a returning client by it and keeps session state for it: subscriptions, messages queued at QoS > 0, and the association with its Last Will. A directory never knew who was watching, which is exactly why a restarted watcher’s backlog was never replayed.
  • +
  • the broker address is deployment configuration: every runnable reads System.getProperty("mqtt.broker", "tcp://localhost:1883"). It is also the one piece of configuration that cannot arrive as Intent, because Intent travels through the broker. Topology can be published; the address of the thing that publishes it cannot.
  • +
+

Subscribing costs one packet, and the broker keeps the subscription list. There is no standard way to ask it what another client subscribed to — which is why S/subscriptions exists: a component’s own declaration of its wiring, published so the architecture can know what the transport keeps private. Only its owner may publish it, by the one-writer rule, because only its owner knows what it accepted.

+
+
+

9.4 Structured Intent, and two object mappers

+

TOPIC some/path has one field and one meaning. It cannot say which kind of Intent this is, carry a second parameter, nest, or be extended; and there is nothing for a receiver to validate against. Richer Intent wants structure:

+
subscribe:
+  topic: Demo/ConsoleIn/U/alice/E/text
+

Only then does a serialisation library have a clear job. JsonTools keeps two mappers, and the asymmetry is deliberate:

+
    +
  • reading uses a YAML factory with FAIL_ON_UNKNOWN_PROPERTIES off — JSON is a subset of YAML, so hand-typed Intent is accepted, and a newer configurator can send fields an older service ignores;
  • +
  • writing uses plain JSON with INDENT_OUTPUT on, so published payloads are strict and readable.
  • +
+

Tolerant in, strict out. A single shared mapper would have to give up one of those.

+
+
+

9.5 DUISE, and rewiring a running system

+

The naming scheme finally gets its name: Description (what contracts this service understands and publishes), Unit (which instance), Intent (requested behaviour), Status (what is true now), Event (what happened).

+
Demo/ROT13/U/alice/{I, S/online, S/subscriptions/text, E/crypted}
+

U/<unit> is what the filesystem never needed: each machine had its own replica of the same relative path, so instance identity was implicit. MQTT has one shared namespace, so a topic must say which copy. Hard-coding U/alice in a capability is therefore worse than hard-coding consoleIn.outbox ever was: it binds the build to one deployment. Configured by Intent, one build serves everyone — which is why MqttConfigure takes three unit names as arguments. The unit names are the topology.

+

Rewiring, observed on a running system: publish a new Intent naming a different source topic, and the service unsubscribes from the old one, subscribes to the new one, and republishes S/subscriptions to match. No restart, no edit. Send an invalid filter instead — Demo/#/E/text, where # is not the last level — and MqttTools.isValidFilter rejects it; the old subscription stands and the Status still tells the truth.

+

That rejection exposes a real gap, worth naming rather than hiding: it is logged locally only. The configurator cannot tell whether its Intent was applied or refused, and a monitor cannot distinguish “refused” from “not yet processed”. In this design a sender learns the outcome by reading Status and comparing it with what it asked for. Publishing refusals as an Event, or a last-error Status, would close that gap; neither is in the material, so it is a design decision to justify.

+
+
+

9.6 What a new subscriber learns, and what a dead one admits

+

Subscribing to Demo/# for three seconds, with nothing being published, returns this:

+
Demo/ROT13/U/nitro5/S/online              {"value":true}
+Demo/ROT13/U/nitro5/S/subscriptions/text  "Demo/ConsoleIn/U/nitro5/E/text"
+Demo/ConsoleOut/U/nitro5/S/online         {"value":true}
+Demo/ConsoleOut/U/nitro5/S/subscriptions/text  "Demo/ROT13/U/nitro5/E/crypted"
+

A late arrival learns the entire current wiring of the system, instantly, without asking anyone and without any component knowing a monitor exists. That is retained Status. No Events arrive, because Events are published non-retained — “retained State, non-retained Events”. It is also the proper answer to the instinct of asking a service what it is doing: nobody asks; the service states it, once, and the broker keeps it for whoever turns up.

+

Retained Status alone would lie, though. Kill a service with Ctrl+C and its S/online = true stays on the broker forever. Hence the Last Will, registered at connect time:

+
var will = new MqttMessage("{\"value\":false}".getBytes(UTF_8), 1, true, new MqttProperties());
+options.setWill(lastWillTopic, will);
+

The will is retained, so when the broker publishes it on the client’s behalf it replaces the stale true. The component that fails is not the component that reports the failure — which is the only arrangement that can work. One caveat: a clean DISCONNECT does not trigger a will, so a well-behaved service publishes online=false itself on the way out, and the will covers the ugly deaths.

+
+
+

9.7 What survived the transport, and what coupling remains

+

The lower half of the filesystem→MQTT table is the point: I, S, E, egoistic services, runtime topology and “transformer if needed” are unchanged. The architecture survived the transport replacement, and that is the strongest available evidence that the architecture was never about the transport.

+

Loose coupling does not mean nothing knows anything. What remains, necessarily, is agreement on: message syntax, message semantics, topic contracts, Intent, ownership, the meaning of State and the meaning of Events. The goal is not to eliminate coupling but to eliminate unnecessary knowledge. Concretely, in this system each service must understand exactly one foreign Event contract — ROT13 understands ConsoleIn’s E/text, ConsoleOut understands ROT13’s E/crypted — plus the Intent schema it accepts on its own I. That list is the irreducible minimum.

+

Separately, the broker is a shared infrastructure dependency: everyone needs its address and nothing works without it. Real, but a different kind of thing from one component knowing another.

+

The step-78 checklist is the tool to keep. Twelve questions, of which these six carry the argument for this system:

+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
questionanswer here
does a capability contain a hard-coded producer identity?no — it arrives as Intent
which foreign contracts must it understand?one Event contract each, plus its own Intent schema
where is topology defined?in the configurator, outside the data path
can topology change without recompiling?yes — demonstrated on a running system
could the transport be replaced?yes — demonstrated, filesystem then MQTT
does every mediator do something that needs mediation?yes, vacuously: TEXT → TEXT needs none, and none exists
+

The material’s own caution applies: the answers need not all be “no”. They need to be intentional.

+
+
+

9.8 The whole journey

+

The program never changed: a line goes in, the same line comes out rotated by 13 letters. What changed, eleven times, is how the parts are joined and who holds the knowledge of how they are joined.

+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
stagehow the parts are joinedwhere the topology livesin the data path besides the capabilities
1 proceduraldirect callsinside the capability code—
2 egoistic servicesnot joined at allnowhere — that is the problem—
3 static mediation, one JVMmailboxes, copied by mediatorsthe mediators, started in main()two mediators
4 static mediation, filesystemdirectories, copied by mediator processesthe operator’s command linestwo mediator processes
5 static mediation, Syncthingreplicated directoriesthe operator’s command linestwo mediator processes, plus replication delay
6 named, configurable mediatorsROUTE Intent from an orchestratorthe orchestrator, outside the paththe mediators, still
7 dynamic, one JVMservices listen, told by TOPIC Intentthe configuratornothing
8 dynamic, filesystemthe same, over directoriesthe configuratornothing
9 dynamic, Syncthingthe same, over replicated directoriesthe configuratornothing — transport hops only
10 contractscompatible: direct; incompatible: a transformerthe configuratora transformer, only where contracts differ
11 MQTTtopics on a brokerthe configuratornothing — the broker is transport
+

Read the third column from top to bottom: the topology moves outward, one stage at a time, until no capability holds any of it. Read the last one: the price of that move falls to zero at stage 7 and stays there while the transport changes underneath three times. Same architecture, better transport.

+
+
+

9.9 The sentences to remember

+
    +
  • Event-driven describes how information and control flow.
  • +
  • Loose coupling describes how much participants need to know about one another.
  • +
  • Publish what happened.
  • +
  • Declare what you want.
  • +
  • Publish your own State.
  • +
  • Keep capabilities egoistic.
  • +
  • Keep topology out of capabilities.
  • +
  • Do not pay for a mediator unless it actually mediates something.
  • +
+

And whenever an architecture becomes confusing, go back to the first question of this book: who knows whom?

+ + +
+ +
+ + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/_book/Process-Control.pdf b/_book/Process-Control.pdf index 372abbc..404f179 100644 Binary files a/_book/Process-Control.pdf and b/_book/Process-Control.pdf differ diff --git a/_book/de/00-orientation.html b/_book/de/00-orientation.html index 2a6ddfe..9374cc8 100644 --- a/_book/de/00-orientation.html +++ b/_book/de/00-orientation.html @@ -52,19 +52,19 @@ ul.task-list li input[type="checkbox"] { - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + - + @@ -87,19 +87,19 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + +
+ + + +
+ + +
+
+

6  Teil V — Die dynamische Idee über Prozesse hinweg wiederholen

+
+ + + +
+ + + + +
+ + + +
+ + + +

Die Schritte 35 bis 38 holen die Abonnement-Idee aus der einzelnen JVM heraus. Die Dienste werden wieder getrennte Programme, aber anstelle von Vermittlern, die Dateien kopieren, beobachtet jeder Dienst das Postfach, das ihm gesagt wurde. Eine Annahme des ersten Dateisystem-Helfers übersteht den Umzug nicht, und genau deren Korrektur ist das Thema dieses Teils.

+
+

6.1 Ein blockierendes watch genügt nicht

+

FileMessageBoard.watch(topic, receiver) registriert ein Verzeichnis und blockiert für immer. Das genügte, solange jeder Prozess ein festes Postfach beobachtete. Ein dynamisch verdrahteter Dienst braucht mehr:

+
dauerhaft das eigene Steuerpostfach beobachten
+UND
+zur Laufzeit ein beobachtetes Verzeichnis hinzufügen
+UND
+es möglicherweise später entfernen
+

Die alte Signatur kann das nicht ausdrücken, und die Folge war schon vorher sichtbar: der konfigurierbare Vermittler nahm genau eine ROUTE an, denn sobald er seine Quelle beobachtete, wurde er für sein eigenes Steuerpostfach taub. Die Grenze war nie, wessen Verzeichnis es ist — sondern eines, festes, für immer.

+
+
+

6.2 Der Helfer: FileSubscriptions

+

Ein WatchService kann viele Verzeichnisse bedienen. register(...) gibt einen WatchKey zurück, der eines davon bezeichnet, watcher.take() liefert den Schlüssel mit Ereignissen, und key.cancel() meldet ihn ab. Der Helfer hält beide Richtungen, Name → Schlüssel und Schlüssel → Name, damit ein Ereignis auf das Postfach zurückgeführt werden kann, aus dem es kam.

+

Ereignisse erreichen keinen Callback direkt. Sie gehen in eine Warteschlange, gelesen mit take(), und tragen

+
record IncomingMessage(String mailbox, Message message) {}
+

Dafür zwei Gründe; die Ankunftsreihenfolge ist nur der dritte. Erstens muss der beobachtende Thread für jedes abonnierte Verzeichnis ansprechbar bleiben: ein Callback, der transformiert, veröffentlicht oder blockiert, hielte die Beobachtung aller anderen auf. Zweitens reist der Postfachname mit der Nachricht, sodass eine Schleife im Dienst deren Bedeutung bestimmen kann — Steuerpostfach, also ein anzuwendender Intent; abonnierte Quelle, also zu transformierende Daten — und dieselbe Schleife darf Abonnements hinzufügen oder entfernen, weil sie nicht in einem Callback feststeckt.

+
+
+

6.3 Zwei Veröffentlichungen statt vier

+

Starten Sie SensorService, DynamicProcessorService und DynamicActuatorService — ohne Vermittler — und lassen Sie dann Configure.java die zwei TOPIC-Nachrichten veröffentlichen. Eine danach getippte Zeile hinterlässt genau zwei Anwendungsveröffentlichungen im Brett:

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PostfachInhaltwas es ist
consoleIn/outboxTEXT hellodie Eingabe
rot13/outboxTEXT uryybdas Ergebnis
rot13/inboxTOPIC consoleIn/outboxIntent, einmal veröffentlicht
consoleOut/inboxTOPIC rot13/outboxIntent, einmal veröffentlicht
+

consoleOut/inbox enthält keine Nutzlast: ConsoleOut nimmt direkt aus rot13/outbox. Sein Postfach wechselte die Aufgabe, von Nachrichten zu Verdrahtung.

+

Eine Zeile, die vor dem Lauf von Configure.java getippt wurde, bleibt für immer in consoleIn/outbox. Ein Abonnement, das noch nicht existiert, verpasst, was ihm vorausging — dieselbe Lehre wie beim neu gestarteten Vermittler, der nichts auslieferte.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
FassungAnwendungsveröffentlichungenProzesse im Datenpfad
vermittelt (Schritt 18)45
konfigurierbarer Vermittler (Schritt 27)45
dynamisch (Schritt 38)23
+ + +
+ +
+ + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/_book/de/06-part-vi-vocabulary.html b/_book/de/06-part-vi-vocabulary.html new file mode 100644 index 0000000..bf4e2d3 --- /dev/null +++ b/_book/de/06-part-vi-vocabulary.html @@ -0,0 +1,1324 @@ + + + + + + + + + +7  Teil VI — Über Syncthing wiederholen und die Nachrichten benennen – Prozesssteuerung + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + +
+ + + +
+ + +
+
+

7  Teil VI — Über Syncthing wiederholen und die Nachrichten benennen

+
+ + + +
+ + + + +
+ + + +
+ + + +

Die Schritte 39 bis 47 verteilen die dynamische Fassung auf zwei Maschinen, sagen genau, was „direkt” bedeutet, und geben dann — erst jetzt, nachdem die Ideen benutzt wurden — den drei Nachrichtenarten ihre Namen: Intent, Status, Event.

+
+

7.1 Der verteilte dynamische Lauf

+

Sensor auf einer Maschine, ROT13 und der Aktor auf der anderen, nirgends ein Vermittler. Nachdem die zwei TOPIC-Intents repliziert waren, erzeugte eine getippte Zeile das Ergebnis auf der anderen Maschine — und das Brett zeigt die Kosten:

+
    +
  • consoleIn/outbox: die Eingabe;
  • +
  • rot13/outbox: das Ergebnis, geschrieben von dem Dienst, der es erzeugt hat;
  • +
  • consoleOut/inbox: nur Intent, wo die vermittelte Fassung eine vollständige Kopie jeder Nachricht hielt.
  • +
+

Spannend war die Zeit. Die Eingabe wurde um 02:35:12 veröffentlicht, die Ergebnisse erschienen auf der ersten Maschine um 04:11:28,797 und ,893 — 96 ms auseinander, lange nach der Eingabe. Syncthing war über Nacht überlastet; der Stapel kam, als die Warteschlange abfloss. Die Kette war durchgehend korrekt; die Latenz des Transports steuert die Architektur nicht. Zum Vergleich: 24 ms für dieselbe Kette auf einer Maschine.

+
+
+

7.2 Was „direkt” genau bedeutet

+

Zwei Sprünge, die gleich aussehen, sind architektonisch Gegensätze:

+
    +
  • ein Transportsprung — Syncthing auf jeder Seite, möglicherweise ein Relay dazwischen — fügt keinen Beteiligten hinzu, der die Topologie kennt, und nichts reagiert darauf. Liefen die Pakete über einen anderen Kontinent, widerspräche das keiner Aussage hier.
  • +
  • ein architektonischer Sprung — ein Vermittler, der consoleIn/outbox → rot13/inbox kopiert — fügt eine Komponente hinzu, die beide Namen kennen muss, in der Verfügbarkeitskette steht und die Nachricht erneut veröffentlicht.
  • +
+

Die vertretbare Aussage lautet daher: ROT13 reagiert auf ConsoleIns Veröffentlichung, ohne eine unserer Komponenten dazwischen und ohne ConsoleIns Identität zu enthalten. Nicht: die Daten gehen direkt von A nach B. Die Architektur bestimmt, auf welche Nachrichten ein Dienst reagiert, nicht die Wegewahl des Transports.

+
+
+

7.3 Intent, Status, Event

+

Drei Nachrichtenarten, benannt erst nach ihrem Gebrauch:

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + +
sagtunsere Beispiele
E — Eventetwas ist geschehenTEXT hello als ConsoleIn/E/text; TEXT uryyb als ROT13/E/crypted
S — Status/Stateetwas ist gerade wahrROT13/S/subscriptions — von unserem System noch nicht veröffentlicht
I — Intentwas geschehen sollTOPIC consoleIn/outbox, ROUTE … …
+

Vergangenheitsform ist ein nützlicher Hinweis für Events. Für Intent lautet der Test zwei Fragen: berichtet die Nachricht etwas Geschehenes? Nein. Etwas gerade Wahres? Nein. Dann verlangt sie Verhalten.

+

Eine Falle: einen Intent zu veröffentlichen ist natürlich etwas Geschehenes. Eingeordnet wird nach dem, was die Nachricht sagt, nicht nach ihrer Existenz — sonst wird alles zum Event und das Vokabular nützt nichts mehr.

+

Status verdient eine eigene Anmerkung, denn der Instinkt ist, ihn zu erfragen: „welche Abonnements hast du?” Doch Fragen ist ein Aufruf, und ein Aufruf verlangt, dass der Fragende die Komponente kennt, sie als laufend weiss und wartet. Status wird veröffentlicht: ROT13 veröffentlicht ROT13/S/subscriptions, sobald sich seine Verdrahtung ändert, und wer will, liest es. Der Leser braucht dann ein Topic, keine Komponente, und ROT13 erfährt nie, wer es prüft. Jede Art beantwortet eine andere Frage:

+
    +
  • ein Event nützt nur, wenn man zuhörte — unsere liegengebliebenen Nachrichten, dreimal;
  • +
  • ein Status ist, was ein Neuankömmling braucht: der aktuelle Wert, ohne Geschichte nachzuspielen;
  • +
  • ein Intent verlangt eine Änderung.
  • +
+

Und Kommandos sind nicht verboten. ROT13/I mit ACTION Hello zu senden ist kommandoartig, und das Urteil des Materials lautet „Fine.” Die Komponente übt ihre Fähigkeit aus und veröffentlicht ihre Events und ihren Status. Der empfohlene Fluss ist Intent → Komponente → State + Events.

+
+
+

7.4 Die Ein-Schreiber-Regel

+
+

Jede schreibbare Ressource hat genau eine Schreibautorität.

+
+

Nicht zu verwechseln mit der UUID im Dateinamen. Die UUID verhindert, dass zwei Veröffentlichungen denselben physischen Namen wählen; die Schreibautorität sagt, welche Komponente eine logische Event- oder Status-Ressource besitzt. Zwei Schreiber kollidieren nie bei einem Dateinamen — genau deshalb wird das Problem leicht übersehen.

+

Was ein zweiter Schreiber kostet: der Postfachname war der einzige Herkunftsnachweis, also bedeutet rot13/outbox nicht mehr „ROT13 hat dies transformiert”, und ein Abonnent kann dem Vertrag nicht mehr trauen, auf dem er aufbaut. Für Status ist es schlimmer — zwei Komponenten, die je den aktuellen Wert eines Faktes zu veröffentlichen behaupten, widersprechen sich, ohne Reihenfolgegarantie zwischen Maschinen, die entscheiden könnte. Bei append-only Events koexistieren viele Veröffentlichungen absichtlich; die Frage ist semantischer Besitz, nicht Kollision. Treten zwei Autoritäten auf, frage nach dem Warum, statt zum Lock zu greifen.

+ + +
+ +
+ + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/_book/de/07-part-vii-mediation.html b/_book/de/07-part-vii-mediation.html new file mode 100644 index 0000000..da2dcb5 --- /dev/null +++ b/_book/de/07-part-vii-mediation.html @@ -0,0 +1,1312 @@ + + + + + + + + + +8  Teil VII — Die zwei architektonischen Ideen zusammenführen – Prozesssteuerung + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + +
+ + + +
+ + +
+
+

8  Teil VII — Die zwei architektonischen Ideen zusammenführen

+
+ + + +
+ + + + +
+ + + +
+ + + +

Zwei Vermittler wurden entfernt und der Gewinn gemessen. Die Schritte 48 bis 52 beantworten die naheliegende nächste Frage: ist Vermittlung damit falsch? Nein — und die entscheidende Unterscheidung ist scharf genug, um sie auf einen fremden Entwurf anzuwenden.

+
+

8.1 Ein Transformator verdient seine Existenz

+

Entfernt wurde ein Vermittler, der A → A berechnete: eine teure Identitätsfunktion in der Verfügbarkeitskette, die jede Nachricht ohne Bedeutungsgewinn kopierte.

+

Nun ein Produzent, der {"value":"Hello"} veröffentlicht, und ein Konsument, der eine Anzeigestruktur erwartet. Ein TextToDisplayTransformer dazwischen leistet Schematransformation, semantische Anpassung, möglicherweise Einheitenumrechnung, möglicherweise Aggregation. Das ist Arbeit, die keine der beiden Seiten besitzen sollte: ROT13 hat nicht über Terminalfarben zu entscheiden, und die Konsole hat die Nutzlastform von ROT13 nicht zu verstehen.

+

Die Grenze zieht die Vertragskompatibilität, nicht die Frage, ob etwas hinzukommt. Ein Vermittler, der Celsius in Fahrenheit umrechnet, ändert statt hinzuzufügen und hat seinen Platz verdient; einer, der einer schon verstandenen Nachricht einen Zeitstempel anhängt, hat etwas hinzugefügt und bleibt verdächtig. Die Frage ist immer: könnte der Konsument die Nachricht des Produzenten so lesen, wie sie ist?

+
+

Versteht ein Konsument die Veröffentlichung eines Produzenten semantisch, genügt direktes Abonnieren oft. Sind die Verträge inkompatibel, führe einen Transformator ein, der eine echte Anpassung leistet.

+

Ein Vermittler, der nur kompatible Daten weiterleitet, ist verdächtig. Ein Vermittler, der nötige Semantik hinzufügt, hat seine Existenz verdient.

+
+
+
+

8.2 Auch der Transformator ist egoistisch

+

In die Kette eingefügt, abonniert der Transformator rot13/outbox und veröffentlicht in sein eigenes Ausgangspostfach; ConsoleOut abonniert dann dieses statt das von ROT13. Was das an Code kostet: nichts. ConsoleOut erhält einen anderen Intent — TOPIC display/outbox statt TOPIC rot13/outbox — und die Kette ist umverdrahtet. ROT13 erfährt nie, dass der Transformator existiert; der Transformator nie, dass ConsoleOut existiert.

+

Warum nicht direkt in consoleOut/inbox veröffentlichen und ein Postfach sparen? Vier Gründe:

+
    +
  • Wissen — er enthielte ConsoleOuts Namen, also Topologie in einem Dienst, der Rückfall von Schritt 28;
  • +
  • Besitz — dieses Postfach ist ConsoleOuts Steuerkanal, geschrieben vom Konfigurator; Nutzlast vom Transformator gäbe ihm zwei Autoritäten;
  • +
  • Reichweite — sein eigenes Ausgangspostfach kann ein Logger, eine Webansicht oder ein zweites Display kostenlos lesen, während ein Eingangspostfach genau einen Konsumenten bedient;
  • +
  • Veränderbarkeit — ein Aggregator lässt sich danach durch einen anderen Intent einfügen, ohne eine Komponente zu ändern.
  • +
+
+
+

8.3 Die vollständige Dateisystem-Architektur

+

Jedes Postfach mit genau einem Schreiber:

+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Postfacheinziger Schreiber
consoleIn/outboxSensorService
rot13/outboxProcessorService
display/outboxder Transformator
jedes Steuerpostfachder Konfigurator — die eine bestimmte Intent-Autorität
das TerminalActuatorService, der kein Postfach schreibt
+

Egoistische Fähigkeiten, Intent aus einer Autorität, ein Transformator nur dort, wo Verträge sich unterscheiden, ein Schreiber pro Ressource, und die Topologie nirgends in den Fähigkeiten. Das ist der Entwurf, den das Dateisystem gut genug war zu lehren — und der nächste Teil fragt, wofür das Dateisystem selbst nicht mehr gut genug ist.

+ + +
+ +
+ + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/_book/de/08-part-ix-mqtt.html b/_book/de/08-part-ix-mqtt.html new file mode 100644 index 0000000..2e159af --- /dev/null +++ b/_book/de/08-part-ix-mqtt.html @@ -0,0 +1,1547 @@ + + + + + + + + + +9  Teil IX — MQTT – Prozesssteuerung + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + +
+ + + +
+ + +
+
+

9  Teil IX — MQTT

+
+ + + +
+ + + + +
+ + + +
+ + + +
+

9.1 Was das Dateisystem gelehrt hat und wofür es nicht taugt

+

Das Dateisystem lehrte Veröffentlichungsgrenzen, Verzeichnisse als Adressen, Beobachtung, unabhängige Prozesse, unabhängige Sprachen, Synchronisationslatenz, Verdrahtung zur Laufzeit, State, Intent, Events, Vermittlerkosten, Dienstbesitz und Transformatordienste. Es war ein guter Lehrer und ist kein eleganter Nachrichten-Broker: am Ende war die Architektur sauber und der Transport ein Haufen .tmp-Dateien, atomarer Verschiebungen, erneuter Scans, geteilter Pfade und Replikationsverzögerung.

+

Die Schlussfolgerung ist nicht „Dateien schlecht, MQTT gut”. Das Dateisystem hat einen Vorteil, den MQTT nicht erreicht — es speichert routinemässig Gigabytes bis Terabytes, während Broker und Clients für kleine Nachrichten gebaut sind, und das Stückeln einer riesigen Nutzlast über MQTT heisst, ein Dateitransferprotokoll in einem Nachrichtenprotokoll zu erfinden. Also:

+
+

Nachrichten für Koordination und Ereignisse. Für grosse Daten ein passender Datei- oder Objektspeicher. Eine Nachricht kann Ort, Identität und Metadaten dieser Daten tragen statt der Terabytes selbst.

+
+

Ein repliziertes Dateisystem gibt zudem jeder Maschine eine lokale Kopie, eine echte Stärke — doch Replikation ist kein Backup: Löschungen und Beschädigungen replizieren mit, sofern nicht eine Versionierung ältere Kopien bewahrt.

+
+
+

9.2 MQTT sollte vertraut wirken

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Dateisystem / SyncthingMQTT
Wurzel des synchronisierten NachrichtenbrettsBroker / Namensraum
VerzeichnispfadTopic
.msg-DateiVeröffentlichung
DateiinhaltNutzlast
WatchServiceAbonnement
dynamisches VerzeichnisTopic / Filter
SteuerverzeichnisI
ZustandsverzeichnisS/…
EreignisverzeichnisE/…
+

Die gewünschte Reaktion des Materials: „Ach. Diese Architektur kennen wir schon.” MQTT ist ein Transportwechsel, keine architektonische Aussage.

+

Zwei Dinge, die ein Verzeichnis nicht konnte, in einer Minute auf der Kommandozeile sichtbar. Eine Veröffentlichung vor der Existenz eines Abonnenten erreicht ihn nie — die Lehre der liegengebliebenen Nachrichten zum dritten Mal, nun mit einer Antwort, die das Dateisystem nie hatte. Und ein Filter wie test/# passt auf test/a und test/a/b/c, nicht aber auf testing/x, weil # auf Ebenen arbeitet, nicht auf Zeichenpräfixen; test/+ passte nur eine Ebene tief.

+

Die tiefere Korrektur: ein Topic ist kein Behälter. Es gibt kein Objekt namens test/a auf dem Broker. Ein Topic ist ein Routing-Schlüssel, den jede Veröffentlichung trägt und der gegen die Filter derjenigen geprüft wird, die in diesem Moment abonniert haben. Verzeichnisse halten Nachrichten; Topics vergleichen sie. Ein Abonnement deckt daher Topics ab, die noch nicht existieren — wo ein Nachrichtenbrett ein neues Verzeichnis und eine neue Registrierung brauchte.

+
+
+

9.3 Die Bibliothek, die Client-ID und die Broker-Adresse

+

Java hat keinen MQTT-Client in der Standardbibliothek, also kommt Paho jetzt — nach dem Bedarf, wie der Vermittler in Schritt 7 und Jackson in Schritt 64. Vier Dinge braucht man: verbinden, veröffentlichen, abonnieren, Rückruf. Das Verbinden ist absichtlich unspektakulär: „Hier ist architektonisch nichts geschehen. Wir haben unseren Prozess nur an den Transport angeschlossen.”

+

Zwei Details des Verbindens haben Gewicht:

+
    +
  • die Client-ID ist nicht bloss ein Eindeutigkeitsmerkmal. Der Broker erkennt daran einen zurückkehrenden Client und hält Sitzungszustand für ihn: Abonnements, bei QoS > 0 eingereihte Nachrichten und die Verknüpfung mit seinem Last Will. Ein Verzeichnis wusste nie, wer es beobachtete — genau deshalb spielte ein neu gestarteter Beobachter nichts nach.
  • +
  • die Broker-Adresse ist Deployment-Konfiguration: jedes Programm liest System.getProperty("mqtt.broker", "tcp://localhost:1883"). Sie ist auch die einzige Konfiguration, die nicht als Intent kommen kann, denn Intent reist durch den Broker. Topologie lässt sich veröffentlichen; die Adresse des Veröffentlichenden nicht.
  • +
+

Abonnieren kostet ein Paket, und der Broker führt die Abonnementliste. Es gibt keinen Standardweg, ihn zu fragen, was ein anderer Client abonniert hat — daher S/subscriptions: die eigene Erklärung einer Komponente über ihre Verdrahtung, veröffentlicht, damit die Architektur weiss, was der Transport privat hält. Nur ihr Eigentümer darf sie veröffentlichen, nach der Ein-Schreiber-Regel, denn nur er weiss, was er angenommen hat.

+
+
+

9.4 Strukturierter Intent und zwei Mapper

+

TOPIC some/path hat ein Feld und eine Bedeutung. Es kann nicht sagen, welche Art Intent vorliegt, keinen zweiten Parameter tragen, nicht verschachteln, nicht erweitert werden; und ein Empfänger hat nichts, wogegen er prüfen könnte. Reicherer Intent braucht Struktur:

+
subscribe:
+  topic: Demo/ConsoleIn/U/alice/E/text
+

Erst dann hat eine Serialisierungsbibliothek eine klare Aufgabe. JsonTools hält zwei Mapper, und die Asymmetrie ist Absicht:

+
    +
  • das Lesen nutzt eine YAML-Factory mit abgeschaltetem FAIL_ON_UNKNOWN_PROPERTIES — JSON ist eine Teilmenge von YAML, handgetippter Intent wird akzeptiert, und ein neuerer Konfigurator darf Felder senden, die ein älterer Dienst ignoriert;
  • +
  • das Schreiben nutzt strenges JSON mit INDENT_OUTPUT, die veröffentlichten Nutzlasten sind also streng und lesbar.
  • +
+

Tolerant hinein, streng hinaus. Ein einziger Mapper müsste auf eines davon verzichten.

+
+
+

9.5 DUISE und das Umverdrahten im Betrieb

+

Das Namensschema erhält endlich seinen Namen: Description (welche Verträge dieser Dienst versteht und veröffentlicht), Unit (welche Instanz), Intent (gewünschtes Verhalten), Status (was jetzt gilt), Event (was geschehen ist).

+
Demo/ROT13/U/alice/{I, S/online, S/subscriptions/text, E/crypted}
+

U/<unit> brauchte das Dateisystem nie: jede Maschine hatte ihr eigenes Replikat desselben relativen Pfades, Instanzidentität war implizit. MQTT hat einen gemeinsamen Namensraum, ein Topic muss also sagen, welche Kopie. U/alice in einer Fähigkeit festzuschreiben ist daher schlimmer, als consoleIn.outbox es je war: es bindet das Build an ein Deployment. Per Intent konfiguriert, dient ein Build allen — daher die drei Unit-Namen als Argumente von MqttConfigure. Die Unit-Namen sind die Topologie.

+

Umverdrahten, am laufenden System beobachtet: einen neuen Intent mit anderer Quelle veröffentlichen, und der Dienst kündigt die alte, abonniert die neue und veröffentlicht S/subscriptions passend neu. Kein Neustart, keine Änderung. Schickt man stattdessen einen ungültigen Filter — Demo/#/E/text, wo # nicht die letzte Ebene ist — weist MqttTools.isValidFilter ihn ab; das alte Abonnement bleibt, und der Status sagt weiter die Wahrheit.

+

Diese Abweisung legt eine echte Lücke offen, die man benennen und nicht verstecken sollte: sie wird nur lokal protokolliert. Der Konfigurator erfährt nicht, ob sein Intent angewandt oder abgelehnt wurde, und ein Monitor kann „abgelehnt” nicht von „noch nicht verarbeitet” unterscheiden. In diesem Entwurf erfährt ein Sender das Ergebnis, indem er den Status liest und mit seiner Anfrage vergleicht. Abweisungen als Event zu veröffentlichen oder ein Letzter-Fehler-Status würden die Lücke schliessen; beides steht nicht im Material — es ist eine zu begründende Entwurfsentscheidung.

+
+
+

9.6 Was ein neuer Abonnent erfährt und was ein Toter zugibt

+

Drei Sekunden Demo/# abonnieren, ohne dass etwas veröffentlicht wird, ergibt dies:

+
Demo/ROT13/U/nitro5/S/online              {"value":true}
+Demo/ROT13/U/nitro5/S/subscriptions/text  "Demo/ConsoleIn/U/nitro5/E/text"
+Demo/ConsoleOut/U/nitro5/S/online         {"value":true}
+Demo/ConsoleOut/U/nitro5/S/subscriptions/text  "Demo/ROT13/U/nitro5/E/crypted"
+

Ein Spätankömmling erfährt augenblicklich die gesamte aktuelle Verdrahtung des Systems, ohne jemanden zu fragen und ohne dass eine Komponente von einem Monitor weiss. Das ist retained Status. Keine Events kommen an, denn Events werden nicht retained veröffentlicht — „retained State, nicht retained Events”. Es ist auch die richtige Antwort auf den Reflex, einen Dienst zu fragen, was er tut: niemand fragt; der Dienst erklärt es einmal, und der Broker bewahrt es für jeden, der kommt.

+

Retained Status allein würde allerdings lügen. Beendet man einen Dienst mit Ctrl+C, bleibt sein S/online = true für immer beim Broker. Daher der Last Will, bei der Verbindung registriert:

+
var will = new MqttMessage("{\"value\":false}".getBytes(UTF_8), 1, true, new MqttProperties());
+options.setWill(lastWillTopic, will);
+

Der Will ist retained, ersetzt also beim Veröffentlichen durch den Broker das veraltete true. Die Komponente, die ausfällt, ist nicht die, die den Ausfall meldet — die einzige Anordnung, die funktionieren kann. Ein Vorbehalt: ein sauberes DISCONNECT löst keinen Will aus; ein gut erzogener Dienst veröffentlicht daher beim Beenden selbst online=false, und der Will deckt die hässlichen Tode.

+
+
+

9.7 Was den Transport überlebte und welche Kopplung bleibt

+

Die untere Hälfte der Tabelle Dateisystem→MQTT ist der Punkt: I, S, E, egoistische Dienste, Topologie zur Laufzeit und „Transformator wenn nötig” sind unverändert. Die Architektur überlebte den Transportwechsel, und das ist der stärkste verfügbare Beleg, dass sie nie am Transport hing.

+

Lose Kopplung heisst nicht, dass nichts etwas weiss. Notwendig bleibt die Einigkeit über: Nachrichtensyntax, Nachrichtensemantik, Topic-Verträge, Intent, Besitz, Bedeutung von State und Bedeutung von Events. Ziel ist nicht, Kopplung zu beseitigen, sondern unnötiges Wissen zu beseitigen. Konkret muss hier jeder Dienst genau einen fremden Event-Vertrag verstehen — ROT13 den E/text von ConsoleIn, ConsoleOut den E/crypted von ROT13 — plus das Intent-Schema, das er auf seinem eigenen I annimmt. Diese Liste ist das unverzichtbare Minimum.

+

Davon getrennt: der Broker ist eine geteilte Infrastrukturabhängigkeit; alle brauchen seine Adresse, und ohne ihn läuft nichts. Real, aber anderer Art als das Wissen einer Komponente über eine andere.

+

Die Prüfliste aus Schritt 78 ist das Werkzeug, das bleibt. Zwölf Fragen, von denen diese sechs das Argument dieses Systems tragen:

+ ++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FrageAntwort hier
enthält eine Fähigkeit eine festgeschriebene Produzentenidentität?nein — sie kommt als Intent
welche fremden Verträge muss sie verstehen?je einen Event-Vertrag, plus ihr eigenes Intent-Schema
wo ist die Topologie definiert?im Konfigurator, ausserhalb des Datenpfads
kann sich die Topologie ohne Neukompilieren ändern?ja — am laufenden System gezeigt
könnte der Transport ersetzt werden?ja — gezeigt: Dateisystem, dann MQTT
leistet jeder Vermittler etwas, das Vermittlung braucht?ja, trivial: TEXT → TEXT braucht keine, und es gibt keinen
+

Die Mahnung des Materials gilt: die Antworten müssen nicht alle „nein” lauten. Sie müssen absichtlich sein.

+
+
+

9.8 Der ganze Weg

+

Das Programm hat sich nie geändert: eine Zeile geht hinein, dieselbe kommt um 13 Buchstaben verschoben heraus. Geändert hat sich, elfmal, wie die Teile verbunden sind und wer das Wissen über diese Verbindung hält.

+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Stufewie die Teile verbunden sindwo die Topologie liegtim Datenpfad ausser den Fähigkeiten
1 prozeduraldirekte Aufrufeim Code der Fähigkeit—
2 egoistische Dienstegar nicht verbundennirgends — das ist das Problem—
3 statische Vermittlung, eine JVMPostfächer, von Vermittlern kopiertdie Vermittler, gestartet in main()zwei Vermittler
4 statische Vermittlung, DateisystemVerzeichnisse, von Vermittlerprozessen kopiertdie Befehlszeilen des Bedienerszwei Vermittlerprozesse
5 statische Vermittlung, Syncthingreplizierte Verzeichnissedie Befehlszeilen des Bedienerszwei Vermittlerprozesse, dazu Replikationsverzögerung
6 benannte, konfigurierbare VermittlerROUTE-Intent von einem Orchestratorder Orchestrator, ausserhalb des Pfadsweiterhin die Vermittler
7 dynamisch, eine JVMdie Dienste hören selbst, gesteuert durch TOPIC-Intentder Konfiguratornichts
8 dynamisch, Dateisystemdasselbe, über Verzeichnisseder Konfiguratornichts
9 dynamisch, Syncthingdasselbe, über replizierte Verzeichnisseder Konfiguratornichts — nur Transportsprünge
10 Verträgekompatibel: direkt; inkompatibel: ein Transformatorder Konfiguratorein Transformator, nur wo Verträge sich unterscheiden
11 MQTTTopics auf einem Brokerder Konfiguratornichts — der Broker ist Transport
+

Die dritte Spalte von oben nach unten gelesen: die Topologie wandert nach aussen, Stufe um Stufe, bis keine Fähigkeit mehr etwas davon hält. Die letzte gelesen: der Preis dieser Wanderung fällt in Stufe 7 auf null und bleibt dort, während darunter dreimal der Transport wechselt. Dieselbe Architektur, besserer Transport.

+
+
+

9.9 Die Sätze, die man behalten sollte

+
    +
  • „Event-driven” beschreibt, wie Information und Steuerung fliessen.
  • +
  • Lose Kopplung beschreibt, wie viel die Beteiligten voneinander wissen müssen.
  • +
  • Veröffentliche, was geschehen ist.
  • +
  • Erkläre, was du willst.
  • +
  • Veröffentliche deinen eigenen Zustand.
  • +
  • Halte Fähigkeiten egoistisch.
  • +
  • Halte die Topologie aus den Fähigkeiten heraus.
  • +
  • Bezahle keinen Vermittler, der nicht wirklich vermittelt.
  • +
+

Und wann immer eine Architektur verwirrend wird, zurück zur ersten Frage dieses Buches: wer kennt wen?

+ + +
+ +
+ + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/_book/de/Prozesssteuerung.pdf b/_book/de/Prozesssteuerung.pdf index 64ada73..567c39d 100644 Binary files a/_book/de/Prozesssteuerung.pdf and b/_book/de/Prozesssteuerung.pdf differ diff --git a/_book/de/glossary.html b/_book/de/glossary.html index 10bb408..a726404 100644 --- a/_book/de/glossary.html +++ b/_book/de/glossary.html @@ -36,7 +36,7 @@ ul.task-list li input[type="checkbox"] { - + @@ -51,19 +51,19 @@ ul.task-list li input[type="checkbox"] { - - - - - - - - - - - - - + + + + + + + + + + + + +