pub struct ServiceBroker { /* private fields */ }
Expand description
The struct used to interact with moleculer.
Use emit()
, broadcast()
and call()
functions.
ⓘ
// emit an event
broker.emit("printHi", json!{{}});
// broadcast an event
broker.broadcast("printHi", json!{{}});
// call an action
let result = broker.call("math.add", json!{"a": 1, "b": c}).await?;
Implementations§
Source§impl ServiceBroker
impl ServiceBroker
Sourcepub fn new(config: Config) -> ServiceBroker
pub fn new(config: Config) -> ServiceBroker
Create new service broker, takes Config struct.
Sourcepub fn add_service(self, service: Service) -> Self
pub fn add_service(self, service: Service) -> Self
Add a service to the service broker.
Sourcepub fn add_services(self, services: Vec<Service>) -> Self
pub fn add_services(self, services: Vec<Service>) -> Self
Add all the services to the service broker at once. Takes a vector of services and replaces any services the broker already had.
Sourcepub async fn start(self)
pub async fn start(self)
Starts the service, this will run forever until your application exits.
Sourcepub async fn call<S: Into<String>>(
self,
action: S,
params: Value,
) -> Result<Value, Error>
pub async fn call<S: Into<String>>( self, action: S, params: Value, ) -> Result<Value, Error>
Request/Response style call
Call an action directly with params serialized into
serde_json::Value and await
on the result
Trait Implementations§
Source§impl Clone for ServiceBroker
impl Clone for ServiceBroker
Source§fn clone(&self) -> ServiceBroker
fn clone(&self) -> ServiceBroker
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for ServiceBroker
impl !RefUnwindSafe for ServiceBroker
impl Send for ServiceBroker
impl Sync for ServiceBroker
impl Unpin for ServiceBroker
impl !UnwindSafe for ServiceBroker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more