Skip to content

52 bi directional connector trait#53

Merged
lxsaah merged 28 commits into
mainfrom
52-bi-directional-connector-trait
Nov 16, 2025
Merged

52 bi directional connector trait#53
lxsaah merged 28 commits into
mainfrom
52-bi-directional-connector-trait

Conversation

@lxsaah

@lxsaah lxsaah commented Nov 16, 2025

Copy link
Copy Markdown
Contributor

Closed #52.

This PR introduces bidirectional connector support, enabling true two-way data synchronization between AimDB and external systems. The new architecture supports simultaneous publishing and subscribing with automatic message routing, working seamlessly across both Tokio (std) and Embassy (no_std) runtimes.

Highlights

  • 🔄 Bidirectional Connectors: New .link_to() and .link_from() APIs for clear directional data flows
  • 🎯 Type-Erased Router: Automatic routing of incoming messages to correct typed producers
  • 🏗️ ConnectorBuilder Pattern: Simplified connector registration with automatic initialization
  • 📡 Enhanced MQTT Connector: Complete rewrite supporting simultaneous pub/sub with automatic reconnection
  • 🌐 Embassy Network Integration: Connectors can now access Embassy's network stack for network operations
  • 📚 Comprehensive Guide: New 1000+ line connector development guide with real-world examples

Breaking Changes

  • aimdb-core: .build() is now async; connector registration changed from .with_connector(scheme, instance) to .with_connector(builder)
  • aimdb-core: .link() deprecated in favor of .link_to() (outbound) and .link_from() (inbound)
  • aimdb-mqtt-connector: API changed from MqttConnector::new() to MqttConnectorBuilder::new(); automatic task spawning removes need for manual background task management

Modified Crates

See individual changelogs for detailed changes:

- Added `produce_any` method to `ProducerTrait` for type-erased value production.
- Updated `RecordRegistrar` to use connector builders instead of direct connectors.
- Enhanced error handling for missing connectors and serializers.
- Refactored inbound connector task spawning to utilize new routing logic.

refactor: Update TypedRecord to support outbound consumer spawning

- Introduced `spawn_outbound_consumers` method for managing outbound connector tasks.
- Removed redundant inbound connector count and task spawning methods.
- Added `create_producer_trait` method for creating type-erased producers.

fix: Adjust MQTT connector to use router-based dispatch

- Refactored `MqttConnector` to utilize a router for message dispatching.
- Updated event loop to route incoming messages to appropriate producers.
- Removed deprecated subscribe method in favor of router-based handling.

test: Enhance tests for connector spawning and routing

- Updated tests to reflect changes in connector registration and routing.
- Added mock connector for testing purposes.
- Verified correct behavior with no connectors and with registered links.

chore: Update dependencies and clean up unused code

- Added `async-trait` dependency for async trait support.
- Cleaned up unused imports and code comments across various files.
… update type aliases, and adjust resource ID handling for proper memory management in both `std` and `no_std` environments.
- Added support for `embassy-net` in the `Cargo.toml` and `Cargo.lock` files.
- Introduced `embassy-net-support` feature in `aimdb-embassy-adapter` for network stack integration.
- Updated `MqttConnector` to support bidirectional communication, allowing both publishing and subscribing to MQTT topics.
- Implemented `EmbassyNetwork` trait for accessing the network stack within the `EmbassyAdapter`.
- Refactored the MQTT connector builder to facilitate the creation of connectors with network capabilities.
- Enhanced the example application to demonstrate bidirectional MQTT integration, including command processing from MQTT messages.
- Updated documentation and comments for clarity on new features and usage patterns.
@lxsaah lxsaah requested a review from Copilot November 16, 2025 14:10
@lxsaah lxsaah self-assigned this Nov 16, 2025
@lxsaah lxsaah added the 🔌 bridges Protocol bridges label Nov 16, 2025
@lxsaah lxsaah linked an issue Nov 16, 2025 that may be closed by this pull request
22 tasks

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces bidirectional connector support for AimDB, enabling simultaneous publishing and subscribing between AimDB and external systems (MQTT, Kafka, etc.). The architecture uses a type-erased router system for automatic message dispatch and implements the ConnectorBuilder pattern for simplified connector registration, with full support for both Tokio (std) and Embassy (no_std) runtimes.

Key Changes:

  • New .link_to() and .link_from() APIs replace generic .link() method for explicit data flow direction
  • Type-erased Router system automatically routes incoming messages to correct typed producers
  • ConnectorBuilder pattern with async initialization during database build phase
  • Complete MQTT connector rewrite supporting simultaneous pub/sub with automatic reconnection
  • Embassy runtime enhanced with network stack access for connector TCP/UDP operations

Reviewed Changes

Copilot reviewed 36 out of 37 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
aimdb-core/src/builder.rs Async build() method, connector builder integration, route collection
aimdb-core/src/connector.rs ConnectorBuilder trait, ProducerTrait, InboundConnectorLink
aimdb-core/src/router.rs New router system for type-erased message dispatch
aimdb-core/src/typed_api.rs Bidirectional link APIs (link_to/link_from), builder implementations
aimdb-core/src/typed_record.rs Outbound consumer spawning, inbound connector storage
aimdb-mqtt-connector/src/tokio_client.rs Router-based bidirectional MQTT with automatic subscriptions
aimdb-mqtt-connector/src/embassy_client.rs Embassy MQTT with network stack access, automatic task spawning
aimdb-embassy-adapter/src/runtime.rs EmbassyNetwork trait for connector network access
examples/tokio-mqtt-connector-demo/src/main.rs Bidirectional MQTT demo with command processing
examples/embassy-mqtt-connector-demo/src/main.rs Embedded bidirectional MQTT with network stack integration
docs/design/012-M5-connector-development-guide.md Comprehensive 1000+ line connector development guide

Comment thread aimdb-core/src/builder.rs
Comment thread aimdb-mqtt-connector/src/embassy_client.rs Outdated
Comment thread aimdb-embassy-adapter/src/runtime.rs Outdated
Comment thread aimdb-core/src/typed_record.rs
Comment thread aimdb-mqtt-connector/src/tokio_client.rs
…mDB → External) from inbound (External → AimDB) flows
- Introduced `spawn_outbound_publishers()` method for both Tokio and Embassy implementations to handle AimDB → MQTT publishing.
- Updated `MqttConnectorBuilder` to require outbound publisher spawning during `build()`.
- Refactored outbound architecture to utilize `ConsumerTrait` for type-safe message dispatch.
- Enhanced documentation to clarify the importance of spawning outbound publishers.
- Updated changelog to reflect breaking changes and new features.
@lxsaah lxsaah requested a review from Copilot November 16, 2025 18:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 41 out of 42 changed files in this pull request and generated no new comments.

@lxsaah lxsaah merged commit 23b543b into main Nov 16, 2025
12 of 13 checks passed
@lxsaah lxsaah deleted the 52-bi-directional-connector-trait branch November 16, 2025 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔌 bridges Protocol bridges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bi-directional connector trait

2 participants