pub struct Service { /* private fields */ }Expand description
A Synapse service instance
Implementations§
Source§impl Service
impl Service
Sourcepub fn builder(service_name: impl Into<String>) -> ServiceBuilder
pub fn builder(service_name: impl Into<String>) -> ServiceBuilder
Create a new service builder
Sourcepub fn instance_id(&self) -> InstanceId
pub fn instance_id(&self) -> InstanceId
Get the instance ID
Sourcepub fn rpc_server(&self) -> &Arc<RpcServer>
pub fn rpc_server(&self) -> &Arc<RpcServer>
Get access to the RPC server
Sourcepub async fn register(
&self,
registration: InterfaceRegistration,
handler: Arc<dyn RpcHandler>,
) -> Result<()>
pub async fn register( &self, registration: InterfaceRegistration, handler: Arc<dyn RpcHandler>, ) -> Result<()>
Register a codegen-generated interface
Takes the (InterfaceRegistration, Arc<dyn RpcHandler>) tuple returned by
FooServiceRouter::create(impl) and registers it locally + with the gateway.
This is the preferred way to register interfaces — no need to repeat interface names or method names manually.
§Example
let impl_ = MyServiceImpl::new();
let (reg, handler) = MyServiceRouter::create(impl_);
service.register(reg, handler).await?;Sourcepub async fn register_interface(
&self,
interface_name: &str,
method_names: &[&str],
handler: Arc<dyn RpcHandler>,
) -> Result<()>
pub async fn register_interface( &self, interface_name: &str, method_names: &[&str], handler: Arc<dyn RpcHandler>, ) -> Result<()>
Register an interface implementation from string parameters
Prefer [register] when using codegen-generated routers.
This method is useful for dynamic/manual interface registration.
Sourcepub async fn register_http_routes(
&self,
routes: Vec<HttpRouteConfig>,
) -> Result<()>
pub async fn register_http_routes( &self, routes: Vec<HttpRouteConfig>, ) -> Result<()>
Register HTTP routes with the gateway, proxying to this service’s own endpoint.
Sends an HttpEndpointRegister message to the gateway, which will
add the routes to the gateway’s HTTP router. The gateway must have
appropriate http_registration_permissions configured to allow this.
Routes are stored and automatically re-registered if the gateway connection is lost and re-established.
Sourcepub async fn register_http_route_group(
&self,
group: HttpRouteGroup,
) -> Result<()>
pub async fn register_http_route_group( &self, group: HttpRouteGroup, ) -> Result<()>
Register HTTP routes with the gateway, proxying to an arbitrary host:port.
Use this to register routes for services that aren’t Synapse-connected (e.g., a frontend dev server, static file server, or external API). The gateway will proxy matching requests to the specified target.
Each group has its own service_name because the gateway maps
service_name → endpoint URL. Different backends need different names.
Routes are stored and automatically re-registered on reconnect.
Sourcepub async fn handle_request(&self, request: RpcRequest) -> RpcResponse
pub async fn handle_request(&self, request: RpcRequest) -> RpcResponse
Handle an RPC request
Sourcepub fn set_health_check<F>(&mut self, check: F)
pub fn set_health_check<F>(&mut self, check: F)
Set a custom health check function
Sourcepub fn health_response(&self) -> HealthResponse
pub fn health_response(&self) -> HealthResponse
Create a HealthResponse message
Sourcepub fn is_gateway_connected(&self) -> bool
pub fn is_gateway_connected(&self) -> bool
Check if currently connected to gateway
Sourcepub fn start_gateway_connection_task(
self: Arc<Self>,
interval_ms: u64,
) -> JoinHandle<()>
pub fn start_gateway_connection_task( self: Arc<Self>, interval_ms: u64, ) -> JoinHandle<()>
Start background task that pushes health status and handles reconnection
This task:
- Sends health status to gateway periodically
- Detects when gateway connection is lost
- Automatically re-registers all interfaces and HTTP routes when gateway comes back
interval_ms controls the health push frequency.
initial_delay_ms controls the initial startup delay (default 500ms if 0).
Sourcepub fn start_gateway_connection_task_with_delay(
self: Arc<Self>,
interval_ms: u64,
initial_delay_ms: u64,
) -> JoinHandle<()>
pub fn start_gateway_connection_task_with_delay( self: Arc<Self>, interval_ms: u64, initial_delay_ms: u64, ) -> JoinHandle<()>
Like start_gateway_connection_task but with a custom initial delay
Sourcepub fn start_health_pusher(self: Arc<Self>, interval_ms: u64) -> JoinHandle<()>
pub fn start_health_pusher(self: Arc<Self>, interval_ms: u64) -> JoinHandle<()>
Start background health push task (legacy alias for start_gateway_connection_task)
Sourcepub fn gateway_client(&self) -> Option<&HttpRpcClient>
pub fn gateway_client(&self) -> Option<&HttpRpcClient>
Get access to the gateway client (if configured)