Skip to main content

Service

Struct Service 

Source
pub struct Service { /* private fields */ }
Expand description

A Synapse service instance

Implementations§

Source§

impl Service

Source

pub fn builder(service_name: impl Into<String>) -> ServiceBuilder

Create a new service builder

Source

pub fn name(&self) -> &str

Get the service name

Source

pub fn instance_id(&self) -> InstanceId

Get the instance ID

Source

pub fn rpc_server(&self) -> &Arc<RpcServer>

Get access to the RPC server

Source

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?;
Source

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.

Source

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.

Source

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.

Source

pub async fn handle_request(&self, request: RpcRequest) -> RpcResponse

Handle an RPC request

Source

pub fn set_health_check<F>(&mut self, check: F)
where F: Fn() -> HealthStatus + Send + Sync + 'static,

Set a custom health check function

Source

pub fn health_response(&self) -> HealthResponse

Create a HealthResponse message

Source

pub fn is_gateway_connected(&self) -> bool

Check if currently connected to gateway

Source

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).

Source

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

Source

pub fn start_health_pusher(self: Arc<Self>, interval_ms: u64) -> JoinHandle<()>

Start background health push task (legacy alias for start_gateway_connection_task)

Source

pub fn gateway_client(&self) -> Option<&HttpRpcClient>

Get access to the gateway client (if configured)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more