Crate spectacles_brokers

Crate spectacles_brokers 

Source
Expand description

§spectacles-brokers

Message brokers which allow for simple communication between Spectacles services.

§Available Brokers

  • AMQP - An interface to connect to an AMQP-compliant server.

§Example AMQP Publisher

use std::env::var;
use std::net::SocketAddr;
use futures::future::Future;
use spectacles_brokers::AmqpBroker;

fn main() {
   let addr = var("AMQP_ADDR").expect("No AMQP server address found.");
   let addr: SocketAddr = addr.parse();

   let connect = AmqpBroker::new(&addr, "test".to_string(), None);
   let result = connect.and_then(|broker| {
       let json = r#"{"message": "Example Publish."}"#.as_bytes();
       broker.publish("HELLO", json.to_vec())
   });
   let success = result.map(|_| {
       println!("Message publish succeeded, check the other window!");
   }).map_err(|err| {
       eprintln!("An error was encountered during publish: {}", err);
   });

   tokio::run(success);
}

More examples can be found in the examples directory on Github.

Modules§

amqp
Utilities for interfacing with an AMQP-based message broker.

Enums§

Error
Details the various errors of the crate.

Traits§

MessageHandler
Event handler for receiving messages from a message brokers.