1919import java .io .Serializable ;
2020import java .util .Properties ;
2121
22+ /**
23+ * The {@code Message} interface is the root interface of all OMS messages, and the most commonly used OMS message is
24+ * {@link Message}.
25+ * <p>
26+ * Most message-oriented middleware (MOM) products treat messages as lightweight entities that consist of header and
27+ * body and is used by separate applications to exchange a piece of information, like <a
28+ * href="http://rocketmq.apache.org/">Apache RocketMQ</a>.
29+ * <p>
30+ * The header contains fields used by the messaging system that describes the message's meta information, while the body
31+ * contains the application data being transmitted.
32+ * <p>
33+ * As for the message header, OMS defines two kinds types: userProperties and systemProperties with respect to
34+ * flexibility in vendor implementation and user usage.
35+ * <ul>
36+ * <li>
37+ * System Properties, OMS defines some standard attributes in {@link SystemPropKey} that represent the characteristics
38+ * of the message.
39+ * </li>
40+ * <li>
41+ * User properties, some OMS vendors may require enhanced extra attributes of the message or some users may want to
42+ * clarify some customized attributes to draw the body. OMS provides the improved scalability for these scenarios.
43+ * </li>
44+ * </ul>
45+ * The body contains the application data being transmitted, which is generally ignored by the messaging system and
46+ * simply transmitted to its destination.
47+ * <p>
48+ * In BytesMessage, the body is just a byte array, may be compressed and uncompressed in the transmitting process by the
49+ * messaging system. The application is responsible for explaining the concrete content and format of the message body,
50+ * OMS is never aware of that.
51+ *
52+ * The body part is placed in the implementation classes of {@code Message}.
53+ *
54+ * @version OMS 1.2.0
55+ * @since OMS 1.2.0
56+ */
2257public class Message implements Serializable {
2358
2459 private static final long serialVersionUID = -1385924226856188094L ;
2560
26-
2761 protected Properties systemProperties ;
2862
29-
3063 private String topic ;
3164
32-
3365 private Properties userProperties ;
3466
35-
3667 private byte [] body ;
3768
38-
3969 public Message () {
4070 this (null , null , "" , null );
4171 }
4272
43-
4473 public Message (String topic , String tag , String key , byte [] body ) {
4574 this .topic = topic ;
4675 this .body = body ;
@@ -49,7 +78,6 @@ public Message(String topic, String tag, String key, byte[] body) {
4978 this .putSystemProperties (SystemPropKey .KEY , key );
5079 }
5180
52-
5381 public void putSystemProperties (final String key , final String value ) {
5482 if (null == this .systemProperties ) {
5583 this .systemProperties = new Properties ();
@@ -60,12 +88,10 @@ public void putSystemProperties(final String key, final String value) {
6088 }
6189 }
6290
63-
6491 public Message (String topic , String tags , byte [] body ) {
6592 this (topic , tags , "" , body );
6693 }
6794
68-
6995 public void putUserProperties (final String key , final String value ) {
7096 if (null == this .userProperties ) {
7197 this .userProperties = new Properties ();
@@ -76,7 +102,6 @@ public void putUserProperties(final String key, final String value) {
76102 }
77103 }
78104
79-
80105 public String getUserProperties (final String key ) {
81106 if (null != this .userProperties ) {
82107 return (String ) this .userProperties .get (key );
@@ -85,22 +110,18 @@ public String getUserProperties(final String key) {
85110 return null ;
86111 }
87112
88-
89113 public String getTopic () {
90114 return topic ;
91115 }
92116
93-
94117 public void setTopic (String topic ) {
95118 this .topic = topic ;
96119 }
97120
98-
99121 public String getTag () {
100122 return this .getSystemProperties (SystemPropKey .TAG );
101123 }
102124
103-
104125 public String getSystemProperties (final String key ) {
105126 if (null != this .systemProperties ) {
106127 return this .systemProperties .getProperty (key );
@@ -109,27 +130,22 @@ public String getSystemProperties(final String key) {
109130 return null ;
110131 }
111132
112-
113133 public void setTag (String tag ) {
114134 this .putSystemProperties (SystemPropKey .TAG , tag );
115135 }
116136
117-
118137 public String getKey () {
119138 return this .getSystemProperties (SystemPropKey .KEY );
120139 }
121140
122-
123141 public void setKey (String key ) {
124142 this .putSystemProperties (SystemPropKey .KEY , key );
125143 }
126144
127-
128145 public String getMsgID () {
129146 return this .getSystemProperties (SystemPropKey .MSGID );
130147 }
131148
132-
133149 public void setMsgID (String msgid ) {
134150 this .putSystemProperties (SystemPropKey .MSGID , msgid );
135151 }
@@ -164,7 +180,6 @@ public void setBody(byte[] body) {
164180 this .body = body ;
165181 }
166182
167-
168183 public int getReconsumeTimes () {
169184 String pro = this .getSystemProperties (SystemPropKey .RECONSUMETIMES );
170185 if (pro != null ) {
@@ -174,12 +189,10 @@ public int getReconsumeTimes() {
174189 return 0 ;
175190 }
176191
177-
178192 public void setReconsumeTimes (final int value ) {
179193 putSystemProperties (SystemPropKey .RECONSUMETIMES , String .valueOf (value ));
180194 }
181195
182-
183196 public long getBornTimestamp () {
184197 String pro = this .getSystemProperties (SystemPropKey .BORNTIMESTAMP );
185198 if (pro != null ) {
@@ -189,23 +202,19 @@ public long getBornTimestamp() {
189202 return 0L ;
190203 }
191204
192-
193205 public void setBornTimestamp (final long value ) {
194206 putSystemProperties (SystemPropKey .BORNTIMESTAMP , String .valueOf (value ));
195207 }
196208
197-
198209 public String getBornHost () {
199210 String pro = this .getSystemProperties (SystemPropKey .BORNHOST );
200211 return pro == null ? "" : pro ;
201212 }
202213
203-
204214 public void setBornHost (final String value ) {
205215 putSystemProperties (SystemPropKey .BORNHOST , value );
206216 }
207217
208-
209218 public long getStartDeliverTime () {
210219 String pro = this .getSystemProperties (SystemPropKey .STARTDELIVERTIME );
211220 if (pro != null ) {
@@ -224,7 +233,6 @@ public void setShardingKey(final String value) {
224233 putSystemProperties (SystemPropKey .SHARDINGKEY , value );
225234 }
226235
227-
228236 public void setStartDeliverTime (final long value ) {
229237 putSystemProperties (SystemPropKey .STARTDELIVERTIME , String .valueOf (value ));
230238 }
@@ -235,7 +243,6 @@ public String toString() {
235243 + (body != null ? body .length : 0 ) + "]" ;
236244 }
237245
238-
239246 static public class SystemPropKey {
240247 public static final String TAG = "__TAG" ;
241248 public static final String KEY = "__KEY" ;
0 commit comments