feat(config): integrate etcd for service discovery and config management
- Add etcd-client dependency for distributed configuration storage - Implement EtcdConfig with priority: etcd > environment variables > defaults - Add ServiceRegistry for service registration with lease keep-alive - Integrate etcd-based service discovery for appks gRPC connections - Add service watcher for real-time service instance updates - Migrate Redis configuration from single URL to cluster node list - Update Dockerfile with default IMKS_HOST and IMKS_PORT environment variables - Add etcd bootstrap configuration through environment variables - Implement Redis cluster URL building with optional authentication
This commit is contained in:
+13
-10
@@ -3,13 +3,12 @@ use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use dashmap::DashMap;
|
||||
use fred::clients::Client;
|
||||
use fred::interfaces::{KeysInterface, SetsInterface};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::socket::adapter::{
|
||||
Adapter, AdapterError, BroadcastOptions, BusMessage, LocalBroadcastFn, SocketInfo,
|
||||
};
|
||||
use crate::socket::message_bus::redis::RedisCommandClient;
|
||||
use crate::socket::message_bus::MessageBus;
|
||||
use crate::socket::packet::Packet;
|
||||
use crate::socket::parser;
|
||||
@@ -68,7 +67,7 @@ async fn handle_bus_message(
|
||||
|
||||
pub struct RedisAdapter {
|
||||
message_bus: Arc<dyn MessageBus>,
|
||||
redis_client: Client,
|
||||
redis_client: RedisCommandClient,
|
||||
room_subscribers: DashMap<String, mpsc::Receiver<Vec<u8>>>,
|
||||
socket_rooms: DashMap<String, HashSet<String>>,
|
||||
rooms: DashMap<String, HashSet<String>>,
|
||||
@@ -83,7 +82,7 @@ pub struct RedisAdapter {
|
||||
impl RedisAdapter {
|
||||
pub fn new(
|
||||
message_bus: Arc<dyn MessageBus>,
|
||||
redis_client: Client,
|
||||
redis_client: RedisCommandClient,
|
||||
server_id: String,
|
||||
namespace: String,
|
||||
on_local_broadcast: LocalBroadcastFn,
|
||||
@@ -195,12 +194,12 @@ impl Adapter for RedisAdapter {
|
||||
let srk = socket_rooms_key(ns, sid);
|
||||
|
||||
self.redis_client
|
||||
.sadd::<(), _, _>(&rk, sid)
|
||||
.query::<()>(redis::cmd("SADD").arg(&rk).arg(sid))
|
||||
.await
|
||||
.map_err(|e| AdapterError::Redis(e.to_string()))?;
|
||||
|
||||
self.redis_client
|
||||
.sadd::<(), _, _>(&srk, room)
|
||||
.query::<()>(redis::cmd("SADD").arg(&srk).arg(room))
|
||||
.await
|
||||
.map_err(|e| AdapterError::Redis(e.to_string()))?;
|
||||
|
||||
@@ -241,12 +240,12 @@ impl Adapter for RedisAdapter {
|
||||
let srk = socket_rooms_key(ns, sid);
|
||||
|
||||
self.redis_client
|
||||
.srem::<(), _, _>(&rk, sid)
|
||||
.query::<()>(redis::cmd("SREM").arg(&rk).arg(sid))
|
||||
.await
|
||||
.map_err(|e| AdapterError::Redis(e.to_string()))?;
|
||||
|
||||
self.redis_client
|
||||
.srem::<(), _, _>(&srk, room)
|
||||
.query::<()>(redis::cmd("SREM").arg(&srk).arg(room))
|
||||
.await
|
||||
.map_err(|e| AdapterError::Redis(e.to_string()))?;
|
||||
|
||||
@@ -308,7 +307,11 @@ impl Adapter for RedisAdapter {
|
||||
}
|
||||
|
||||
let rk = room_key(ns, room);
|
||||
if let Err(e) = self.redis_client.srem::<(), _, _>(&rk, sid).await {
|
||||
if let Err(e) = self
|
||||
.redis_client
|
||||
.query::<()>(redis::cmd("SREM").arg(&rk).arg(sid))
|
||||
.await
|
||||
{
|
||||
tracing::warn!("Redis SREM room error: {}", e);
|
||||
}
|
||||
}
|
||||
@@ -316,7 +319,7 @@ impl Adapter for RedisAdapter {
|
||||
|
||||
let srk = socket_rooms_key(ns, sid);
|
||||
self.redis_client
|
||||
.del::<(), _>(&srk)
|
||||
.query::<()>(redis::cmd("DEL").arg(&srk))
|
||||
.await
|
||||
.map_err(|e| AdapterError::Redis(e.to_string()))?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user