当前位置: 首页>>代码示例>>Java>>正文


Java Message.getBody方法代码示例

本文整理汇总了Java中org.apache.rocketmq.common.message.Message.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getBody方法的具体用法?Java Message.getBody怎么用?Java Message.getBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.rocketmq.common.message.Message的用法示例。


在下文中一共展示了Message.getBody方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkMessage

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
 * Validate message
 *
 * @param msg
 * @param defaultMQProducer
 * @throws 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");
    }

    /**
     * 消息内容不要超过4M
     */
    if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) {
        throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL,
            "the message body size over max value, MAX: " + defaultMQProducer.getMaxMessageSize());
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:33,代码来源:Validators.java

示例2: tryToCompressMessage

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
private boolean tryToCompressMessage(final Message msg) {
    if (msg instanceof MessageBatch) {
        //batch dose not support compressing right now
        return false;
    }
    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;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:24,代码来源:DefaultMQProducerImpl.java

示例3: checkMessage

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
 * Validate message
 *
 * @param msg
 * @param defaultMQProducer
 * @throws 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());
    }
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:29,代码来源:Validators.java

示例4: tryToCompressMessage

import org.apache.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;
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:20,代码来源:DefaultMQProducerImpl.java

示例5: next

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Override public List<Message> next() {
    int nextIndex = currIndex;
    int totalSize = 0;
    for (; nextIndex < messages.size(); nextIndex++) {
        Message message = messages.get(nextIndex);
        int tmpSize = message.getTopic().length() + message.getBody().length;
        Map<String, String> properties = message.getProperties();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            tmpSize += entry.getKey().length() + entry.getValue().length();
        }
        tmpSize = tmpSize + 20; //for log overhead
        if (tmpSize > sizeLimit) {
            //it is unexpected that single message exceeds the sizeLimit
            //here just let it go, otherwise it will block the splitting process
            if (nextIndex - currIndex == 0) {
                //if the next sublist has no element, add this one and then break, otherwise just break
                nextIndex++;
            }
            break;
        }
        if (tmpSize + totalSize > sizeLimit) {
            break;
        } else {
            totalSize += tmpSize;
        }

    }
    List<Message> subList = messages.subList(currIndex, nextIndex);
    currIndex = nextIndex;
    return subList;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:32,代码来源:SplitBatchProducer.java


注:本文中的org.apache.rocketmq.common.message.Message.getBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。