|
| 1 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +// you may not use this file except in compliance with the License. |
| 3 | +// You may obtain a copy of the License at |
| 4 | +// |
| 5 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +// |
| 7 | +// Unless required by applicable law or agreed to in writing, software |
| 8 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +// See the License for the specific language governing permissions and |
| 11 | +// limitations under the License. |
| 12 | + |
| 13 | +//! Source / Sink 连接器协议:按 [`ConnectorOp::connector`] 分发到具体实现。 |
| 14 | +
|
| 15 | +use anyhow::{anyhow, Result}; |
| 16 | +use prost::Message; |
| 17 | +use std::sync::Arc; |
| 18 | + |
| 19 | +use protocol::grpc::api::ConnectorOp; |
| 20 | + |
| 21 | +use crate::runtime::streaming::api::operator::ConstructedOperator; |
| 22 | +use crate::runtime::streaming::factory::global::Registry; |
| 23 | +use crate::runtime::streaming::factory::operator_constructor::OperatorConstructor; |
| 24 | +use crate::sql::common::constants::connector_type; |
| 25 | + |
| 26 | +use super::kafka::{KafkaSinkDispatcher, KafkaSourceDispatcher}; |
| 27 | + |
| 28 | +pub struct ConnectorSourceDispatcher; |
| 29 | + |
| 30 | +impl OperatorConstructor for ConnectorSourceDispatcher { |
| 31 | + fn with_config(&self, config: &[u8], registry: Arc<Registry>) -> Result<ConstructedOperator> { |
| 32 | + let op = ConnectorOp::decode(config) |
| 33 | + .map_err(|e| anyhow!("decode ConnectorOp (source): {e}"))?; |
| 34 | + |
| 35 | + match op.connector.as_str() { |
| 36 | + ct if ct == connector_type::KAFKA => KafkaSourceDispatcher.with_config(config, registry), |
| 37 | + ct if ct == connector_type::REDIS => Err(anyhow!( |
| 38 | + "ConnectorSource '{}' factory wiring not yet implemented", |
| 39 | + op.connector |
| 40 | + )), |
| 41 | + other => Err(anyhow!("Unsupported source connector type: {}", other)), |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +pub struct ConnectorSinkDispatcher; |
| 47 | + |
| 48 | +impl OperatorConstructor for ConnectorSinkDispatcher { |
| 49 | + fn with_config(&self, config: &[u8], registry: Arc<Registry>) -> Result<ConstructedOperator> { |
| 50 | + let op = ConnectorOp::decode(config) |
| 51 | + .map_err(|e| anyhow!("decode ConnectorOp (sink): {e}"))?; |
| 52 | + |
| 53 | + match op.connector.as_str() { |
| 54 | + ct if ct == connector_type::KAFKA => KafkaSinkDispatcher.with_config(config, registry), |
| 55 | + other => Err(anyhow!("Unsupported sink connector type: {}", other)), |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments