Skip to content

Commit 5599313

Browse files
committed
feat: pass connection id in server for subscription
Signed-off-by: Mauro Sardara <msardara@cisco.com>
1 parent ad7480d commit 5599313

File tree

1 file changed

+41
-2
lines changed
  • data-plane/bindings/rust/src/slimrpc

1 file changed

+41
-2
lines changed

data-plane/bindings/rust/src/slimrpc/server.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ impl Server {
5555
app: Arc<SlimApp<AuthProvider, AuthVerifier>>,
5656
base_name: SlimName,
5757
notification_rx: Arc<RwLock<mpsc::Receiver<Result<Notification, SlimSessionError>>>>,
58+
connection_id: Option<u64>,
5859
) -> Arc<Self> {
5960
let runtime = crate::get_runtime().handle().clone();
6061
let inner = CoreServer::new_with_shared_rx_and_connection(
6162
app,
6263
base_name,
63-
None,
64+
connection_id,
6465
notification_rx,
6566
Some(runtime),
6667
);
@@ -100,10 +101,48 @@ impl Server {
100101
/// ```
101102
#[uniffi::constructor]
102103
pub fn new(app: &Arc<App>, base_name: Arc<Name>) -> Arc<Self> {
104+
Self::new_with_connection(app, base_name, None)
105+
}
106+
107+
/// Create a new RPC server with optional connection ID
108+
///
109+
/// The connection ID is used to set up routing before serving RPC requests,
110+
/// enabling multi-hop RPC calls through specific connections.
111+
///
112+
/// # Arguments
113+
/// * `app` - The SLIM application instance that provides the underlying
114+
/// network transport and session management
115+
/// * `base_name` - The base name for this service (e.g., org.namespace.service).
116+
/// This name is used to construct subscription names for RPC methods.
117+
/// * `connection_id` - Optional connection ID for routing setup
118+
///
119+
/// # Returns
120+
/// A new RPC server instance wrapped in an Arc for shared ownership
121+
///
122+
/// # Example
123+
/// ```no_run
124+
/// # use std::sync::Arc;
125+
/// # use slim_bindings::{App, Name, RpcServer};
126+
/// # async fn example() {
127+
/// let app = App::new_with_secret_async(
128+
/// Arc::new(Name::new("org".into(), "example".into(), "service".into())),
129+
/// "secret".into(),
130+
/// ).await.unwrap();
131+
///
132+
/// let service_name = Arc::new(Name::new("org".into(), "example".into(), "rpc".into()));
133+
/// let server = RpcServer::new_with_connection(&app, service_name, Some(42));
134+
/// # }
135+
/// ```
136+
#[uniffi::constructor]
137+
pub fn new_with_connection(
138+
app: &Arc<App>,
139+
base_name: Arc<Name>,
140+
connection_id: Option<u64>,
141+
) -> Arc<Self> {
103142
let app_inner = app.inner();
104143
let rx = app.notification_receiver();
105144

106-
Server::new_internal(app_inner, base_name.as_ref().into(), rx)
145+
Server::new_internal(app_inner, base_name.as_ref().into(), rx, connection_id)
107146
}
108147

109148
/// Register a unary-to-unary RPC handler

0 commit comments

Comments
 (0)