Skip to content

Commit 035464b

Browse files
committed
feat: allow passing connection id
Signed-off-by: Mauro Sardara <msardara@cisco.com>
1 parent 3cc3886 commit 035464b

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub struct Channel {
3030
#[uniffi::export]
3131
impl Channel {
3232
/// Create a new RPC channel
33-
/// Make a unary-to-unary RPC call (blocking version)
3433
///
3534
/// # Arguments
3635
/// * `app` - The SLIM application instance
@@ -40,9 +39,31 @@ impl Channel {
4039
/// A new channel instance
4140
#[uniffi::constructor]
4241
pub fn new(app: Arc<App>, remote: Arc<Name>) -> Arc<Self> {
42+
Self::new_with_connection(app, remote, None)
43+
}
44+
45+
/// Create a new RPC channel with optional connection ID
46+
///
47+
/// The connection ID is used to set up routing before making RPC calls,
48+
/// enabling multi-hop RPC calls through specific connections.
49+
///
50+
/// # Arguments
51+
/// * `app` - The SLIM application instance
52+
/// * `remote` - The remote service name to connect to
53+
/// * `connection_id` - Optional connection ID for routing setup
54+
///
55+
/// # Returns
56+
/// A new channel instance
57+
#[uniffi::constructor]
58+
pub fn new_with_connection(
59+
app: Arc<App>,
60+
remote: Arc<Name>,
61+
connection_id: Option<u64>,
62+
) -> Arc<Self> {
4363
let slim_name = remote.as_ref().clone().into();
4464
let runtime = crate::get_runtime().handle().clone();
45-
let inner = CoreChannel::new_with_connection(app.inner(), slim_name, None, Some(runtime));
65+
let inner =
66+
CoreChannel::new_with_connection(app.inner(), slim_name, connection_id, Some(runtime));
4667

4768
Arc::new(Self { inner })
4869
}

data-plane/slimrpc/src/channel.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,23 @@ impl Channel {
620620
let method_subscription_name =
621621
crate::build_method_subscription_name(&self.inner.remote, service_name, method_name);
622622

623+
// Set route if connection_id is provided
624+
if let Some(conn_id) = self.inner.connection_id {
625+
tracing::debug!(
626+
%service_name,
627+
%method_name,
628+
%method_subscription_name,
629+
connection_id = conn_id,
630+
"Setting route before creating session"
631+
);
632+
633+
self.inner
634+
.app
635+
.set_route(&method_subscription_name, conn_id)
636+
.await
637+
.map_err(|e| Status::internal(format!("Failed to set route: {}", e)))?;
638+
}
639+
623640
// Create the session with optional connection ID for propagation
624641
tracing::debug!(
625642
%service_name,

0 commit comments

Comments
 (0)