Java Code Examples for org.apache.rocketmq.store.DefaultMessageStore#putMessage()
The following examples show how to use
org.apache.rocketmq.store.DefaultMessageStore#putMessage() .
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: MessageStoreWithFilterTest.java From DDMQ with Apache License 2.0 | 6 votes |
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception { List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>(); for (int i = 0; i < topicCount; i++) { String realTopic = topic + i; for (int j = 0; j < msgCountPerTopic; j++) { MessageExtBrokerInner msg = buildMessage(); msg.setTopic(realTopic); msg.putUserProperty("a", String.valueOf(j * 10 + 5)); msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties())); PutMessageResult result = master.putMessage(msg); msg.setMsgId(result.getAppendMessageResult().getMsgId()); msgs.add(msg); } } return msgs; }
Example 2
Source File: MessageStoreWithFilterTest.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception { List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>(); for (int i = 0; i < topicCount; i++) { String realTopic = topic + i; for (int j = 0; j < msgCountPerTopic; j++) { MessageExtBrokerInner msg = buildMessage(); msg.setTopic(realTopic); msg.putUserProperty("a", String.valueOf(j * 10 + 5)); msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties())); PutMessageResult result = master.putMessage(msg); msg.setMsgId(result.getAppendMessageResult().getMsgId()); msgs.add(msg); } } return msgs; }
Example 3
Source File: MessageStoreWithFilterTest.java From rocketmq-read with Apache License 2.0 | 6 votes |
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception { List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>(); for (int i = 0; i < topicCount; i++) { String realTopic = topic + i; for (int j = 0; j < msgCountPerTopic; j++) { MessageExtBrokerInner msg = buildMessage(); msg.setTopic(realTopic); msg.putUserProperty("a", String.valueOf(j * 10 + 5)); msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties())); PutMessageResult result = master.putMessage(msg); msg.setMsgId(result.getAppendMessageResult().getMsgId()); msgs.add(msg); } } return msgs; }
Example 4
Source File: MessageStoreWithFilterTest.java From DDMQ with Apache License 2.0 | 6 votes |
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception { List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>(); for (int i = 0; i < topicCount; i++) { String realTopic = topic + i; for (int j = 0; j < msgCountPerTopic; j++) { MessageExtBrokerInner msg = buildMessage(); msg.setTopic(realTopic); msg.putUserProperty("a", String.valueOf(j * 10 + 5)); msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties())); PutMessageResult result = master.putMessage(msg); msg.setMsgId(result.getAppendMessageResult().getMsgId()); msgs.add(msg); } } return msgs; }
Example 5
Source File: MessageStoreWithFilterTest.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception { List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>(); for (int i = 0; i < topicCount; i++) { String realTopic = topic + i; for (int j = 0; j < msgCountPerTopic; j++) { MessageExtBrokerInner msg = buildMessage(); msg.setTopic(realTopic); msg.putUserProperty("a", String.valueOf(j * 10 + 5)); msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties())); PutMessageResult result = master.putMessage(msg); msg.setMsgId(result.getAppendMessageResult().getMsgId()); msgs.add(msg); } } return msgs; }
Example 6
Source File: MessageStoreWithFilterTest.java From rocketmq with Apache License 2.0 | 6 votes |
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception { List<MessageExtBrokerInner> msgs = new ArrayList<MessageExtBrokerInner>(); for (int i = 0; i < topicCount; i++) { String realTopic = topic + i; for (int j = 0; j < msgCountPerTopic; j++) { MessageExtBrokerInner msg = buildMessage(); msg.setTopic(realTopic); msg.putUserProperty("a", String.valueOf(j * 10 + 5)); msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties())); PutMessageResult result = master.putMessage(msg); msg.setMsgId(result.getAppendMessageResult().getMsgId()); msgs.add(msg); } } return msgs; }
Example 7
Source File: DLedgerCommitlogTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testPutAndGetMessage() throws Exception { String base = createBaseDir(); String peers = String.format("n0-localhost:%d", nextPort()); String group = UUID.randomUUID().toString(); DefaultMessageStore messageStore = createDledgerMessageStore(base, group, "n0", peers, null, false, 0); Thread.sleep(1000); String topic = UUID.randomUUID().toString(); List<PutMessageResult> results = new ArrayList<>(); for (int i = 0; i < 10; i++) { MessageExtBrokerInner msgInner = i < 5 ? buildMessage() : buildIPv6HostMessage(); msgInner.setTopic(topic); msgInner.setQueueId(0); PutMessageResult putMessageResult = messageStore.putMessage(msgInner); results.add(putMessageResult); Assert.assertEquals(PutMessageStatus.PUT_OK, putMessageResult.getPutMessageStatus()); Assert.assertEquals(i, putMessageResult.getAppendMessageResult().getLogicsOffset()); } Thread.sleep(100); Assert.assertEquals(0, messageStore.getMinOffsetInQueue(topic, 0)); Assert.assertEquals(10, messageStore.getMaxOffsetInQueue(topic, 0)); Assert.assertEquals(0, messageStore.dispatchBehindBytes()); GetMessageResult getMessageResult = messageStore.getMessage("group", topic, 0, 0, 32, null); Assert.assertEquals(GetMessageStatus.FOUND, getMessageResult.getStatus()); Assert.assertEquals(10, getMessageResult.getMessageBufferList().size()); Assert.assertEquals(10, getMessageResult.getMessageMapedList().size()); for (int i = 0; i < results.size(); i++) { ByteBuffer buffer = getMessageResult.getMessageBufferList().get(i); MessageExt messageExt = MessageDecoder.decode(buffer); Assert.assertEquals(i, messageExt.getQueueOffset()); Assert.assertEquals(results.get(i).getAppendMessageResult().getMsgId(), messageExt.getMsgId()); Assert.assertEquals(results.get(i).getAppendMessageResult().getWroteOffset(), messageExt.getCommitLogOffset()); } messageStore.destroy(); messageStore.shutdown(); }
Example 8
Source File: DLedgerCommitlogTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testCommittedPos() throws Exception { String peers = String.format("n0-localhost:%d;n1-localhost:%d", nextPort(), nextPort()); String group = UUID.randomUUID().toString(); DefaultMessageStore leaderStore = createDledgerMessageStore(createBaseDir(), group,"n0", peers, "n0", false, 0); String topic = UUID.randomUUID().toString(); MessageExtBrokerInner msgInner = buildMessage(); msgInner.setTopic(topic); msgInner.setQueueId(0); PutMessageResult putMessageResult = leaderStore.putMessage(msgInner); Assert.assertEquals(PutMessageStatus.OS_PAGECACHE_BUSY, putMessageResult.getPutMessageStatus()); Thread.sleep(1000); Assert.assertEquals(0, leaderStore.getCommitLog().getMaxOffset()); Assert.assertEquals(0, leaderStore.getMaxOffsetInQueue(topic, 0)); DefaultMessageStore followerStore = createDledgerMessageStore(createBaseDir(), group,"n1", peers, "n0", false, 0); Thread.sleep(2000); Assert.assertEquals(1, leaderStore.getMaxOffsetInQueue(topic, 0)); Assert.assertEquals(1, followerStore.getMaxOffsetInQueue(topic, 0)); Assert.assertTrue(leaderStore.getCommitLog().getMaxOffset() > 0); leaderStore.destroy(); followerStore.destroy(); leaderStore.shutdown(); followerStore.shutdown(); }
Example 9
Source File: DLedgerCommitlogTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testIPv6HostMsgCommittedPos() throws Exception { String peers = String.format("n0-localhost:%d;n1-localhost:%d", nextPort(), nextPort()); String group = UUID.randomUUID().toString(); DefaultMessageStore leaderStore = createDledgerMessageStore(createBaseDir(), group,"n0", peers, "n0", false, 0); String topic = UUID.randomUUID().toString(); MessageExtBrokerInner msgInner = buildIPv6HostMessage(); msgInner.setTopic(topic); msgInner.setQueueId(0); PutMessageResult putMessageResult = leaderStore.putMessage(msgInner); Assert.assertEquals(PutMessageStatus.OS_PAGECACHE_BUSY, putMessageResult.getPutMessageStatus()); Thread.sleep(1000); Assert.assertEquals(0, leaderStore.getCommitLog().getMaxOffset()); Assert.assertEquals(0, leaderStore.getMaxOffsetInQueue(topic, 0)); DefaultMessageStore followerStore = createDledgerMessageStore(createBaseDir(), group,"n1", peers, "n0", false, 0); Thread.sleep(2000); Assert.assertEquals(1, leaderStore.getMaxOffsetInQueue(topic, 0)); Assert.assertEquals(1, followerStore.getMaxOffsetInQueue(topic, 0)); Assert.assertTrue(leaderStore.getCommitLog().getMaxOffset() > 0); leaderStore.destroy(); followerStore.destroy(); leaderStore.shutdown(); followerStore.shutdown(); }