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; }
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; } }
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; }
public static Message convert2RMQMessage(JmsBaseMessage jmsMsg) throws Exception { Message rocketmqMsg = new MessageExt(); rocketmqMsg.setBody(MessageConverter.getContentFromJms(jmsMsg));
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; }
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; }
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; } }
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; } }
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; }
message.setBuyerId("buyerid123"); message.setFlag(123); message.setBody("body".getBytes()); messageList.add(message);
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; }
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; }
@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); }
@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); }
@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); }
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; }
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; }
message.setBuyerId("buyerid123"); message.setFlag(123); message.setBody("body".getBytes()); messageList.add(message);
msg.setBody(prevBody);