Java Code Examples for org.apache.rocketmq.common.message.Message#setTags()
The following examples show how to use
org.apache.rocketmq.common.message.Message#setTags() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MQMessageFactory.java From DDMQ with Apache License 2.0 | 5 votes |
public static List<Object> getMsg(String topic, int msgSize, String tag) { List<Object> msgs = new ArrayList<Object>(); while (msgSize > 0) { Message msg = new Message(topic, (index++).toString().getBytes()); if (tag != null) { msg.setTags(tag); } msgs.add(msg); msgSize--; } return msgs; }
Example 2
Source File: AppendCallbackTest.java From DDMQ with Apache License 2.0 | 5 votes |
@Test public void testAppendMessageBatchEndOfFile() throws Exception { List<Message> messages = new ArrayList<>(); String topic = "test-topic"; int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); msg.setTopic(topic); msg.setTags("abc"); messages.add(msg); } MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); ByteBuffer buff = ByteBuffer.allocate(1024 * 10); //encounter end of file when append half of the data AppendMessageResult result = callback.doAppend(0, buff, 1000, messageExtBatch); assertEquals(AppendMessageStatus.END_OF_FILE, result.getStatus()); assertEquals(0, result.getWroteOffset()); assertEquals(0, result.getLogicsOffset()); assertEquals(1000, result.getWroteBytes()); assertEquals(8, buff.position()); //write blank size and magic value assertTrue(result.getMsgId().length() > 0); //should have already constructed some message ids }
Example 3
Source File: AppendCallbackTest.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
@Test public void testAppendMessageBatchEndOfFile() throws Exception{ List<Message> messages = new ArrayList<>(); String topic = "test-topic"; int queue= 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); msg.setTopic(topic); msg.setTags("abc"); messages.add(msg); } MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1",123)); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1",124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); ByteBuffer buff = ByteBuffer.allocate(1024 * 10); //encounter end of file when append half of the data AppendMessageResult result = callback.doAppend(0, buff, 1000, messageExtBatch); assertEquals(AppendMessageStatus.END_OF_FILE, result.getStatus()); assertEquals(0, result.getWroteOffset()); assertEquals(0, result.getLogicsOffset()); assertEquals(1000, result.getWroteBytes()); assertEquals(8, buff.position()); //write blank size and magic value assertTrue(result.getMsgId().length() > 0); //should have already constructed some message ids }
Example 4
Source File: MQMessageFactory.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
public static List<Object> getMsg(String topic, int msgSize, String tag) { List<Object> msgs = new ArrayList<Object>(); while (msgSize > 0) { Message msg = new Message(topic, (index++).toString().getBytes()); if (tag != null) { msg.setTags(tag); } msgs.add(msg); msgSize--; } return msgs; }
Example 5
Source File: MQProducter.java From j360-boot-app-all with Apache License 2.0 | 5 votes |
public void createPushMessage(Message message) { message.setTags("PUSH"); try { rocketMQProducerTemplate.send(message); } catch (MQBrokerException | MQClientException | RemotingException | InterruptedException e) { throw new ServiceException(DefaultErrorCode.SYSTEM_ERROR, e); } }
Example 6
Source File: AppendCallbackTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testAppendMessageBatchEndOfFile() throws Exception { List<Message> messages = new ArrayList<>(); String topic = "test-topic"; int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); msg.setTopic(topic); msg.setTags("abc"); messages.add(msg); } MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); ByteBuffer buff = ByteBuffer.allocate(1024 * 10); //encounter end of file when append half of the data AppendMessageResult result = callback.doAppend(0, buff, 1000, messageExtBatch); assertEquals(AppendMessageStatus.END_OF_FILE, result.getStatus()); assertEquals(0, result.getWroteOffset()); assertEquals(0, result.getLogicsOffset()); assertEquals(1000, result.getWroteBytes()); assertEquals(8, buff.position()); //write blank size and magic value assertTrue(result.getMsgId().length() > 0); //should have already constructed some message ids }
Example 7
Source File: AppendCallbackTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testAppendMessageBatchEndOfFile() throws Exception { List<Message> messages = new ArrayList<>(); String topic = "test-topic"; int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); msg.setTopic(topic); msg.setTags("abc"); messages.add(msg); } MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); ByteBuffer buff = ByteBuffer.allocate(1024 * 10); //encounter end of file when append half of the data AppendMessageResult result = callback.doAppend(0, buff, 1000, messageExtBatch); assertEquals(AppendMessageStatus.END_OF_FILE, result.getStatus()); assertEquals(0, result.getWroteOffset()); assertEquals(0, result.getLogicsOffset()); assertEquals(1000, result.getWroteBytes()); assertEquals(8, buff.position()); //write blank size and magic value assertTrue(result.getMsgId().length() > 0); //should have already constructed some message ids }
Example 8
Source File: MQMessageFactory.java From DDMQ with Apache License 2.0 | 5 votes |
public static List<Object> getMsg(String topic, int msgSize, String tag) { List<Object> msgs = new ArrayList<Object>(); while (msgSize > 0) { Message msg = new Message(topic, (index++).toString().getBytes()); if (tag != null) { msg.setTags(tag); } msgs.add(msg); msgSize--; } return msgs; }
Example 9
Source File: MQMessageFactory.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
public static List<Object> getMsg(String topic, int msgSize, String tag) { List<Object> msgs = new ArrayList<Object>(); while (msgSize > 0) { Message msg = new Message(topic, (index++).toString().getBytes()); if (tag != null) { msg.setTags(tag); } msgs.add(msg); msgSize--; } return msgs; }
Example 10
Source File: BatchSendIT.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 4 votes |
@Test public void testBatchSend_CheckProperties() throws Exception { List<Message> messageList = new ArrayList<>(); Message message = new Message(); message.setTopic(topic); message.setKeys("keys123"); message.setTags("tags123"); message.setWaitStoreMsgOK(false); message.setBuyerId("buyerid123"); message.setFlag(123); message.setBody("body".getBytes()); messageList.add(message); DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); SendResult sendResult = producer.send(messageList); Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus()); String[] offsetIds = sendResult.getOffsetMsgId().split(","); String[] msgIds = sendResult.getMsgId().split(","); Assert.assertEquals(messageList.size(), offsetIds.length); Assert.assertEquals(messageList.size(), msgIds.length); Thread.sleep(2000); Message messageByOffset = producer.viewMessage(offsetIds[0]); Message messageByMsgId = producer.viewMessage(topic, msgIds[0]); System.out.println(messageByOffset); System.out.println(messageByMsgId); Assert.assertEquals(message.getTopic(), messageByMsgId.getTopic()); Assert.assertEquals(message.getTopic(), messageByOffset.getTopic()); Assert.assertEquals(message.getKeys(), messageByOffset.getKeys()); Assert.assertEquals(message.getKeys(), messageByMsgId.getKeys()); Assert.assertEquals(message.getTags(), messageByOffset.getTags()); Assert.assertEquals(message.getTags(), messageByMsgId.getTags()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByOffset.isWaitStoreMsgOK()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByMsgId.isWaitStoreMsgOK()); Assert.assertEquals(message.getBuyerId(), messageByOffset.getBuyerId()); Assert.assertEquals(message.getBuyerId(), messageByMsgId.getBuyerId()); Assert.assertEquals(message.getFlag(), messageByOffset.getFlag()); Assert.assertEquals(message.getFlag(), messageByMsgId.getFlag()); }
Example 11
Source File: AppendCallbackTest.java From DDMQ with Apache License 2.0 | 4 votes |
@Test public void testAppendMessageBatchSucc() throws Exception { List<Message> messages = new ArrayList<>(); String topic = "test-topic"; int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); msg.setTopic(topic); msg.setTags("abc"); messages.add(msg); } MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); ByteBuffer buff = ByteBuffer.allocate(1024 * 10); AppendMessageResult allresult = callback.doAppend(0, buff, 1024 * 10, messageExtBatch); assertEquals(AppendMessageStatus.PUT_OK, allresult.getStatus()); assertEquals(0, allresult.getWroteOffset()); assertEquals(0, allresult.getLogicsOffset()); assertEquals(buff.position(), allresult.getWroteBytes()); assertEquals(messages.size(), allresult.getMsgNum()); Set<String> msgIds = new HashSet<>(); for (String msgId : allresult.getMsgId().split(",")) { assertEquals(32, msgId.length()); msgIds.add(msgId); } assertEquals(messages.size(), msgIds.size()); List<MessageExt> decodeMsgs = MessageDecoder.decodes((ByteBuffer) buff.flip()); assertEquals(decodeMsgs.size(), decodeMsgs.size()); long queueOffset = decodeMsgs.get(0).getQueueOffset(); long storeTimeStamp = decodeMsgs.get(0).getStoreTimestamp(); for (int i = 0; i < messages.size(); i++) { assertEquals(messages.get(i).getTopic(), decodeMsgs.get(i).getTopic()); assertEquals(new String(messages.get(i).getBody()), new String(decodeMsgs.get(i).getBody())); assertEquals(messages.get(i).getTags(), decodeMsgs.get(i).getTags()); assertEquals(messageExtBatch.getBornHostNameString(), decodeMsgs.get(i).getBornHostNameString()); assertEquals(messageExtBatch.getBornTimestamp(), decodeMsgs.get(i).getBornTimestamp()); assertEquals(storeTimeStamp, decodeMsgs.get(i).getStoreTimestamp()); assertEquals(queueOffset++, decodeMsgs.get(i).getQueueOffset()); } }
Example 12
Source File: BatchSendIT.java From rocketmq with Apache License 2.0 | 4 votes |
@Test public void testBatchSend_CheckProperties() throws Exception { List<Message> messageList = new ArrayList<>(); Message message = new Message(); message.setTopic(topic); message.setKeys("keys123"); message.setTags("tags123"); message.setWaitStoreMsgOK(false); message.setBuyerId("buyerid123"); message.setFlag(123); message.setBody("body".getBytes()); messageList.add(message); DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); SendResult sendResult = producer.send(messageList); Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus()); String[] offsetIds = sendResult.getOffsetMsgId().split(","); String[] msgIds = sendResult.getMsgId().split(","); Assert.assertEquals(messageList.size(), offsetIds.length); Assert.assertEquals(messageList.size(), msgIds.length); Thread.sleep(2000); Message messageByOffset = producer.viewMessage(offsetIds[0]); Message messageByMsgId = producer.viewMessage(topic, msgIds[0]); System.out.println(messageByOffset); System.out.println(messageByMsgId); Assert.assertEquals(message.getTopic(), messageByMsgId.getTopic()); Assert.assertEquals(message.getTopic(), messageByOffset.getTopic()); Assert.assertEquals(message.getKeys(), messageByOffset.getKeys()); Assert.assertEquals(message.getKeys(), messageByMsgId.getKeys()); Assert.assertEquals(message.getTags(), messageByOffset.getTags()); Assert.assertEquals(message.getTags(), messageByMsgId.getTags()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByOffset.isWaitStoreMsgOK()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByMsgId.isWaitStoreMsgOK()); Assert.assertEquals(message.getBuyerId(), messageByOffset.getBuyerId()); Assert.assertEquals(message.getBuyerId(), messageByMsgId.getBuyerId()); Assert.assertEquals(message.getFlag(), messageByOffset.getFlag()); Assert.assertEquals(message.getFlag(), messageByMsgId.getFlag()); }
Example 13
Source File: AppendCallbackTest.java From rocketmq with Apache License 2.0 | 4 votes |
@Test public void testAppendMessageBatchSucc() throws Exception { List<Message> messages = new ArrayList<>(); String topic = "test-topic"; int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); msg.setTopic(topic); msg.setTags("abc"); messages.add(msg); } MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); ByteBuffer buff = ByteBuffer.allocate(1024 * 10); AppendMessageResult allresult = callback.doAppend(0, buff, 1024 * 10, messageExtBatch); assertEquals(AppendMessageStatus.PUT_OK, allresult.getStatus()); assertEquals(0, allresult.getWroteOffset()); assertEquals(0, allresult.getLogicsOffset()); assertEquals(buff.position(), allresult.getWroteBytes()); assertEquals(messages.size(), allresult.getMsgNum()); Set<String> msgIds = new HashSet<>(); for (String msgId : allresult.getMsgId().split(",")) { assertEquals(32, msgId.length()); msgIds.add(msgId); } assertEquals(messages.size(), msgIds.size()); List<MessageExt> decodeMsgs = MessageDecoder.decodes((ByteBuffer) buff.flip()); assertEquals(decodeMsgs.size(), decodeMsgs.size()); long queueOffset = decodeMsgs.get(0).getQueueOffset(); long storeTimeStamp = decodeMsgs.get(0).getStoreTimestamp(); for (int i = 0; i < messages.size(); i++) { assertEquals(messages.get(i).getTopic(), decodeMsgs.get(i).getTopic()); assertEquals(new String(messages.get(i).getBody()), new String(decodeMsgs.get(i).getBody())); assertEquals(messages.get(i).getTags(), decodeMsgs.get(i).getTags()); assertEquals(messageExtBatch.getBornHostNameString(), decodeMsgs.get(i).getBornHostNameString()); assertEquals(messageExtBatch.getBornTimestamp(), decodeMsgs.get(i).getBornTimestamp()); assertEquals(storeTimeStamp, decodeMsgs.get(i).getStoreTimestamp()); assertEquals(queueOffset++, decodeMsgs.get(i).getQueueOffset()); } }
Example 14
Source File: AppendCallbackTest.java From rocketmq-read with Apache License 2.0 | 4 votes |
@Test public void testAppendMessageBatchSucc() throws Exception { List<Message> messages = new ArrayList<>(); String topic = "test-topic"; int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); msg.setTopic(topic); msg.setTags("abc"); messages.add(msg); } MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); ByteBuffer buff = ByteBuffer.allocate(1024 * 10); AppendMessageResult allresult = callback.doAppend(0, buff, 1024 * 10, messageExtBatch); assertEquals(AppendMessageStatus.PUT_OK, allresult.getStatus()); assertEquals(0, allresult.getWroteOffset()); assertEquals(0, allresult.getLogicsOffset()); assertEquals(buff.position(), allresult.getWroteBytes()); assertEquals(messages.size(), allresult.getMsgNum()); Set<String> msgIds = new HashSet<>(); for (String msgId : allresult.getMsgId().split(",")) { assertEquals(32, msgId.length()); msgIds.add(msgId); } assertEquals(messages.size(), msgIds.size()); List<MessageExt> decodeMsgs = MessageDecoder.decodes((ByteBuffer) buff.flip()); assertEquals(decodeMsgs.size(), decodeMsgs.size()); long queueOffset = decodeMsgs.get(0).getQueueOffset(); long storeTimeStamp = decodeMsgs.get(0).getStoreTimestamp(); for (int i = 0; i < messages.size(); i++) { assertEquals(messages.get(i).getTopic(), decodeMsgs.get(i).getTopic()); assertEquals(new String(messages.get(i).getBody()), new String(decodeMsgs.get(i).getBody())); assertEquals(messages.get(i).getTags(), decodeMsgs.get(i).getTags()); assertEquals(messageExtBatch.getBornHostNameString(), decodeMsgs.get(i).getBornHostNameString()); assertEquals(messageExtBatch.getBornTimestamp(), decodeMsgs.get(i).getBornTimestamp()); assertEquals(storeTimeStamp, decodeMsgs.get(i).getStoreTimestamp()); assertEquals(queueOffset++, decodeMsgs.get(i).getQueueOffset()); } }
Example 15
Source File: BatchSendIT.java From rocketmq-read with Apache License 2.0 | 4 votes |
@Test public void testBatchSend_CheckProperties() throws Exception { List<Message> messageList = new ArrayList<>(); Message message = new Message(); message.setTopic(topic); message.setKeys("keys123"); message.setTags("tags123"); message.setWaitStoreMsgOK(false); message.setBuyerId("buyerid123"); message.setFlag(123); message.setBody("body".getBytes()); messageList.add(message); DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); SendResult sendResult = producer.send(messageList); Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus()); String[] offsetIds = sendResult.getOffsetMsgId().split(","); String[] msgIds = sendResult.getMsgId().split(","); Assert.assertEquals(messageList.size(), offsetIds.length); Assert.assertEquals(messageList.size(), msgIds.length); Thread.sleep(2000); Message messageByOffset = producer.viewMessage(offsetIds[0]); Message messageByMsgId = producer.viewMessage(topic, msgIds[0]); System.out.println(messageByOffset); System.out.println(messageByMsgId); Assert.assertEquals(message.getTopic(), messageByMsgId.getTopic()); Assert.assertEquals(message.getTopic(), messageByOffset.getTopic()); Assert.assertEquals(message.getKeys(), messageByOffset.getKeys()); Assert.assertEquals(message.getKeys(), messageByMsgId.getKeys()); Assert.assertEquals(message.getTags(), messageByOffset.getTags()); Assert.assertEquals(message.getTags(), messageByMsgId.getTags()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByOffset.isWaitStoreMsgOK()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByMsgId.isWaitStoreMsgOK()); Assert.assertEquals(message.getBuyerId(), messageByOffset.getBuyerId()); Assert.assertEquals(message.getBuyerId(), messageByMsgId.getBuyerId()); Assert.assertEquals(message.getFlag(), messageByOffset.getFlag()); Assert.assertEquals(message.getFlag(), messageByMsgId.getFlag()); }
Example 16
Source File: BatchPutMessageTest.java From rocketmq with Apache License 2.0 | 4 votes |
@Test public void testPutMessages() throws Exception { List<Message> messages = new ArrayList<>(); String topic = "batch-write-topic"; int queue = 0; int[] msgLengthArr = new int[11]; msgLengthArr[0] = 0; int j = 1; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody(("body" + i).getBytes()); msg.setTopic(topic); msg.setTags("TAG1"); msg.setKeys(String.valueOf(System.currentTimeMillis())); messages.add(msg); String properties = messageProperties2String(msg.getProperties()); byte[] propertiesBytes = properties.getBytes(CHARSET_UTF8); short propertiesLength = (short) propertiesBytes.length; final byte[] topicData = msg.getTopic().getBytes(MessageDecoder.CHARSET_UTF8); final int topicLength = topicData.length; msgLengthArr[j] = calMsgLength(msg.getBody().length, topicLength, propertiesLength) + msgLengthArr[j - 1]; j++; } byte[] batchMessageBody = MessageDecoder.encodeMessages(messages); MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBody(batchMessageBody); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 125)); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 126)); PutMessageResult putMessageResult = messageStore.putMessages(messageExtBatch); assertThat(putMessageResult.isOk()).isTrue(); Thread.sleep(3 * 1000); for (long i = 0; i < 10; i++) { MessageExt messageExt = messageStore.lookMessageByOffset(msgLengthArr[(int) i]); assertThat(messageExt).isNotNull(); GetMessageResult result = messageStore.getMessage("batch_write_group", topic, queue, i, 1024 * 1024, null); assertThat(result).isNotNull(); assertThat(result.getStatus()).isEqualTo(GetMessageStatus.FOUND); result.release(); } }
Example 17
Source File: AppendCallbackTest.java From rocketmq-4.3.0 with Apache License 2.0 | 4 votes |
@Test public void testAppendMessageBatchSucc() throws Exception { List<Message> messages = new ArrayList<>(); String topic = "test-topic"; int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); msg.setTopic(topic); msg.setTags("abc"); messages.add(msg); } MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); ByteBuffer buff = ByteBuffer.allocate(1024 * 10); AppendMessageResult allresult = callback.doAppend(0, buff, 1024 * 10, messageExtBatch); assertEquals(AppendMessageStatus.PUT_OK, allresult.getStatus()); assertEquals(0, allresult.getWroteOffset()); assertEquals(0, allresult.getLogicsOffset()); assertEquals(buff.position(), allresult.getWroteBytes()); assertEquals(messages.size(), allresult.getMsgNum()); Set<String> msgIds = new HashSet<>(); for (String msgId : allresult.getMsgId().split(",")) { assertEquals(32, msgId.length()); msgIds.add(msgId); } assertEquals(messages.size(), msgIds.size()); List<MessageExt> decodeMsgs = MessageDecoder.decodes((ByteBuffer) buff.flip()); assertEquals(decodeMsgs.size(), decodeMsgs.size()); long queueOffset = decodeMsgs.get(0).getQueueOffset(); long storeTimeStamp = decodeMsgs.get(0).getStoreTimestamp(); for (int i = 0; i < messages.size(); i++) { assertEquals(messages.get(i).getTopic(), decodeMsgs.get(i).getTopic()); assertEquals(new String(messages.get(i).getBody()), new String(decodeMsgs.get(i).getBody())); assertEquals(messages.get(i).getTags(), decodeMsgs.get(i).getTags()); assertEquals(messageExtBatch.getBornHostNameString(), decodeMsgs.get(i).getBornHostNameString()); assertEquals(messageExtBatch.getBornTimestamp(), decodeMsgs.get(i).getBornTimestamp()); assertEquals(storeTimeStamp, decodeMsgs.get(i).getStoreTimestamp()); assertEquals(queueOffset++, decodeMsgs.get(i).getQueueOffset()); } }
Example 18
Source File: BatchSendIT.java From rocketmq-4.3.0 with Apache License 2.0 | 4 votes |
@Test public void testBatchSend_CheckProperties() throws Exception { List<Message> messageList = new ArrayList<>(); Message message = new Message(); message.setTopic(topic); message.setKeys("keys123"); message.setTags("tags123"); message.setWaitStoreMsgOK(false); message.setBuyerId("buyerid123"); message.setFlag(123); message.setBody("body".getBytes()); messageList.add(message); DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); SendResult sendResult = producer.send(messageList); Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus()); String[] offsetIds = sendResult.getOffsetMsgId().split(","); String[] msgIds = sendResult.getMsgId().split(","); Assert.assertEquals(messageList.size(), offsetIds.length); Assert.assertEquals(messageList.size(), msgIds.length); Thread.sleep(2000); Message messageByOffset = producer.viewMessage(offsetIds[0]); Message messageByMsgId = producer.viewMessage(topic, msgIds[0]); System.out.println(messageByOffset); System.out.println(messageByMsgId); Assert.assertEquals(message.getTopic(), messageByMsgId.getTopic()); Assert.assertEquals(message.getTopic(), messageByOffset.getTopic()); Assert.assertEquals(message.getKeys(), messageByOffset.getKeys()); Assert.assertEquals(message.getKeys(), messageByMsgId.getKeys()); Assert.assertEquals(message.getTags(), messageByOffset.getTags()); Assert.assertEquals(message.getTags(), messageByMsgId.getTags()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByOffset.isWaitStoreMsgOK()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByMsgId.isWaitStoreMsgOK()); Assert.assertEquals(message.getBuyerId(), messageByOffset.getBuyerId()); Assert.assertEquals(message.getBuyerId(), messageByMsgId.getBuyerId()); Assert.assertEquals(message.getFlag(), messageByOffset.getFlag()); Assert.assertEquals(message.getFlag(), messageByMsgId.getFlag()); }
Example 19
Source File: AppendCallbackTest.java From DDMQ with Apache License 2.0 | 4 votes |
@Test public void testAppendMessageBatchSucc() throws Exception { List<Message> messages = new ArrayList<>(); String topic = "test-topic"; int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); msg.setTopic(topic); msg.setTags("abc"); messages.add(msg); } MessageExtBatch messageExtBatch = new MessageExtBatch(); messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); ByteBuffer buff = ByteBuffer.allocate(1024 * 10); AppendMessageResult allresult = callback.doAppend(0, buff, 1024 * 10, messageExtBatch); assertEquals(AppendMessageStatus.PUT_OK, allresult.getStatus()); assertEquals(0, allresult.getWroteOffset()); assertEquals(0, allresult.getLogicsOffset()); assertEquals(buff.position(), allresult.getWroteBytes()); assertEquals(messages.size(), allresult.getMsgNum()); Set<String> msgIds = new HashSet<>(); for (String msgId : allresult.getMsgId().split(",")) { assertEquals(32, msgId.length()); msgIds.add(msgId); } assertEquals(messages.size(), msgIds.size()); List<MessageExt> decodeMsgs = MessageDecoder.decodes((ByteBuffer) buff.flip()); assertEquals(decodeMsgs.size(), decodeMsgs.size()); long queueOffset = decodeMsgs.get(0).getQueueOffset(); long storeTimeStamp = decodeMsgs.get(0).getStoreTimestamp(); for (int i = 0; i < messages.size(); i++) { assertEquals(messages.get(i).getTopic(), decodeMsgs.get(i).getTopic()); assertEquals(new String(messages.get(i).getBody()), new String(decodeMsgs.get(i).getBody())); assertEquals(messages.get(i).getTags(), decodeMsgs.get(i).getTags()); assertEquals(messageExtBatch.getBornHostNameString(), decodeMsgs.get(i).getBornHostNameString()); assertEquals(messageExtBatch.getBornTimestamp(), decodeMsgs.get(i).getBornTimestamp()); assertEquals(storeTimeStamp, decodeMsgs.get(i).getStoreTimestamp()); assertEquals(queueOffset++, decodeMsgs.get(i).getQueueOffset()); } }
Example 20
Source File: BatchSendIT.java From DDMQ with Apache License 2.0 | 4 votes |
@Test public void testBatchSend_CheckProperties() throws Exception { List<Message> messageList = new ArrayList<>(); Message message = new Message(); message.setTopic(topic); message.setKeys("keys123"); message.setTags("tags123"); message.setWaitStoreMsgOK(false); message.setBuyerId("buyerid123"); message.setFlag(123); message.setBody("body".getBytes()); messageList.add(message); DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); SendResult sendResult = producer.send(messageList); Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus()); String[] offsetIds = sendResult.getOffsetMsgId().split(","); String[] msgIds = sendResult.getMsgId().split(","); Assert.assertEquals(messageList.size(), offsetIds.length); Assert.assertEquals(messageList.size(), msgIds.length); Thread.sleep(2000); Message messageByOffset = producer.viewMessage(offsetIds[0]); Message messageByMsgId = producer.viewMessage(topic, msgIds[0]); System.out.println(messageByOffset); System.out.println(messageByMsgId); Assert.assertEquals(message.getTopic(), messageByMsgId.getTopic()); Assert.assertEquals(message.getTopic(), messageByOffset.getTopic()); Assert.assertEquals(message.getKeys(), messageByOffset.getKeys()); Assert.assertEquals(message.getKeys(), messageByMsgId.getKeys()); Assert.assertEquals(message.getTags(), messageByOffset.getTags()); Assert.assertEquals(message.getTags(), messageByMsgId.getTags()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByOffset.isWaitStoreMsgOK()); Assert.assertEquals(message.isWaitStoreMsgOK(), messageByMsgId.isWaitStoreMsgOK()); Assert.assertEquals(message.getBuyerId(), messageByOffset.getBuyerId()); Assert.assertEquals(message.getBuyerId(), messageByMsgId.getBuyerId()); Assert.assertEquals(message.getFlag(), messageByOffset.getFlag()); Assert.assertEquals(message.getFlag(), messageByMsgId.getFlag()); }