Struct batch::WorkerBuilder
[−]
[src]
pub struct WorkerBuilder<Ctx> { /* fields omitted */ }
A builder to ease the construction of Worker
instances.
Methods
impl<Ctx> WorkerBuilder<Ctx>
[src]
fn new(context: Ctx) -> Self
[src]
Create a new WorkerBuilder
instance, using the mandatory context.
The type of the given context is then used to typecheck the tasks registered on this builder.
Example
use batch::WorkerBuilder; let builder = WorkerBuilder::new(());
fn connection_url(self, url: &str) -> Self
[src]
Set the URL used to connect to RabbitMQ
.
The URL must be a valid AMQP connection URL (ex: amqp://localhost/%2f
) using either the
amqp
protocol or the amqps
protocol.
Example
use batch::WorkerBuilder; let builder = WorkerBuilder::new(()) .connection_url("amqp://guest:guest@localhost:5672/%2f");
fn exchanges<EIter>(self, exchanges: EIter) -> Self where
EIter: IntoIterator<Item = ExchangeBuilder>,
[src]
EIter: IntoIterator<Item = ExchangeBuilder>,
Add exchanges to be declared when connecting to RabbitMQ
.
See exchange
documentation.
Example
use batch::{exchange, WorkerBuilder}; let exchanges = vec![ exchange("batch.example"), ]; let builder = WorkerBuilder::new(()) .exchanges(exchanges);
fn queues<QIter>(self, queues: QIter) -> Self where
QIter: IntoIterator<Item = QueueBuilder>,
[src]
QIter: IntoIterator<Item = QueueBuilder>,
Add queues to be declared when connecting to RabbitMQ
.
See queue
documentation.
Example
use batch::{queue, WorkerBuilder}; let queues = vec![ queue("hello-world").bind("batch.example", "hello-world"), ]; let builder = WorkerBuilder::new(()) .queues(queues);
fn handle(self, handle: Handle) -> Self
[src]
Set the Handle
to the Tokio reactor that should be used by the Worker
.
Example
use batch::WorkerBuilder; use tokio_core::reactor::Core; let core = Core::new().unwrap(); let handle = core.handle(); let builder = WorkerBuilder::new(()) .handle(handle);
fn task<T>(self) -> Self where
T: Task + Perform<Context = Ctx>,
[src]
T: Task + Perform<Context = Ctx>,
Register a new Task
to be handled by the Worker
.
The type of the Task
's Context
must be the same as the Worker
's.
Example
use batch::{Perform, WorkerBuilder}; #[derive(Serialize, Deserialize, Task)] #[task_routing_key = "hello-world"] struct SayHello { to: String, } impl Perform for SayHello { type Context = (); fn perform(&self, _ctx: Self::Context) { println!("Hello {}", self.to); } } let builder = WorkerBuilder::new(()) .task::<SayHello>();
fn build(self) -> StdResult<Worker<Ctx>, Error>
[src]
Create a new Worker
instance from this builder data.
Example
use batch::WorkerBuilder; let builder = WorkerBuilder::new(()) .build();
Trait Implementations
impl<Ctx> Debug for WorkerBuilder<Ctx> where
Ctx: Debug,
[src]
Ctx: Debug,