Chapter 18
Reject an unknown route
Ask the router to report an unknown destination.
Compare how the same send behaves when route checking is enabled or disabled.
Prerequisite: Route an envelope. Course map →
The situation
A router sends a result to a worker that has disappeared. The caller assumes a successful API return proves delivery.
A ROUTER socket can accept a send call and silently discard a reply when the address is unknown. ROUTER_MANDATORY makes this send report EHOSTUNREACH, which means the socket cannot find the destination. An existing route only tells you the socket has a connection to use.
- ROUTER_MANDATORY=1EHOSTUNREACHThe send reports that the route is missing.
- Default behaviorMay discard silentlyAPI acceptance is not delivery evidence.
Conceptual diagram. These are alternative settings for the actual ROUTER experiment. Neither proves application completion on an existing route.
Before you run
What does the router report when the required destination does not exist?
Run the experiment
No clients connect. The router tries to send a message to an address called unknown.
For the original example, click Restore code if it is shown, then click Run. Compare your output with the worked result.
Python prepares in the background while you read. First use can download about 71 MiB. Your code runs only when you select Run; each run starts with clean experiment state.
Your edits are saved in this browser when storage is available.
Full error details
Run output
Troubleshooting
If Python stops responding, restart the environment and try again. Your code and last completed result are kept.
Downloads
Worked result
outcome is EHOSTUNREACH with route checking enabled. It identifies the reason this send could not be routed.
Full output from the original example
{
"mandatory": true,
"outcome": "EHOSTUNREACH"
}The build ran the original editor code to produce this output.
Try one change
Replace the last line with result = mandatory(enabled=False) and click Run again. Read outcome in both results. Which setting signals that no such route exists?
Inspect the socket implementation
The editor calls this read-only helper. Read all socket helpers or read the separate-process code. The code download includes both files.
def mandatory(enabled=True):
with lab() as socket:
router=socket(zmq.ROUTER);router.router_mandatory=int(enabled);router.bind('inproc://missing')
try:router.send_multipart([b'unknown',b'payload'],zmq.DONTWAIT);outcome='send accepted without delivery evidence'
except zmq.ZMQError as e:
if e.errno!=zmq.EHOSTUNREACH:raise
outcome='EHOSTUNREACH'
return {'mandatory':enabled,'outcome':outcome}
Costs, waiting and recovery
| Aspect | What to account for |
|---|---|
| Work | The router checks which connection can receive the reply. |
| Stored information | Each connected peer can have its own queue. |
| Message path | A missing route is detected by the local socket. |
| Waiting | A sender can handle a missing route differently from a full queue or a timeout. |
| Recovery | Reuse a stable request ID when resending a request to avoid repeating its effect. |
Check your understanding
Does enabling ROUTER_MANDATORY make a reply to an existing route an application acknowledgement?
Show hints
Hint 1
Which part of the system reports a missing route?
Hint 2
Where would you get evidence that a connected peer handled a request?
Show explanation
Route checking reports that the address cannot be found. To check that a real receiver handled the request, define a reply that identifies the request and records its outcome.
ReferencesFunction documentation and helper source
References open in a new tab; course helpers are documented separately from library APIs. PyZMQ API links use version 27.3.0. ZeroMQ manuals are pinned to libzmq 4.3.5.
Make missing routes observable
SocketOption.ROUTER_MANDATORY(new tab)Socket.send_multipart(new tab)libzmq ZMQ_ROUTER_MANDATORY (4.3.5)(new tab)Read the behavior when a ROUTER has no route for the supplied identity.
Course helper implementation
These are functions written for this course, not additional library APIs. Inspect their parameters, operator calls and authored policies. The source shown is generated from the same Python files packaged with Run and Download Python.
Experiment scope
The example sends to an address with no connected peer. A send during a real disconnect can require separate testing.
ZeroMQ reference · Runtime and model boundaries