org.apache.rocketmq.common.message.Message.setBody()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中org.apache.rocketmq.common.message.Message.setBody()方法的一些代码示例,展示了Message.setBody()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setBody()方法的具体详情如下:
包路径:org.apache.rocketmq.common.message.Message
类名称:Message
方法名:setBody

Message.setBody介绍

暂无

代码示例

代码示例来源:origin: apache/rocketmq

private static Message buildMessage(final String topic, final int messageSize) throws UnsupportedEncodingException {
  Message msg = new Message();
  msg.setTopic(topic);
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < messageSize; i += 11) {
    sb.append("hello jodie");
  }
  msg.setBody(sb.toString().getBytes(MixAll.DEFAULT_CHARSET));
  return msg;
}

代码示例来源:origin: apache/rocketmq

private static Message buildMessage(final int messageSize, final String topic) throws UnsupportedEncodingException {
    Message msg = new Message();
    msg.setTopic(topic);

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 10) {
      sb.append("hello baby");
    }

    msg.setBody(sb.toString().getBytes(RemotingHelper.DEFAULT_CHARSET));

    return msg;
  }
}

代码示例来源:origin: apache/rocketmq

public static Message decodeMessage(ByteBuffer byteBuffer) throws Exception {
  Message message = new Message();
  // 1 TOTALSIZE
  byteBuffer.getInt();
  // 2 MAGICCODE
  byteBuffer.getInt();
  // 3 BODYCRC
  byteBuffer.getInt();
  // 4 FLAG
  int flag = byteBuffer.getInt();
  message.setFlag(flag);
  // 5 BODY
  int bodyLen = byteBuffer.getInt();
  byte[] body = new byte[bodyLen];
  byteBuffer.get(body);
  message.setBody(body);
  // 6 properties
  short propertiesLen = byteBuffer.getShort();
  byte[] propertiesBytes = new byte[propertiesLen];
  byteBuffer.get(propertiesBytes);
  message.setProperties(string2messageProperties(new String(propertiesBytes, CHARSET_UTF8)));
  return message;
}

代码示例来源:origin: apache/rocketmq-externals

public static Message convert2RMQMessage(JmsBaseMessage jmsMsg) throws Exception {
  Message rocketmqMsg = new MessageExt();
  rocketmqMsg.setBody(MessageConverter.getContentFromJms(jmsMsg));

代码示例来源:origin: apache/rocketmq

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;
}

代码示例来源:origin: apache/rocketmq

public static org.apache.rocketmq.common.message.Message msgConvert(BytesMessage omsMessage) {
  org.apache.rocketmq.common.message.Message rmqMessage = new org.apache.rocketmq.common.message.Message();
  rmqMessage.setBody(omsMessage.getBody(byte[].class));
  KeyValue sysHeaders = omsMessage.sysHeaders();
  KeyValue userHeaders = omsMessage.userHeaders();
  //All destinations in RocketMQ use Topic
  rmqMessage.setTopic(sysHeaders.getString(BuiltinKeys.DESTINATION));
  if (sysHeaders.containsKey(BuiltinKeys.START_TIME)) {
    long deliverTime = sysHeaders.getLong(BuiltinKeys.START_TIME, 0);
    if (deliverTime > 0) {
      rmqMessage.putUserProperty(RocketMQConstants.START_DELIVER_TIME, String.valueOf(deliverTime));
    }
  }
  for (String key : userHeaders.keySet()) {
    MessageAccessor.putProperty(rmqMessage, key, userHeaders.getString(key));
  }
  //System headers has a high priority
  for (String key : sysHeaders.keySet()) {
    MessageAccessor.putProperty(rmqMessage, key, sysHeaders.getString(key));
  }
  return rmqMessage;
}

代码示例来源:origin: didi/DDMQ

private static Message buildMessage(final int messageSize, final String topic) throws UnsupportedEncodingException {
    Message msg = new Message();
    msg.setTopic(topic);

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 10) {
      sb.append("hello baby");
    }

    msg.setBody(sb.toString().getBytes(RemotingHelper.DEFAULT_CHARSET));

    return msg;
  }
}

代码示例来源:origin: didi/DDMQ

