new(all): Initial import.
This commit is contained in:
parent
8542f26cab
commit
e6201719ce
5 changed files with 41 additions and 5 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2486,6 +2486,7 @@ name = "gb-messaging"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"chrono",
|
||||
"futures",
|
||||
"futures-util",
|
||||
"gb-core",
|
||||
|
|
|
@ -8,16 +8,38 @@ use axum::{
|
|||
response::IntoResponse,
|
||||
Json,
|
||||
};
|
||||
|
||||
use gb_core::{Result, Error, models::*};
|
||||
use gb_messaging::{MessageProcessor, MessageEnvelope};
|
||||
use gb_messaging::{MessageProcessor, models::MessageEnvelope}; // Update this line
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
|
||||
use tracing::{instrument, error};
|
||||
use uuid::Uuid;
|
||||
|
||||
use futures_util::StreamExt;
|
||||
use futures_util::SinkExt;
|
||||
|
||||
pub struct ApiState {
|
||||
pub message_processor: Mutex<MessageProcessor>,
|
||||
}
|
||||
|
||||
pub fn create_router(message_processor: MessageProcessor) -> Router {
|
||||
let state = Arc::new(ApiState {
|
||||
message_processor: Mutex::new(message_processor),
|
||||
});
|
||||
|
||||
Router::new()
|
||||
.route("/health", get(|| async { "OK" }))
|
||||
.route("/messages", post(send_message))
|
||||
.route("/messages/:id", get(get_message))
|
||||
.route("/rooms", post(create_room))
|
||||
.route("/rooms/:id", get(get_room))
|
||||
.route("/rooms/:id/join", post(join_room))
|
||||
.route("/ws", get(websocket_handler))
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
async fn handle_ws_connection(
|
||||
ws: WebSocket,
|
||||
State(_state): State<Arc<ApiState>>,
|
||||
|
@ -26,7 +48,6 @@ async fn handle_ws_connection(
|
|||
// ... rest of the implementation
|
||||
}
|
||||
|
||||
|
||||
#[axum::debug_handler]
|
||||
#[instrument(skip(state, ws))]
|
||||
async fn websocket_handler(
|
||||
|
@ -80,8 +101,8 @@ async fn get_message(
|
|||
#[axum::debug_handler]
|
||||
#[instrument(skip(state, config))]
|
||||
async fn create_room(
|
||||
State(state): State<Arc<ApiState>>,
|
||||
Json(config): Json<RoomConfig>,
|
||||
State(_state): State<Arc<ApiState>>,
|
||||
Json(_config): Json<RoomConfig>,
|
||||
) -> Result<Json<Room>> {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ async-trait.workspace = true
|
|||
tracing.workspace = true
|
||||
futures.workspace = true
|
||||
futures-util = "0.3"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
lapin = "2.3"
|
||||
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
|
||||
|
||||
|
|
|
@ -3,12 +3,14 @@ mod rabbitmq;
|
|||
mod redis_pubsub;
|
||||
mod websocket;
|
||||
mod processor;
|
||||
pub mod models;
|
||||
|
||||
pub use kafka::Kafka;
|
||||
pub use rabbitmq::RabbitMQ;
|
||||
pub use redis_pubsub::RedisPubSub;
|
||||
pub use websocket::WebSocketClient;
|
||||
pub use processor::MessageProcessor;
|
||||
pub use models::MessageEnvelope;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
11
gb-messaging/src/models.rs
Normal file
11
gb-messaging/src/models.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use gb_core::models::Message;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct MessageEnvelope {
|
||||
pub id: Uuid,
|
||||
pub message: Message,
|
||||
pub metadata: HashMap<String, String>,
|
||||
}
|
Loading…
Add table
Reference in a new issue