Skip to content

Commit abfdf44

Browse files
authored
Merge pull request #67 from duhenglucky/metadata
[ISSUE #68]Export offset and partition meta data
2 parents 3e999d6 + df8d962 commit abfdf44

File tree

1 file changed

+26
-0
lines changed
  • openmessaging-api/src/main/java/io/openmessaging/api

1 file changed

+26
-0
lines changed

openmessaging-api/src/main/java/io/openmessaging/api/Message.java

+26
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,28 @@ public void setStartDeliverTime(final long value) {
237237
putSystemProperties(SystemPropKey.STARTDELIVERTIME, String.valueOf(value));
238238
}
239239

240+
/**
241+
* Get the offset of this message assigned by the broker.
242+
*
243+
* @return Message offset in relative partition
244+
*/
245+
public long getOffset() {
246+
String v = getSystemProperties(SystemPropKey.CONSUMEOFFSET);
247+
if (v != null) {
248+
return Long.parseLong(v);
249+
}
250+
return 0;
251+
}
252+
253+
/**
254+
* Get the partition to which the message belongs.
255+
*
256+
* @return Message offset in relative partition
257+
*/
258+
public TopicPartition getTopicPartition() {
259+
return new TopicPartition(topic, getSystemProperties(SystemPropKey.PARTITION));
260+
}
261+
240262
@Override
241263
public String toString() {
242264
return "Message [topic=" + topic + ", systemProperties=" + systemProperties + ", userProperties=" + userProperties + ", body="
@@ -253,5 +275,9 @@ static public class SystemPropKey {
253275
public static final String BORNHOST = "__BORNHOST";
254276

255277
public static final String STARTDELIVERTIME = "__STARTDELIVERTIME";
278+
279+
public static final String CONSUMEOFFSET = "__CONSUMEOFFSET";
280+
281+
public static final String PARTITION = "__PARTITION";
256282
}
257283
}

0 commit comments

Comments
 (0)