Skip to content

feat(amgi-paho-mqtt): add message send manager - #124

Merged
TomKimber merged 1 commit into
mainfrom
feat/add-paho-mqtt-message-send-manager
Oct 13, 2026
Merged

TomKimber merged 1 commit into
mainfrom
feat/add-paho-mqtt-message-send-manager

Conversation

@TomKimber

@TomKimber TomKimber commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Add Portable Senders support to amgi-paho-mqtt: #72.

This adds a MessageSend async context manager to amgi-paho-mqtt. It handles message.send events on its own paho client and connection instead of reusing the consuming client. It waits for the CONNACK on entry and raises on a broker rejection or a timeout (connect_timeout, default 10s). Each send waits for the broker’s acknowledgement and raises PublishError on failure. The mqtt binding now supports retain as well as qos. With MQTT v5, headers are sent as user properties and content-type maps to the MQTT content type property. MQTT v3.1.1 cannot represent headers, so they are dropped. run() and Server accept an optional message_send manager and connect_timeout.

To share the logic, the asyncio socket, publish and disconnect handling moved out of Server into a _ClientLoop helper that both clients use. It also adds reconnection after unexpected disconnects, which retries every second and logs failures to amgi-paho-mqtt.error. On event loops without add_reader/add_writer, such as the default Proactor loop on Windows, a _SocketWatcher fallback watches the socket from a background thread and runs paho's read and write handlers on the event loop. Previously the package failed on Windows with NotImplementedError. A blocking connect that is abandoned by a timeout or cancellation but later succeeds is now disconnected rather than leaked. The amgi_server entry point now points at a thin _run_cli wrapper, and typing-extensions is added for Python < 3.11. The README has a new “Sending Messages” section, and there are new unit tests plus a broker-backed integration test.

amgi-paho-mqtt is the only gap - Confirmed all other packages have a consistent portable senders implementation.

Copilot AI balanced review requested due to automatic review settings October 9, 2026 23:49
@read-the-docs-community

read-the-docs-community Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 AMGI | 🛠️ Build #35127415 | 📁 Comparing d2454ef against latest (7f72e38)

  🔍 Preview build  

3 files changed
± specifications/bindings.html
± specifications/lifespan.html
± specifications/message.html

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Connection and publish failures can leave sender initialization or in-flight publishes hanging indefinitely.

1 open finding
What changed in this PR

Adds portable MQTT message-sender support with injectable lifecycle management.

Changes:

  • Introduces MessageSend and shared asynchronous MQTT client-loop handling.
  • Adds sender injection and a CLI-safe wrapper.
  • Adds unit/integration coverage and Python 3.10 typing support.
File Description
uv.lock Locks the conditional typing dependency.
test_mqtt_message.py Tests send dispatch and initialization requirements.
test_mqtt_message_integration.py Tests sender injection, lifecycle, and CLI execution.
amgi_paho_mqtt/​__init__.py Implements portable sending and lifecycle integration.
pyproject.toml Adds typing support and updates the CLI entry point.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/amgi-paho-mqtt/src/amgi_paho_mqtt/__init__.py
@TomKimber
TomKimber force-pushed the feat/add-paho-mqtt-message-send-manager branch from e7246c2 to ab15597 Compare October 9, 2026 23:58
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TomKimber
TomKimber force-pushed the feat/add-paho-mqtt-message-send-manager branch 2 times, most recently from c0321e3 to 148770e Compare October 10, 2026 19:32
@TomKimber
TomKimber requested a balanced review from Copilot October 10, 2026 19:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Non-cancellable connection workers and unhandled entry cancellation can leak MQTT connections during timeout or shutdown.

3 open findings
1 resolved since last review

🧠 Review effort: Balanced

Comment thread packages/amgi-paho-mqtt/src/amgi_paho_mqtt/__init__.py
Comment thread packages/amgi-paho-mqtt/src/amgi_paho_mqtt/__init__.py Outdated
Comment thread packages/amgi-paho-mqtt/src/amgi_paho_mqtt/__init__.py
@TomKimber
TomKimber force-pushed the feat/add-paho-mqtt-message-send-manager branch 5 times, most recently from 622ce8b to 4a175df Compare October 10, 2026 20:36
@TomKimber
TomKimber force-pushed the feat/add-paho-mqtt-message-send-manager branch from 4a175df to ea92f38 Compare October 13, 2026 20:19
@read-the-docs-community

read-the-docs-community Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 AsyncFast | 🛠️ Build #35127416 | 📁 Comparing d2454ef against latest (7f72e38)

  🔍 Preview build  

1 file changed
± message_payload.html

@TomKimber
TomKimber force-pushed the feat/add-paho-mqtt-message-send-manager branch from ea92f38 to d2454ef Compare October 13, 2026 20:21
@TomKimber
TomKimber merged commit dc4a4de into main Oct 13, 2026
50 checks passed
@TomKimber
TomKimber deleted the feat/add-paho-mqtt-message-send-manager branch October 13, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants