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


Java Message.getBody方法代码示例

本文整理汇总了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());
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:29,代码来源:Validators.java

示例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);
    }
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:29,代码来源:Validators.java

示例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;
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:21,代码来源:DefaultMQProducerImpl.java

示例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;
}
 
开发者ID:cairenjie1985,项目名称:springBoot-demo,代码行数:16,代码来源:MessageListener.java


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