updated docs
Signed-off-by: minghuaw <michael.wu1107@gmail.com>
This commit is contained in:
parent
1188f17aea
commit
f7d3b8696b
|
@ -4,10 +4,10 @@
|
|||
//! With docker: docker run -it --rm -e ARTEMIS_USERNAME=guest -e ARTEMIS_PASSWORD=guest -p 5672:5672 vromero/activemq-artemis
|
||||
|
||||
use cloudevents::{
|
||||
binding::fe2o3_amqp::EventMessage, message::MessageDeserializer, Event, EventBuilder,
|
||||
binding::fe2o3_amqp::{EventMessage, AmqpMessage}, message::MessageDeserializer, Event, EventBuilder,
|
||||
EventBuilderV10, AttributesReader, event::ExtensionValue,
|
||||
};
|
||||
use fe2o3_amqp::{types::messaging::Message, Connection, Receiver, Sender, Session};
|
||||
use fe2o3_amqp::{Connection, Receiver, Sender, Session};
|
||||
use serde_json::{json, from_slice, from_str};
|
||||
|
||||
type BoxError = Box<dyn std::error::Error>;
|
||||
|
@ -27,7 +27,7 @@ async fn send_binary_event(sender: &mut Sender, i: usize, value: serde_json::Val
|
|||
.data("application/json", value)
|
||||
.build()?;
|
||||
let event_message = EventMessage::from_binary_event(event)?;
|
||||
let message = Message::from(event_message);
|
||||
let message = AmqpMessage::from(event_message);
|
||||
sender.send(message).await?.accepted_or("not accepted")?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ async fn send_structured_event(sender: &mut Sender, i: usize, value: serde_json:
|
|||
.data("application/json", value)
|
||||
.build()?;
|
||||
let event_message = EventMessage::from_structured_event(event)?;
|
||||
let message = Message::from(event_message);
|
||||
let message = AmqpMessage::from(event_message);
|
||||
sender.send(message).await?.accepted_or("not accepted")?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -25,24 +25,45 @@ mod constants;
|
|||
///
|
||||
/// The generic parameter can be anything that implements `Serialize` and `Deserialize` but is of
|
||||
/// no importance because all CloudEvents are using the `Body::Data` as the body section type. For
|
||||
/// convenience, this type alias chose `Value` as the value of the generic parameter
|
||||
/// convenience, this type alias chooses `Value` as the value of the generic parameter
|
||||
pub type AmqpMessage = Message<Value>;
|
||||
|
||||
/// Type alias for an AMQP 1.0 Body
|
||||
///
|
||||
/// The generic parameter can be anything that implements `Serialize` and `Deserialize` but is of
|
||||
/// no importance because all CloudEvents are using the `Body::Data` as the body section type. For
|
||||
/// convenience, this type alias chose `Value` as the value of the generic parameter
|
||||
/// convenience, this type alias chooses `Value` as the value of the generic parameter
|
||||
pub type AmqpBody = Body<Value>;
|
||||
|
||||
/// The receiver of the event can distinguish between the two modes by inspecting the content-type
|
||||
/// message property field. If the value is prefixed with the CloudEvents media type
|
||||
/// application/cloudevents, indicating the use of a known event format, the receiver uses
|
||||
/// structured mode, otherwise it defaults to binary mode.
|
||||
/// This struct contains the necessary fields required for AMQP 1.0 binding.
|
||||
/// It provides conversion between [`Event`] and [`AmqpMessage`]
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ## [`Event`] -> [`AmqpMessage`] in binary content mode
|
||||
///
|
||||
/// ```rust
|
||||
/// let event_message = EventMessage::from_binary_event(event).unwrap();
|
||||
/// let amqp_message = AmqpMessage:from(event_message);
|
||||
/// ```
|
||||
///
|
||||
/// ## [`Event`] -> [`AmqpMessage`] in structured content mode
|
||||
///
|
||||
/// ```rust
|
||||
/// let event_message = EventMessage::from_structured_event(event).unwrap();
|
||||
/// let amqp_message = AmqpMessage:from(event_message);
|
||||
/// ```
|
||||
///
|
||||
/// ## [`AmqpMessage`] -> [`Event`]
|
||||
///
|
||||
/// ```rust
|
||||
/// let event_message = EventMessage::from(amqp_message);
|
||||
/// let event = MessageDeserializer::into_event(event_message).unwrap();
|
||||
/// ```
|
||||
pub struct EventMessage {
|
||||
content_type: Option<Symbol>,
|
||||
application_properties: Option<ApplicationProperties>,
|
||||
body: AmqpBody,
|
||||
pub content_type: Option<Symbol>,
|
||||
pub application_properties: Option<ApplicationProperties>,
|
||||
pub body: AmqpBody,
|
||||
}
|
||||
|
||||
impl EventMessage {
|
||||
|
|
Loading…
Reference in New Issue