camel_component_redis/
lib.rs1pub mod commands;
2pub mod config;
3pub mod consumer;
4pub mod producer;
5
6use camel_api::{BoxProcessor, CamelError};
7use camel_component::{Component, Consumer, Endpoint, ProducerContext};
8
9pub use config::{RedisCommand, RedisConfig};
10pub use consumer::RedisConsumer;
11pub use producer::RedisProducer;
12
13pub struct RedisComponent;
14
15impl RedisComponent {
16 pub fn new() -> Self {
17 Self
18 }
19}
20
21impl Default for RedisComponent {
22 fn default() -> Self {
23 Self::new()
24 }
25}
26
27impl Component for RedisComponent {
28 fn scheme(&self) -> &str {
29 "redis"
30 }
31
32 fn create_endpoint(&self, uri: &str) -> Result<Box<dyn Endpoint>, CamelError> {
33 let config = RedisConfig::from_uri(uri)?;
34 Ok(Box::new(RedisEndpoint {
35 uri: uri.to_string(),
36 config,
37 }))
38 }
39}
40
41struct RedisEndpoint {
42 uri: String,
43 config: RedisConfig,
44}
45
46impl Endpoint for RedisEndpoint {
47 fn uri(&self) -> &str {
48 &self.uri
49 }
50
51 fn create_producer(&self, _ctx: &ProducerContext) -> Result<BoxProcessor, CamelError> {
52 Ok(BoxProcessor::new(RedisProducer::new(self.config.clone())))
53 }
54
55 fn create_consumer(&self) -> Result<Box<dyn Consumer>, CamelError> {
56 Ok(Box::new(RedisConsumer::new(self.config.clone())))
57 }
58}