pub struct Worker { /* private fields */ }Expand description
The worker object that contains all the threads and runners.
Implementations§
Source§impl Worker
impl Worker
Sourcepub async fn new(
amqp_server_url: impl Into<String>,
config: WorkerConfig,
) -> Self
pub async fn new( amqp_server_url: impl Into<String>, config: WorkerConfig, ) -> Self
Create a new instance of Worker
§Arguments
amqp_server_url- A string slice that holds the url of the amqp server (e.g. amqp://localhost:5672)config- AWorkerConfig, containing the TLS config for now.
Sourcepub fn add_non_rpc_consumer<J: Task + 'static + Send>(
&mut self,
state: Arc<J::State>,
listener_config: ListenerConfig,
)
pub fn add_non_rpc_consumer<J: Task + 'static + Send>( &mut self, state: Arc<J::State>, listener_config: ListenerConfig, )
Add a Task listener to the worker object
§Arguments
state- An Arc of the state object that will be passed to the listenerlistener_config-ListenerConfigthat holds the configuration for the listener
use bunbun_worker::{Worker, ListenerConfig, WorkerConfig};
let server = Worker::new("amqp://localhost:5672", Workerconfig::default()).await;
server.add_non_rpc_consumer::<MyTask>(ListenerConfig::default("service-jobname").set_message_version("v2.0.0") ));
server.start_all_listeners().await;Sourcepub fn add_rpc_consumer<J: RPCTask + 'static + Send>(
&mut self,
state: Arc<J::State>,
listener_config: ListenerConfig,
)
pub fn add_rpc_consumer<J: RPCTask + 'static + Send>( &mut self, state: Arc<J::State>, listener_config: ListenerConfig, )
Add an rpc job listener to the worker object Make sure the type you pass in implements RPCTask
§Arguments
queue_name- A string slice that holds the name of the queue to listen to (e.g. service-serviceJobName-v1.0.0)state- An Arc of the state object that will be passed to the listener
§Examples
use bunbun_worker::{Worker, ListenerConfig, WorkerConfig};
let server = Worker::new("amqp://localhost:5672", Workerconfig::default()).await;
server.add_rpc_consumer::<MyRPCTask>(ListenerConfig::default("service-jobname").set_message_version("v2.0.0") ));
server.start_all_listeners().await;Sourcepub async fn start_all_listeners(&self) -> Result<(), String>
pub async fn start_all_listeners(&self) -> Result<(), String>
Start all the listeners added to the worker object
Auto Trait Implementations§
impl Freeze for Worker
impl !RefUnwindSafe for Worker
impl Send for Worker
impl Sync for Worker
impl Unpin for Worker
impl !UnwindSafe for Worker
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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