Struct rump::client::Session [] [src]

pub struct Session<S: WampSender> {
    sender: S,
    pending_subscriptions: Arc<Mutex<HashMap<u64, (String, Box<Fn(&Payload) + Send>)>>>,
    subscriptions: Arc<Mutex<(HashMap<u64, String>, HashMap<String, Vec<Box<Fn(&Payload) + Send>>>)>>,
}

A Session represents a valid WAMP Session with a Router. You can obtain a Session from a Client

Fields

sender

Outgoing socket connection to WAMP Router

pending_subscriptions

Map topic URIs to the event_id that generated them and corresponding callback

subscriptions

Two maps: Firstly a mapping from topic IDs to topic URIs Secondly, topic URIs to their callbacks

Methods

impl<S: WampSender> Session<S>

fn join(&self, realm: String) -> WampResult<()>

Connects to a WAMP Router in a realm without authentication

fn publish<A, K>(&self, topic: &str, args: Vec<A>, kwargs: K) where A: Encodable, K: Encodable

Publish an event to the realm

You can publish 0 or more positional arguments and/or a struct representings Key-Value pairs that have the Encodable trait (can be derived from RustcEncodable, see rustc_serialize docs for more details).

Examples

To send an empty publish event...

use rump::message::WampType;

session.publish("com.example.topic", Vec::new(), WampType::None); 

To send the example positions arguments (42, "foo") and key word arguments...

This library includes a helper enum WampType that makes it easy to encode primitive positional arguments and keyword argument maps.

use rump::message::WampType;

extern crate rustc_serialize;
use rustc_serialize::Encodable;

#[derive(RustcEncodable)]
struct CustomKwargs {
    key1: String,
    key2: u32
}

session.publish("com.example.topic", vec![WampType::i32(42), WampType::String("foo".to_string())], CustomKwargs {key1: "hello".to_string(), key2: 19});

fn subscribe<F>(&self, topic: &str, callback: F) where F: 'static + Send + Fn(&Payload)