Files
imks/socket/message_bus/mod.rs
T
zhenyi 06e8ee96a5 feat(auth): add authentication protocol definitions and build configuration
- Add TokenClaims message for JWT payload structure with user id, issuer, timestamps, and scopes
- Implement IssueTokenRequest/Response for creating access and refresh tokens with TTL support
- Create RefreshTokenRequest/Response for token rotation functionality
- Define RevokeTokenRequest/Response with support for single token or user-wide revocation
- Add VerifyTokenRequest/Response for validating JWT tokens with detailed claims information
- Implement signing key distribution system with GetSigningKeysRequest/Response
- Create TokenService gRPC service with IssueToken, RefreshToken, RevokeToken, VerifyToken, and GetSigningKeys methods
- Add build.rs configuration to compile proto files using tonic_prost_build
- Include channel, channel_settings, member, and permission protocol definitions for IM services
- Generate Rust code bindings through pb/core.rs and pb/im.rs modules
2026-06-10 23:45:40 +08:00

31 lines
905 B
Rust

pub mod redis;
pub mod nats;
use async_trait::async_trait;
use thiserror::Error;
use tokio::sync::mpsc;
#[derive(Error, Debug)]
pub enum MessageBusError {
#[error("Redis error: {0}")]
Redis(String),
#[error("NATS error: {0}")]
Nats(String),
#[error("Connection closed")]
ConnectionClosed,
#[error("Channel not found: {0}")]
ChannelNotFound(String),
#[error("Serialization error: {0}")]
Serialization(String),
}
#[async_trait]
pub trait MessageBus: Send + Sync + 'static {
async fn publish(&self, channel: &str, message: &[u8]) -> Result<(), MessageBusError>;
async fn subscribe(&self, channel: &str) -> Result<mpsc::Receiver<Vec<u8>>, MessageBusError>;
async fn unsubscribe(&self, channel: &str) -> Result<(), MessageBusError>;
async fn close(&self) -> Result<(), MessageBusError>;
}
pub use redis::RedisMessageBus;
pub use nats::NatsMessageBus;