Struct svc_agent::mqtt::agent::Agent

source ·
pub struct Agent { /* private fields */ }

Implementations§

source§

impl Agent

source

pub fn address(&self) -> &Address

source

pub fn id(&self) -> &AgentId

source

pub fn publish<T: Serialize>( &mut self, message: OutgoingMessage<T> ) -> Result<(), Error>

Publish a message.

This method is a shorthand to dump and publish the message with a single call. If you want to print out the dump before or after publishing or assert it in tests consider using IntoPublishableDump::into_dump and publish_dump.

Arguments
  • message – a boxed message of any type implementing Publishable trait.
Example
let props = OutgoingRequestProperties::new(
    "system.ping",
    Subscription::unicast_responses_from(to).subscription_topic(agent.id(), "v1")?,
    "random-string-123",
    OutgoingShortTermTimingProperties::new(Utc::now()),
);

let message = OutgoingMessage::new(
    json!({ "ping": "hello" }),
    props,
    Destination::Unicast(agent.id().clone(), "v1"),
);

agent.publish(message)?;
source

pub fn publish_publishable( &mut self, message: Box<dyn IntoPublishableMessage> ) -> Result<(), Error>

Publish a publishable message.

Arguments
  • message – message to publish.
Example
let props = OutgoingRequestProperties::new(
    "system.ping",
    Subscription::unicast_responses_from(to).subscription_topic(agent.id(), "v1")?,
    "random-string-123",
    OutgoingShortTermTimingProperties::new(Utc::now()),
);

let message = OutgoingMessage::new(
    json!({ "ping": "hello" }),
    props,
    Destination::Unicast(agent.id().clone(), "v1"),
);

let msg = Box::new(message) as Box<dyn IntoPublishableMessage>;
agent.publish_publishable(msg.clone())?;
println!("Message published: {}", msg);
source

pub fn publish_dump(&mut self, dump: PublishableMessage) -> Result<(), Error>

source

pub fn subscribe<S>( &mut self, subscription: &S, qos: QoS, maybe_group: Option<&SharedGroup> ) -> Result<(), Error>where S: SubscriptionTopic,

Subscribe to a topic.

Note that the subscription is actually gets confirmed on receiving AgentNotification::Suback notification.

Arguments
  • subscription – the Subscription.
  • qos – quality of service. See QoS for available values.
  • maybe_groupSharedGroup in case of multicast subscription.
Example
agent.subscribe(
    &Subscription::multicast_requests(Some("v1")),
    QoS::AtMostOnce,
    Some(&group),
)?;

match rx.recv_timeout(Duration::from_secs(5)) {
    Ok(AgentNotification::Suback(_)) => (),
    Ok(other) => panic!("Expected to receive suback notification, got {:?}", other),
    Err(err) => panic!("Failed to receive suback notification: {}", err),
}
source

pub fn unsubscribe<S>( &mut self, subscription: &S, maybe_group: Option<&SharedGroup> ) -> Result<(), Error>where S: SubscriptionTopic,

Unsubscribe from a topic.

Note that the unsubscribing is actually gets confirmed on receiving AgentNotification::Unsuback notification.

Arguments
Example
agent.unsubscribe(
    &Subscription::multicast_requests(Some("v1")),
    Some(&group),
)?;

match rx.recv_timeout(Duration::from_secs(5)) {
    Ok(AgentNotification::Unsuback(_)) => (),
    Ok(other) => panic!("Expected to receive unsuback notification, got {:?}", other),
    Err(err) => panic!("Failed to receive unsuback notification: {}", err),
}

Trait Implementations§

source§

impl Clone for Agent

source§

fn clone(&self) -> Agent

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnwindSafe for Agent

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.