Search in sources :

Example 16 with MessageExtBrokerInner

use of org.apache.rocketmq.store.MessageExtBrokerInner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MessageStoreWithFilterTest method testGetMessage_withFilterBitMapAndConsumerChanged.

@Test
public void testGetMessage_withFilterBitMapAndConsumerChanged() {
    int topicCount = 10, msgPerTopic = 10;
    ConsumerFilterManager filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic);
    DefaultMessageStore master = null;
    try {
        master = gen(filterManager);
    } catch (Exception e) {
        e.printStackTrace();
        assertThat(true).isFalse();
    }
    try {
        List<MessageExtBrokerInner> msgs = null;
        try {
            msgs = putMsg(master, topicCount, msgPerTopic);
        } catch (Exception e) {
            e.printStackTrace();
            assertThat(true).isFalse();
        }
        // sleep to wait for consume queue has been constructed.
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
            assertThat(true).isFalse();
        }
        // reset consumer;
        String topic = "topic" + 0;
        String resetGroup = "CID_" + 2;
        String normalGroup = "CID_" + 3;
        {
            // reset CID_2@topic0 to get all messages.
            SubscriptionData resetSubData = new SubscriptionData();
            resetSubData.setExpressionType(ExpressionType.SQL92);
            resetSubData.setTopic(topic);
            resetSubData.setClassFilterMode(false);
            resetSubData.setSubString("a is not null OR a is null");
            ConsumerFilterData resetFilterData = ConsumerFilterManager.build(topic, resetGroup, resetSubData.getSubString(), resetSubData.getExpressionType(), System.currentTimeMillis());
            GetMessageResult resetGetResult = master.getMessage(resetGroup, topic, queueId, 0, 1000, new ExpressionMessageFilter(resetSubData, resetFilterData, filterManager));
            try {
                assertThat(resetGetResult).isNotNull();
                List<MessageExtBrokerInner> filteredMsgs = filtered(msgs, resetFilterData);
                assertThat(resetGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size());
            } finally {
                resetGetResult.release();
            }
        }
        {
            ConsumerFilterData normalFilterData = filterManager.get(topic, normalGroup);
            assertThat(normalFilterData).isNotNull();
            assertThat(normalFilterData.getBornTime()).isLessThan(System.currentTimeMillis());
            SubscriptionData normalSubData = new SubscriptionData();
            normalSubData.setExpressionType(normalFilterData.getExpressionType());
            normalSubData.setTopic(topic);
            normalSubData.setClassFilterMode(false);
            normalSubData.setSubString(normalFilterData.getExpression());
            List<MessageExtBrokerInner> filteredMsgs = filtered(msgs, normalFilterData);
            GetMessageResult normalGetResult = master.getMessage(normalGroup, topic, queueId, 0, 1000, new ExpressionMessageFilter(normalSubData, normalFilterData, filterManager));
            try {
                assertThat(normalGetResult).isNotNull();
                assertThat(normalGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size());
            } finally {
                normalGetResult.release();
            }
        }
    } finally {
        master.shutdown();
        master.destroy();
        deleteDirectory(storePath);
    }
}
Also used : GetMessageResult(org.apache.rocketmq.store.GetMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) DefaultMessageStore(org.apache.rocketmq.store.DefaultMessageStore) UnknownHostException(java.net.UnknownHostException) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 17 with MessageExtBrokerInner

use of org.apache.rocketmq.store.MessageExtBrokerInner in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MessageStoreWithFilterTest method putMsg.

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;
}
Also used : PutMessageResult(org.apache.rocketmq.store.PutMessageResult) ArrayList(java.util.ArrayList) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner)

Example 18 with MessageExtBrokerInner

use of org.apache.rocketmq.store.MessageExtBrokerInner in project rocketmq by apache.

the class EndTransactionProcessor method endMessageTransaction.

private MessageExtBrokerInner endMessageTransaction(MessageExt msgExt) {
    MessageExtBrokerInner msgInner = new MessageExtBrokerInner();
    msgInner.setBody(msgExt.getBody());
    msgInner.setFlag(msgExt.getFlag());
    MessageAccessor.setProperties(msgInner, msgExt.getProperties());
    TopicFilterType topicFilterType = (msgInner.getSysFlag() & MessageSysFlag.MULTI_TAGS_FLAG) == MessageSysFlag.MULTI_TAGS_FLAG ? TopicFilterType.MULTI_TAG : TopicFilterType.SINGLE_TAG;
    long tagsCodeValue = MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags());
    msgInner.setTagsCode(tagsCodeValue);
    msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgExt.getProperties()));
    msgInner.setSysFlag(msgExt.getSysFlag());
    msgInner.setBornTimestamp(msgExt.getBornTimestamp());
    msgInner.setBornHost(msgExt.getBornHost());
    msgInner.setStoreHost(msgExt.getStoreHost());
    msgInner.setReconsumeTimes(msgExt.getReconsumeTimes());
    msgInner.setWaitStoreMsgOK(false);
    MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_DELAY_TIME_LEVEL);
    msgInner.setTopic(msgExt.getTopic());
    msgInner.setQueueId(msgExt.getQueueId());
    return msgInner;
}
Also used : MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) TopicFilterType(org.apache.rocketmq.common.TopicFilterType)

