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]

[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(());

[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");

[src]

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

[src]

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

[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);

[src]

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>();

[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]

[src]

Formats the value using the given formatter.