Crate batch [] [src]

Batch is a distributed task queue library.

This library allows you to send a task to a RabbitMQ broker, so that a worker will be able to pull it and execute the associated handler. It leverages the futures and tokio-core crates to provide asynchronous I/O operations.

Example

#[macro_use]
extern crate batch;
extern crate futures;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate tokio_core;

use batch::{exchange, job, ClientBuilder};
use futures::Future;
use tokio_core::reactor::Core;

#[derive(Serialize, Deserialize, Task)]
#[task_routing_key = "hello-world"]
struct SayHello {
    to: String,
}

fn main() {
    let mut core = Core::new().unwrap();
    let handle = core.handle();

    let exchanges = vec![
        exchange("batch.examples"),
    ];
    let client = ClientBuilder::new()
        .connection_url("amqp://localhost/%2f")
        .exchanges(exchanges)
        .handle(handle)
        .build();
    let send = client.and_then(|client| {
        let task = SayHello {
            to: "Ferris".into(),
        };

        job(task).exchange("batch.example").send(&client)
    });

    core.run(send).unwrap();
}

Structs

Client

The Client is responsible for sending tasks to the broker.

ClientBuilder

A builder to ease the construction of Client instances.

Error

Error type for the batch crate. Implements Fail.

ExchangeBuilder

A builder for RabbitMQ Exchange.

Query

A Query is responsible for publishing jobs to RabbitMQ.

QueueBuilder

A builder for RabbitMQ Queue.

Worker

Long-running worker polling tasks from the given Broker.

WorkerBuilder

A builder to ease the construction of Worker instances.

Traits

Perform

The Perform trait allow marking a Task as executable.

Task

An executable task and its related metadata (name, queue, timeout, etc.)

Functions

exchange

Shorthand to create a new ExchangeBuilder instance.

job

Shorthand to create a new Query instance from a Task.

queue

Shorthand to create a new QueueBuilder instance.