Search in sources :

Example 1 with MessageExtBrokerInner

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

the class AbstractSendMessageProcessor method buildInnerMsg.

protected MessageExtBrokerInner buildInnerMsg(final ChannelHandlerContext ctx, final SendMessageRequestHeader requestHeader, final byte[] body, TopicConfig topicConfig) {
    int queueIdInt = requestHeader.getQueueId();
    if (queueIdInt < 0) {
        queueIdInt = Math.abs(this.random.nextInt() % 99999999) % topicConfig.getWriteQueueNums();
    }
    int sysFlag = requestHeader.getSysFlag();
    if (TopicFilterType.MULTI_TAG == topicConfig.getTopicFilterType()) {
        sysFlag |= MessageSysFlag.MULTI_TAGS_FLAG;
    }
    MessageExtBrokerInner msgInner = new MessageExtBrokerInner();
    msgInner.setTopic(requestHeader.getTopic());
    msgInner.setBody(body);
    msgInner.setFlag(requestHeader.getFlag());
    MessageAccessor.setProperties(msgInner, MessageDecoder.string2messageProperties(requestHeader.getProperties()));
    msgInner.setPropertiesString(requestHeader.getProperties());
    msgInner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(topicConfig.getTopicFilterType(), msgInner.getTags()));
    msgInner.setQueueId(queueIdInt);
    msgInner.setSysFlag(sysFlag);
    msgInner.setBornTimestamp(requestHeader.getBornTimestamp());
    msgInner.setBornHost(ctx.channel().remoteAddress());
    msgInner.setStoreHost(this.getStoreHost());
    msgInner.setReconsumeTimes(requestHeader.getReconsumeTimes() == null ? 0 : requestHeader.getReconsumeTimes());
    return msgInner;
}
Also used : MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner)

Example 2 with MessageExtBrokerInner

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

the class PullMessageProcessor method generateOffsetMovedEvent.

private void generateOffsetMovedEvent(final OffsetMovedEvent event) {
    try {
        MessageExtBrokerInner msgInner = new MessageExtBrokerInner();
        msgInner.setTopic(MixAll.OFFSET_MOVED_EVENT);
        msgInner.setTags(event.getConsumerGroup());
        msgInner.setDelayTimeLevel(0);
        msgInner.setKeys(event.getConsumerGroup());
        msgInner.setBody(event.encode());
        msgInner.setFlag(0);
        msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgInner.getProperties()));
        msgInner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(TopicFilterType.SINGLE_TAG, msgInner.getTags()));
        msgInner.setQueueId(0);
        msgInner.setSysFlag(0);
        msgInner.setBornTimestamp(System.currentTimeMillis());
        msgInner.setBornHost(RemotingUtil.string2SocketAddress(this.brokerController.getBrokerAddr()));
        msgInner.setStoreHost(msgInner.getBornHost());
        msgInner.setReconsumeTimes(0);
        PutMessageResult putMessageResult = this.brokerController.getMessageStore().putMessage(msgInner);
    } catch (Exception e) {
        LOG.warn(String.format("GenerateOffsetMovedEvent Exception, %s", event.toString()), e);
    }
}
Also used : PutMessageResult(org.apache.rocketmq.store.PutMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException)

Example 3 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_withFilterBitMap.

@Test
public void testGetMessage_withFilterBitMap() {
    int topicCount = 10, msgPerTopic = 500;
    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);
            // sleep to wait for consume queue has been constructed.
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
            assertThat(true).isFalse();
        }
        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();
                }
            }
        }
    } finally {
        master.shutdown();
        master.destroy();
        deleteDirectory(storePath);
    }
}
Also used : GetMessageResult(org.apache.rocketmq.store.GetMessageResult) MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner) ByteBuffer(java.nio.ByteBuffer) DefaultMessageStore(org.apache.rocketmq.store.DefaultMessageStore) UnknownHostException(java.net.UnknownHostException) MessageExt(org.apache.rocketmq.common.message.MessageExt) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) Test(org.junit.Test)

Example 4 with MessageExtBrokerInner

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

the class MessageStoreWithFilterTest method buildMessage.

public MessageExtBrokerInner buildMessage() {
    MessageExtBrokerInner msg = new MessageExtBrokerInner();
    msg.setTopic(topic);
    msg.setTags("TAG1");
    msg.setKeys("Hello");
    msg.setBody(msgBody);
    msg.setKeys(String.valueOf(System.currentTimeMillis()));
    msg.setQueueId(queueId);
    msg.setSysFlag(0);
    msg.setBornTimestamp(System.currentTimeMillis());
    msg.setStoreHost(StoreHost);
    msg.setBornHost(BornHost);
    for (int i = 1; i < 3; i++) {
        msg.putUserProperty(String.valueOf(i), "imagoodperson" + i);
    }
    msg.setPropertiesString(MessageDecoder.messageProperties2String(msg.getProperties()));
    return msg;
}
Also used : MessageExtBrokerInner(org.apache.rocketmq.store.MessageExtBrokerInner)

Example 5 with MessageExtBrokerInner

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

the class AbstractSendMessageProcessor method buildInnerMsg.

protected MessageExtBrokerInner buildInnerMsg(final ChannelHandlerContext ctx, final SendMessageRequestHeader requestHeader, final byte[] body, TopicConfig topicConfig) {
    int queueIdInt = requestHeader.getQueueId();
    if (queueIdInt < 0) {
        queueIdInt = Math.abs(this.random.nextInt() % 99999999) % topicConfig.getWriteQueueNums();
    }
    int sysFlag = requestHeader.getSysFlag();
    if (TopicFilterType.MULTI_TAG == topicConfig.getTopicFilterType()) {
        sysFlag |= MessageSysFlag.MULTI_TAGS_FLAG;
    }
    MessageExtBrokerInner msgInner = new MessageExtBrokerInner();
    msgInner.setTopic(requestHeader.getTopic());
    msgInner.setBody(body);
    msgInner.setFlag(requestHeader.getFlag());
    MessageAccessor.setProperties(msgInner, MessageDecoder.string2messageProperties(requestHeader.getProperties()));
    msgInner.setPropertiesString(requestHeader.getProperties());
    msgInner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(topicConfig.getTopicFilterType(), msgInner.getTags()));
    msgInner.setQueueId(queueIdInt);
    msgInner.setSysFlag(sysFlag);
    msgInner.setBornTimestamp(requestHeader.getBornTimestamp());
    msgInner.setBornHost(ctx.channel().remoteAddress());
    msgInner.setStoreHost(this.getStoreHost());
    msgInner.setReconsumeTimes(requestHeader.getReconsumeTimes() == null ? 0 : requestHeader.getReconsumeTimes());
    return msgInner;
}
Also used : 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