count++; if (count >= currentBatch || buffer.length() >= traceProducer.getMaxMessageSize()) { sendTraceDataByMQ(keySet, buffer.toString());
/** * 实际批量发送数据 */ private void flushData(List<OnsTraceTransferBean> transBeanList, String topic, String currentRegionId) { if (transBeanList.size() == 0) { return; } // 临时缓冲区 StringBuilder buffer = new StringBuilder(1024); int count = 0; Set<String> keySet = new HashSet<String>(); for (OnsTraceTransferBean bean : transBeanList) { keySet.addAll(bean.getTransKey()); buffer.append(bean.getTransData()); count++; // 保证包的大小不要超过上限 if (buffer.length() >= traceProducer.getMaxMessageSize()) { sendTraceDataByMQ(keySet, buffer.toString(), topic, currentRegionId); // 发送完成,清除临时缓冲区 buffer.delete(0, buffer.length()); keySet.clear(); count = 0; } } if (count > 0) { sendTraceDataByMQ(keySet, buffer.toString(), topic, currentRegionId); } transBeanList.clear(); }
/** * 实际批量发送数据 */ private void flushData(List<OnsTraceTransferBean> transBeanList, String currentRegionId) { if (transBeanList.size() == 0) { return; } // 临时缓冲区 StringBuilder buffer = new StringBuilder(1024); int count = 0; Set<String> keySet = new HashSet<String>(); for (OnsTraceTransferBean bean : transBeanList) { keySet.addAll(bean.getTransKey()); buffer.append(bean.getTransData()); count++; // 保证包的大小不要超过上限 if (buffer.length() >= traceProducer.getMaxMessageSize()) { sendTraceDataByMQ(keySet, buffer.toString(), currentRegionId); // 发送完成,清除临时缓冲区 buffer.delete(0, buffer.length()); keySet.clear(); count = 0; } } if (count > 0) { sendTraceDataByMQ(keySet, buffer.toString(), currentRegionId); } transBeanList.clear(); }
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 (defaultMQProducer != null && msg.getBody().length > defaultMQProducer.getMaxMessageSize()) { throw new MQClientException(ResponseCode.MESSAGE_ILLEGAL, "the message body size over max value, MAX: " + defaultMQProducer.getMaxMessageSize()); } } }
/** * 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()); } }
/** * 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()); } }