public class Message extends Object implements Serializable
注意: 我们对每条消息的自定义键值对的长度没有限制, 但所有的自定义键值对, 系统键值对序列化后, 所占空间不能超过32767字节.
Modifier and Type | Class and Description |
---|---|
static class |
Message.SystemPropKey
该类预定义一些系统键.
|
Constructor and Description |
---|
Message()
默认构造函数; 必要属性后续通过Set方法设置.
|
Message(String topic,
String tags,
byte[] body)
消息有参构造函数
|
Message(String topic,
String tag,
String key,
byte[] body)
有参构造函数.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getBody() |
String |
getBornHost()
获取产生消息的主机.
|
long |
getBornTimestamp()
获取消息的生产时间
|
String |
getKey()
获取业务码
|
String |
getMsgID()
获取消息ID
|
long |
getOffset() |
int |
getReconsumeTimes()
消息消费时, 获取消息已经被重试消费的次数
|
String |
getShardingKey() |
long |
getStartDeliverTime()
获取定时消息开始投递时间.
|
String |
getTag()
获取消息标签
|
String |
getTopic()
获取消息的主题
|
TopicPartition |
getTopicPartition() |
Properties |
getUserProperties() |
String |
getUserProperties(String key)
获取用户自定义键的值
|
void |
putUserProperties(String key,
String value)
添加用户自定义属性键值对; 该键值对在消费消费时可被获取.
|
void |
setBody(byte[] body) |
void |
setBornHost(String value)
设置生产消息的主机
|
void |
setBornTimestamp(long value)
设置消息的产生时间.
|
void |
setKey(String key)
设置业务码
|
void |
setMsgID(String msgid)
设置该消息ID
|
void |
setReconsumeTimes(int value)
设置消息重试消费次数.
|
void |
setShardingKey(String value) |
void |
setStartDeliverTime(long value)
设置消息的定时投递时间(绝对时间),最大延迟时间为7天.
|
void |
setTag(String tag)
设置消息标签
|
void |
setTopic(String topic)
设置消息主题.
|
void |
setUserProperties(Properties userProperties) |
String |
toString() |
public Message()
public Message(String topic, String tag, String key, byte[] body)
topic
- 消息主题, 最长不超过255个字符; 由a-z, A-Z, 0-9, 以及中划线"-"和下划线"_"构成.tag
- 消息标签, 请使用合法标识符, 尽量简短且见名知意key
- 业务主键body
- 消息体, 消息体长度默认不超过4M, 具体请参阅集群部署文档描述.public void putUserProperties(String key, String value)
key
- 自定义键value
- 对应值public String getUserProperties(String key)
key
- 自定义键public String getTopic()
public void setTopic(String topic)
topic
- 消息主题public String getTag()
public void setTag(String tag)
tag
- 标签.public String getKey()
public void setKey(String key)
key
- 业务码public String getMsgID()
public void setMsgID(String msgid)
msgid
- 该消息ID.public Properties getUserProperties()
public void setUserProperties(Properties userProperties)
public byte[] getBody()
public void setBody(byte[] body)
public int getReconsumeTimes()
public void setReconsumeTimes(int value)
value
- 重试消费次数.public long getBornTimestamp()
public void setBornTimestamp(long value)
value
- 消息生产时间.public String getBornHost()
public void setBornHost(String value)
value
- 生产消息的主机public long getStartDeliverTime()
public String getShardingKey()
public void setShardingKey(String value)
public void setStartDeliverTime(long value)
设置消息的定时投递时间(绝对时间),最大延迟时间为7天.
public long getOffset()
public TopicPartition getTopicPartition()
Copyright © 2012–2020. All rights reserved.