[−][src]Struct svc_agent::mqtt::Agent
Implementations
impl Agent
[src]
pub fn address(&self) -> &Address
[src]
pub fn id(&self) -> &AgentId
[src]
pub fn publish<T: Serialize>(
&mut self,
message: OutgoingMessage<T>
) -> Result<(), Error>
[src]
&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)?;
pub fn publish_publishable(
&mut self,
message: Box<dyn IntoPublishableMessage>
) -> Result<(), Error>
[src]
&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);
pub fn subscribe<S>(
&mut self,
subscription: &S,
qos: QoS,
maybe_group: Option<&SharedGroup>
) -> Result<(), Error> where
S: SubscriptionTopic,
[src]
&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_group
– SharedGroup 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), }
Trait Implementations
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,