private static Message buildMessage(final int messageSize) throws UnsupportedEncodingException {
    Message msg = new Message();
    msg.setTopic("BenchmarkTest");

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 10) {
      sb.append("hello baby");
    }

    msg.setBody(sb.toString().getBytes(RemotingHelper.DEFAULT_CHARSET));

    return msg;
  }
}

代码示例来源:origin: didi/DDMQ

private static Message buildMessage(final String topic, final int messageSize) throws UnsupportedEncodingException {
  Message msg = new Message();
  msg.setTopic(topic);
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < messageSize; i += 11) {
    sb.append("hello jodie");
  }
  msg.setBody(sb.toString().getBytes(MixAll.DEFAULT_CHARSET));
  return msg;
}

代码示例来源:origin: apache/rocketmq

message.setBuyerId("buyerid123");
message.setFlag(123);
message.setBody("body".getBytes());
messageList.add(message);

代码示例来源:origin: apache/rocketmq

msg.setBody(prevBody);
msg.setBody(prevBody);

代码示例来源:origin: didi/DDMQ

public static Message decodeMessage(ByteBuffer byteBuffer) throws Exception {
  Message message = new Message();
  // 1 TOTALSIZE
  byteBuffer.getInt();
  // 2 MAGICCODE
  byteBuffer.getInt();
  // 3 BODYCRC
  byteBuffer.getInt();
  // 4 FLAG
  int flag = byteBuffer.getInt();
  message.setFlag(flag);
  // 5 BODY
  int bodyLen = byteBuffer.getInt();
  byte[] body = new byte[bodyLen];
  byteBuffer.get(body);
  message.setBody(body);
  // 6 properties
  short propertiesLen = byteBuffer.getShort();
  byte[] propertiesBytes = new byte[propertiesLen];
  byteBuffer.get(propertiesBytes);
  message.setProperties(string2messageProperties(new String(propertiesBytes, CHARSET_UTF8)));
  return message;
}

代码示例来源:origin: didi/DDMQ

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;
}

代码示例来源:origin: didi/DDMQ

@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSynSendZeroSizeBodyMessage() throws Exception {
  Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
  msg.setBody(new byte[0]);
  producer.send(msg);
}

代码示例来源:origin: didi/DDMQ

@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSynSendOutOfSizeBodyMessage() throws Exception {
  Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
  msg.setBody(new byte[1024 * 1024 * 4 + 1]);
  producer.send(msg);
}

代码示例来源:origin: didi/DDMQ

@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSynSendNullBodyMessage() throws Exception {
  Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
  msg.setBody(null);
  producer.send(msg);
}

代码示例来源:origin: didi/DDMQ

public static org.apache.rocketmq.common.message.Message msgConvert(BytesMessage omsMessage) {
  org.apache.rocketmq.common.message.Message rmqMessage = new org.apache.rocketmq.common.message.Message();
  rmqMessage.setBody(omsMessage.getBody());
  KeyValue headers = omsMessage.headers();
  KeyValue properties = omsMessage.properties();
  //All destinations in RocketMQ use Topic
  if (headers.containsKey(MessageHeader.TOPIC)) {
    rmqMessage.setTopic(headers.getString(MessageHeader.TOPIC));
    rmqMessage.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
  } else {
    rmqMessage.setTopic(headers.getString(MessageHeader.QUEUE));
    rmqMessage.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "QUEUE");
  }
  for (String key : properties.keySet()) {
    MessageAccessor.putProperty(rmqMessage, key, properties.getString(key));
  }
  //Headers has a high priority
  for (String key : headers.keySet()) {
    MessageAccessor.putProperty(rmqMessage, key, headers.getString(key));
  }
  return rmqMessage;
}

代码示例来源:origin: org.apache.rocketmq/rocketmq-tools

private static Message buildMessage(final String topic, final int messageSize) throws UnsupportedEncodingException {
  Message msg = new Message();
  msg.setTopic(topic);
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < messageSize; i += 11) {
    sb.append("hello jodie");
  }
  msg.setBody(sb.toString().getBytes(MixAll.DEFAULT_CHARSET));
  return msg;
}

代码示例来源:origin: didi/DDMQ

message.setBuyerId("buyerid123");
message.setFlag(123);
message.setBody("body".getBytes());
messageList.add(message);

代码示例来源:origin: didi/DDMQ

msg.setBody(prevBody);

相关文章