ChannelPlatform and ConnectorSupervisor
TheChannelPlatform serves as the high-level coordinator within the daemon crates/palyra-daemon/src/channels.rs#106-110. It encapsulates the ConnectorSupervisor, which manages the lifecycle of individual ConnectorAdapter instances.
Key Components
| Component | Responsibility |
|---|---|
ChannelPlatform | Orchestrates initialization, default inventory, and provides the public API for the daemon crates/palyra-daemon/src/channels.rs#106-110. |
ConnectorSupervisor | Manages the runtime state, registration, and status of all connectors crates/palyra-connectors/src/lib.rs#2-12. |
ConnectorStore | A SQLite-backed store for persisting connector configurations, instance records, and outbox messages crates/palyra-daemon/src/channels.rs#119-119. |
ConnectorAdapter | A trait implemented by specific platform integrations (e.g., DiscordConnectorAdapter) to handle low-level transport crates/palyra-connectors/src/connectors/mod.rs#16-18. |
Initialization Lifecycle
WhenChannelPlatform::initialize is called, it performs the following steps:
- Opens the
ConnectorStoreat the specified path crates/palyra-daemon/src/channels.rs#119-119. - Initializes the
MediaArtifactStorefor handling message attachments crates/palyra-daemon/src/channels.rs#120-124. - Creates a
GrpcChannelRouterto bridge inbound connector events back to the daemon’s gRPC services crates/palyra-daemon/src/channels.rs#125-126. - Instantiates the
ConnectorSupervisorwith a set ofdefault_adapters(Echo and Discord) crates/palyra-daemon/src/channels.rs#127-132.
Inbound Message Pipeline
Inbound messages flow from the external platform through the adapter into theConnectorSupervisor, which then routes them to the daemon via the GrpcChannelRouter.
Data Flow: Inbound Message
- Ingestion: The
ConnectorAdapterreceives a message and emits anInboundMessageEvent. - Preprocessing: Attachments are preprocessed and stored in the
MediaArtifactStorecrates/palyra-daemon/src/channels.rs#125-126. - Routing: The
GrpcChannelRouterconstructs aRouteMessageRequestcrates/palyra-daemon/src/channels.rs#32-33. - Daemon Entry: The message is submitted to the Gateway’s gRPC endpoint using
HEADER_CHANNELandHEADER_PRINCIPALfor authentication crates/palyra-daemon/src/channels.rs#31-31.
Code Entity Mapping: Inbound Routing
The following diagram shows how inbound messages are transformed from raw events into routed requests. Title: Inbound Routing Pipeline Sources: crates/palyra-daemon/src/channels.rs#125-132, crates/palyra-daemon/src/channel_router.rs#215-227, crates/palyra-daemon/src/transport/grpc/auth.rs#31-31Outbound Message Pipeline
Outbound messages are enqueued in theConnectorStore outbox and processed by a background “drain” loop.
Outbound Drain Logic
TheConnectorSupervisor periodically drains the outbox for each active connector.
- Selection: It fetches
OutboxEntryRecorditems that are pending or scheduled for retry. - Dispatch: It calls
ConnectorAdapter::send_outboundcrates/palyra-connectors/src/connectors/echo.rs#43-47. - Outcome Handling:
- Delivered: The record is marked as succeeded with a
native_message_idcrates/palyra-connectors/src/connectors/echo.rs#69-69. - Retry: If the adapter returns
RetryClass, the message is rescheduled with exponential backoff crates/palyra-connectors/src/connectors/echo.rs#55-59. - Permanent Failure: The message is moved to the
DeadLetterRecordtable for manual inspection crates/palyra-connectors/src/lib.rs#8-11.
- Delivered: The record is marked as succeeded with a
Code Entity Mapping: Outbound Pipeline
The following diagram illustrates the lifecycle of an outbound message from enqueue to delivery. Title: Outbound Drain and Retry Lifecycle Sources: crates/palyra-connectors/src/connectors/echo.rs#43-75, crates/palyra-connectors/src/lib.rs#8-12Echo Connector
TheEchoConnectorAdapter is a specialized implementation used for internal testing and validation of the pipeline crates/palyra-connectors/src/connectors/echo.rs#21-24.
- Idempotency: It maintains a
delivered_native_idsmap to ensure the sameenvelope_idalways results in the samenative_message_idcrates/palyra-connectors/src/connectors/echo.rs#68-70. - Crash Simulation: If a message contains the string
[connector-crash-once], the adapter will return aRetryClass::ConnectorRestartingoutcome exactly once for thatenvelope_idto test daemon resilience crates/palyra-connectors/src/connectors/echo.rs#48-61. - Availability: It is marked as
ConnectorAvailability::InternalTestOnlycrates/palyra-connectors/src/connectors/echo.rs#40-41.
Supported Connectors
The platform defines several connector kinds, though implementation status varies:| Connector Kind | Availability | Status |
|---|---|---|
Echo | InternalTestOnly | Fully functional for tests crates/palyra-connectors/src/connectors/echo.rs#35-41. |
Discord | Supported | Primary production connector crates/palyra-connectors/src/connectors/mod.rs#38-38. |
Slack | Deferred | Roadmap item; returns PermanentFailure crates/palyra-connectors/src/connectors/slack.rs#14-30. |
Telegram | Deferred | Roadmap item; returns PermanentFailure crates/palyra-connectors/src/connectors/telegram.rs#14-30. |