本文整理汇总了Java中com.alibaba.rocketmq.common.message.Message.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getBody方法的具体用法?Java Message.getBody怎么用?Java Message.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.rocketmq.common.message.Message
的用法示例。
在下文中一共展示了Message.getBody方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkMessage
import com.alibaba.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
* Validate message
*
* @param msg
* @param defaultMQProducer
* @throws com.alibaba.rocketmq.client.exception.MQClientException
*/
public static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer)
throws MQClientException {
if (null == msg) {
throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message is null");
}
// topic
Validators.checkTopic(msg.getTopic());
// body
if (null == msg.getBody()) {
throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message body is null");
}
if (0 == msg.getBody().length) {
throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message body length is zero");
}
if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) {
throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL,
"the message body size over max value, MAX: " + defaultMQProducer.getMaxMessageSize());
}
}
示例2: checkMessage
import com.alibaba.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
* message 有效性检查
*
* @param msg
* @param defaultMQProducer
* @throws com.alibaba.rocketmq.client.exception.MQClientException
*/
public static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer)
throws MQClientException {
if (null == msg) {
throw new MQClientException("the message is null", null);
}
// topic
Validators.checkTopic(msg.getTopic());
// body
if (null == msg.getBody()) {
throw new MQClientException("the message body is null", null);
}
if (0 == msg.getBody().length) {
throw new MQClientException("the message body length is zero", null);
}
if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) {
throw new MQClientException("the message body size over max value, MAX: "
+ defaultMQProducer.getMaxMessageSize(), null);
}
}
示例3: tryToCompressMessage
import com.alibaba.rocketmq.common.message.Message; //导入方法依赖的package包/类
private boolean tryToCompressMessage(final Message msg) {
byte[] body = msg.getBody();
if (body != null) {
if (body.length >= this.defaultMQProducer.getCompressMsgBodyOverHowmuch()) {
try {
byte[] data = UtilAll.compress(body, zipCompressLevel);
if (data != null) {
msg.setBody(data);
return true;
}
}
catch (IOException e) {
log.error("tryToCompressMessage exception", e);
log.warn(msg.toString());
}
}
}
return false;
}
示例4: consumeMessage
import com.alibaba.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
Message msg = msgs.get(0);
String body = null;
try {
body = new String(msg.getBody(), "utf-8");
if("test".equals(msg.getTopic())){
logger.info(body);
}
} catch (Exception e) {
logger.error("consumeMessage error, msg=" + msg.toString(), e);
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}