Skip to content

Commit adb3f25

Browse files
committed
updated docs
Signed-off-by: minghuaw <[email protected]>
1 parent b9fa319 commit adb3f25

File tree

2 files changed

+34
-13
lines changed
  • example-projects/fe2o3-amqp-example/src
  • src/binding/fe2o3_amqp

2 files changed

+34
-13
lines changed

example-projects/fe2o3-amqp-example/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
//! With docker: docker run -it --rm -e ARTEMIS_USERNAME=guest -e ARTEMIS_PASSWORD=guest -p 5672:5672 vromero/activemq-artemis
55
66
use cloudevents::{
7-
binding::fe2o3_amqp::EventMessage, message::MessageDeserializer, Event, EventBuilder,
7+
binding::fe2o3_amqp::{EventMessage, AmqpMessage}, message::MessageDeserializer, Event, EventBuilder,
88
EventBuilderV10, AttributesReader, event::ExtensionValue,
99
};
10-
use fe2o3_amqp::{types::messaging::Message, Connection, Receiver, Sender, Session};
10+
use fe2o3_amqp::{Connection, Receiver, Sender, Session};
1111
use serde_json::{json, from_slice, from_str};
1212

1313
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
2727
.data("application/json", value)
2828
.build()?;
2929
let event_message = EventMessage::from_binary_event(event)?;
30-
let message = Message::from(event_message);
30+
let message = AmqpMessage::from(event_message);
3131
sender.send(message).await?.accepted_or("not accepted")?;
3232
Ok(())
3333
}
@@ -41,7 +41,7 @@ async fn send_structured_event(sender: &mut Sender, i: usize, value: serde_json:
4141
.data("application/json", value)
4242
.build()?;
4343
let event_message = EventMessage::from_structured_event(event)?;
44-
let message = Message::from(event_message);
44+
let message = AmqpMessage::from(event_message);
4545
sender.send(message).await?.accepted_or("not accepted")?;
4646
Ok(())
4747
}

src/binding/fe2o3_amqp/mod.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,45 @@ mod constants;
2525
///
2626
/// The generic parameter can be anything that implements `Serialize` and `Deserialize` but is of
2727
/// no importance because all CloudEvents are using the `Body::Data` as the body section type. For
28-
/// convenience, this type alias chose `Value` as the value of the generic parameter
28+
/// convenience, this type alias chooses `Value` as the value of the generic parameter
2929
pub type AmqpMessage = Message<Value>;
3030

3131
/// Type alias for an AMQP 1.0 Body
3232
///
3333
/// The generic parameter can be anything that implements `Serialize` and `Deserialize` but is of
3434
/// no importance because all CloudEvents are using the `Body::Data` as the body section type. For
35-
/// convenience, this type alias chose `Value` as the value of the generic parameter
35+
/// convenience, this type alias chooses `Value` as the value of the generic parameter
3636
pub type AmqpBody = Body<Value>;
3737

38-
/// The receiver of the event can distinguish between the two modes by inspecting the content-type
39-
/// message property field. If the value is prefixed with the CloudEvents media type
40-
/// application/cloudevents, indicating the use of a known event format, the receiver uses
41-
/// structured mode, otherwise it defaults to binary mode.
38+
/// This struct contains the necessary fields required for AMQP 1.0 binding.
39+
/// It provides conversion between [`Event`] and [`AmqpMessage`]
40+
///
41+
/// # Examples
42+
///
43+
/// ## [`Event`] -> [`AmqpMessage`] in binary content mode
44+
///
45+
/// ```rust
46+
/// let event_message = EventMessage::from_binary_event(event).unwrap();
47+
/// let amqp_message = AmqpMessage:from(event_message);
48+
/// ```
49+
///
50+
/// ## [`Event`] -> [`AmqpMessage`] in structured content mode
51+
///
52+
/// ```rust
53+
/// let event_message = EventMessage::from_structured_event(event).unwrap();
54+
/// let amqp_message = AmqpMessage:from(event_message);
55+
/// ```
56+
///
57+
/// ## [`AmqpMessage`] -> [`Event`]
58+
///
59+
/// ```rust
60+
/// let event_message = EventMessage::from(amqp_message);
61+
/// let event = MessageDeserializer::into_event(event_message).unwrap();
62+
/// ```
4263
pub struct EventMessage {
43-
content_type: Option<Symbol>,
44-
application_properties: Option<ApplicationProperties>,
45-
body: AmqpBody,
64+
pub content_type: Option<Symbol>,
65+
pub application_properties: Option<ApplicationProperties>,
66+
pub body: AmqpBody,
4667
}
4768

4869
impl EventMessage {

0 commit comments

Comments
 (0)