[][src]Struct spectacles_brokers::amqp::AmqpBroker

pub struct AmqpBroker {
    pub group: String,
    pub subgroup: Option<String>,
    // some fields omitted
}

Central AMQP message brokers client.

Fields

group: String

The group used for consuming and producing messages.

subgroup: Option<String>

The subgroup used for consuming and producing messages.

Methods

impl AmqpBroker[src]

pub fn new(
    amqp_uri: String,
    group: String,
    subgroup: Option<String>
) -> impl Future<Item = AmqpBroker, Error = Error>
[src]

Creates a new AMQP-based message broker, with the provided address, and groups.

Example

use std::env::var;
use spectacles_brokers::amqp::*;
use futures::future::future;

fn main() {
    let amqp = var("AMQP_URL").expect("No AMQP Address has been provided.");
    tokio::run({
        AmqpBroker::new(amqp, "mygroup".to_string(), None)
        .map(|broker| {
            /// Publish and subscribe to events here.
        });
    });
}

pub fn publish(
    &self,
    evt: &str,
    payload: Vec<u8>,
    properties: AmqpProperties
) -> impl Future<Item = Option<u64>, Error = Error>
[src]

Publishes a payload for the provided event to the message brokers. You must serialize all payloads to a Vector of bytes. This method accepts an AMQPProperties struct which will set the AMQP properties for this message. See here for more details on the various AMQP properties.

Example

-- snip --

AmqpBroker::new(AMQP_URI, "mygroup".to_string(), None)
   .and_then(|broker| broker.publish(
         "MESSAGE_CREATE",
         b"{'content': 'Hi'}".to_vec(),
         AmqpProperties::default().with_content_type("application/json")
    ))

pub fn consume(&self, evt: &str) -> AmqpConsumer[src]

Attempts to consume the provided event. Returns a stream, which is populated with each incoming AMQP message.

Example

-- snip --
AmqpBroker::new(addr, "mygroup", None)
   .and_then(|broker| broker.consume("MESSAGE_CREATE"))
   .for_each(|message| { // Poll the consumer stream.
        println!("Message Event Received: {}", payload);

        Ok(())
    })
    .map_err(|err| {
        eprintln!("Failed to consume queue. {:?}", err);
    })

Trait Implementations

impl Clone for AmqpBroker[src]

default fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for AmqpBroker

impl Sync for AmqpBroker

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T