Example 19 with MessageExtBrokerInner

use of org.apache.rocketmq.store.MessageExtBrokerInner in project rocketmq by apache.

the class MessageStoreWithFilterTest method testGetMessage_withFilterBitMap.

@Test
public void testGetMessage_withFilterBitMap() throws Exception {
    List<MessageExtBrokerInner> msgs = putMsg(master, topicCount, msgPerTopic);
    Thread.sleep(100);
    for (int i = 0; i < topicCount; i++) {
        String realTopic = topic + i;
        for (int j = 0; j < msgPerTopic; j++) {
            String group = "CID_" + j;
            ConsumerFilterData filterData = filterManager.get(realTopic, group);
            assertThat(filterData).isNotNull();
            List<MessageExtBrokerInner> filteredMsgs = filtered(msgs, filterData);
            SubscriptionData subscriptionData = new SubscriptionData();
            subscriptionData.setExpressionType(filterData.getExpressionType());
            subscriptionData.setTopic(filterData.getTopic());
            subscriptionData.setClassFilterMode(false);
            subscriptionData.setSubString(filterData.getExpression());
            GetMessageResult getMessageResult = master.getMessage(group, realTopic, queueId, 0, 10000, new ExpressionMessageFilter(subscriptionData, filterData, filterManager));
            String assertMsg = group + "-" + realTopic;
            try {
                assertThat(getMessageResult).isNotNull();
                assertThat(GetMessageStatus.FOUND).isEqualTo(getMessageResult.getStatus());
                assertThat(getMessageResult.getMessageBufferList()).isNotNull().isNotEmpty();
                assertThat(getMessageResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size());
                for (ByteBuffer buffer : getMessageResult.getMessageBufferList()) {
                    MessageExt messageExt = MessageDecoder.decode(buffer.slice(), false);
                    assertThat(messageExt).isNotNull();
                    Object evlRet = null;
                    try {
                        evlRet = filterData.getCompiledExpression().evaluate(new MessageEvaluationContext(messageExt.getProperties()));
                    } catch (Exception e) {
                        e.printStackTrace();
                        assertThat(true).isFalse();
                    }
                    assertThat(evlRet).isNotNull().isEqualTo(Boolean.TRUE);
                    // check
                    boolean find = false;
                    for (MessageExtBrokerInner messageExtBrokerInner : filteredMsgs) {
                        if (messageExtBrokerInner.getMsgId().equals(messageExt.getMsgId())) {
                            find = true;
                        }
                    }
                    assertThat(find).isTrue();
                }
            } finally {
                getMessageResult.release();
            }
        }
    }
}
Also used : GetMessageResult(org.apache.rocketmq.store.GetMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) ByteBuffer(java.nio.ByteBuffer) UnknownHostException(java.net.UnknownHostException) MessageExt(org.apache.rocketmq.common.message.MessageExt) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) Test(org.junit.Test)

Example 20 with MessageExtBrokerInner

use of org.apache.rocketmq.store.MessageExtBrokerInner in project rocketmq by apache.

the class MessageStoreWithFilterTest method putMsg.

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;
}
Also used : PutMessageResult(org.apache.rocketmq.store.PutMessageResult) ArrayList(java.util.ArrayList) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner)

Aggregations

MessageExtBrokerInner (org.apache.rocketmq.store.MessageExtBrokerInner)20 PutMessageResult (org.apache.rocketmq.store.PutMessageResult)10 MessageExt (org.apache.rocketmq.common.message.MessageExt)6 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)6 ArrayList (java.util.ArrayList)4 TopicConfig (org.apache.rocketmq.common.TopicConfig)4 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)4 GetMessageResult (org.apache.rocketmq.store.GetMessageResult)4 Test (org.junit.Test)4 UnknownHostException (java.net.UnknownHostException)3 ByteBuffer (java.nio.ByteBuffer)2 List (java.util.List)2 ConsumeMessageContext (org.apache.rocketmq.broker.mqtrace.ConsumeMessageContext)2 TopicFilterType (org.apache.rocketmq.common.TopicFilterType)2 ConsumerSendMsgBackRequestHeader (org.apache.rocketmq.common.protocol.header.ConsumerSendMsgBackRequestHeader)2 EndTransactionRequestHeader (org.apache.rocketmq.common.protocol.header.EndTransactionRequestHeader)2 SendMessageResponseHeader (org.apache.rocketmq.common.protocol.header.SendMessageResponseHeader)2 SubscriptionGroupConfig (org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)2 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)2 DefaultMessageStore (org.apache.rocketmq.store.DefaultMessageStore)2