public StringBuilder getMessageSnapshot(String topicName, int partitionId,
            int msgCount, final Set<String> filterCondSet,
            final StringBuilder sb) throws Exception {
        MessageStore dataStore = null;
        final long startTime = System.currentTimeMillis();
        if (!this.started.get()
                || ServiceStatusHolder.isReadServiceStop()) {
            sb.append("{\"result\":false,\"errCode\":")
                    .append(TErrCodeConstants.SERVICE_UNAVAILABLE)
                    .append(",\"errMsg\":\"Read StoreService temporary unavailable!\"}");
            return sb;
        }
        try {
            if (partitionId == -1) {
                final Collection<MessageStore> msgStores =
                        storeManager.getMessageStoresByTopic(topicName);
                if ((msgStores == null) || (msgStores.isEmpty())) {
                    sb.append("{\"result\":false,\"errCode\":400,\"errMsg\":\"")
                            .append("Invalid parameter: not found the store by topicName(")
                            .append(topicName).append(")!\"}");
                    return sb;
                }
                for (final MessageStore msgStore : msgStores) {
                    dataStore = msgStore;
                    if (dataStore != null) {
                        partitionId = msgStore.getStoreId() * TBaseConstants.META_STORE_INS_BASE;
                        break;
                    }
                }
                if (dataStore == null) {
                    sb.append("{\"result\":false,\"errCode\":400,\"errMsg\":\"")
                            .append("Invalid parameter: all store is null by topicName(")
                            .append(topicName).append(")!\"}");
                    return sb;
                }
            } else {
                dataStore = storeManager.getOrCreateMessageStore(topicName, partitionId);
                if (dataStore == null) {
                    sb.append("{\"result\":false,\"errCode\":400,\"errMsg\":\"")
                            .append("Invalid parameter: not found the store by topicName + partitionId(")
                            .append(topicName).append(":").append(partitionId).append(")!\"}");
                    return sb;
                }
            }
            GetMessageResult getMessageResult =
                    storeManager.getMessages(dataStore, topicName, partitionId, msgCount, filterCondSet);
            BrokerSrvStatsHolder.updGetMsgLatency(System.currentTimeMillis() - startTime);
            if ((getMessageResult.transferedMessageList == null)
                    || (getMessageResult.transferedMessageList.isEmpty())) {
                sb.append("{\"result\":false,\"errCode\":401,\"errMsg\":\"")
                        .append("Could not find message at position by topic (")
                        .append(topicName).append(")!\"}");
                return sb;
            } else {
                List<TransferedMessage> tmpMsgList = getMessageResult.transferedMessageList;
                List<Message> messageList = DataConverterUtil.convertMessage(topicName, tmpMsgList);
                int i = 0;
                int startPos = Math.max(messageList.size() - msgCount, 0);
                sb.append("{\"result\":true,\"errCode\":0,\"errMsg\":\"Success!\",\"dataSet\":[");
                for (; startPos < messageList.size(); startPos++) {
                    if (i > 0) {
                        sb.append(",");
                    }
                    sb.append("{\"index\":").append(i++).append(",\"data\":\"")
                            .append(new String(Base64.encodeBase64(messageList.get(startPos).getData())))
                            .append("\",\"attr\":\"").append(messageList.get(startPos).getAttribute())
                            .append("\"}");
                }
                sb.append("]}");
                return sb;
            }
        } catch (Throwable ee) {
            sb.append("{\"result\":false,\"errCode\":501,\"errMsg\":\"Get Message failure, exception is ")
                    .append(ee.getMessage()).append("\"}");
            return sb;
        }
    }
Get message snapshot by given parameters.

@param topicName        the topic name
@param partitionId      the partition id
@param msgCount         the message count need to query
@param filterCondSet    the filter condition set
@param sb               the string buffer
@return                 the messages returned
@throws Exception       the exception during processing
inlong-tubemq/tubemq-server/src/main/java/org/apache/inlong/tubemq/server/broker/BrokerServiceServer.java