[][src]Struct svc_agent::mqtt::Agent

pub struct Agent { /* fields omitted */ }

Methods

impl Agent[src]

pub fn address(&self) -> &Address[src]

pub fn id(&self) -> &AgentId[src]

pub fn publish(
    &mut self,
    message: Box<dyn IntoPublishableDump>
) -> Result<(), Error>
[src]

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(Box::new(message))?;

pub fn publish_dump(&mut self, dump: PublishableDump) -> Result<(), Error>[src]

Publish a dumped message.

Arguments

  • dump – message dump.

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 dump = Box::new(message).into_dump();
agent.publish_dump(dump.clone())?;
println!("Message published: {}", dump);

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

Subscribe to a topic.

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),
)?;

Trait Implementations

impl Clone for Agent[src]

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

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

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

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

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> 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<V, T> VZip<V> for T where
    V: MultiLane<T>,