diff --git a/NOTICE b/NOTICE
index fea5b4cc9cc..638868a5005 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,5 +1,5 @@
-RocketMQ
-Copyright 2016 Alibaba Group.
+Apache RocketMQ (incubating)
+Copyright 2016 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file
diff --git a/bin/mqbroker b/bin/mqbroker
index b72310f9efd..6a79c392e8d 100644
--- a/bin/mqbroker
+++ b/bin/mqbroker
@@ -42,6 +42,4 @@ fi
export ROCKETMQ_HOME
-rm -f $HOME/rmq_bk_gc.log.bac
-cp $HOME/rmq_bk_gc.log $HOME/rmq_bk_gc.log.bac
sh ${ROCKETMQ_HOME}/bin/runbroker.sh org.apache.rocketmq.broker.BrokerStartup $@
diff --git a/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java b/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java
index 9b89c85c143..af69001c3de 100644
--- a/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java
+++ b/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java
@@ -463,7 +463,7 @@ public long headSlowTimeMills(BlockingQueue
+ * Thread Safety: After initialization, the instance can be regarded as thread-safe. + *
*/ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsumer { + + /** + * Internal implementation. Most of the functions herein are delegated to it. + */ protected final transient DefaultMQPushConsumerImpl defaultMQPushConsumerImpl; + /** - * Do the same thing for the same Group, the application must be set,and - * guarantee Globally unique + * Consumers of the same role is required to have exactly same subscriptions and consumerGroup to correctly achieve + * load balance. It's required and needs to be globally unique. + * + * + * See here for further discussion. */ private String consumerGroup; + /** - * Consumption pattern,default is clustering + * Message model defines the way how messages are delivered to each consumer clients. + * + * + * RocketMQ supports two message models: clustering and broadcasting. If clustering is set, consumer clients with + * the same {@link #consumerGroup} would only consume shards of the messages subscribed, which achieves load + * balances; Conversely, if the broadcasting is set, each consumer client will consume all subscribed messages + * separately. + * + * + * This field defaults to clustering. */ private MessageModel messageModel = MessageModel.CLUSTERING; + /** - * Consumption offset + * Consuming point on consumer booting. + * + * + * There are three consuming points: + *CONSUME_FROM_LAST_OFFSET: consumer clients pick up where it stopped previously.
+ * If it were a newly booting up consumer client, according aging of the consumer group, there are two
+ * cases:
+ * CONSUME_FROM_FIRST_OFFSET: Consumer client will start from earliest messages available.
+ * CONSUME_FROM_TIMESTAMP: Consumer client will start from specified timestamp, which means
+ * messages born prior to {@link #consumeTimestamp} will be ignored
+ * brokerName and the message will be re-delivered in
+ * future.
+ *
+ * @param msg Message to send back.
+ * @param delayLevel delay level.
+ * @param brokerName broker name.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws MQBrokerException if there is any broker error.
+ * @throws InterruptedException if the thread is interrupted.
+ * @throws MQClientException if there is any client error.
+ */
@Override
public void sendMessageBack(MessageExt msg, int delayLevel, String brokerName)
throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
@@ -325,11 +447,18 @@ public Setsend methods to deliver messages to brokers. Each of them has pros and
+ * cons; you'd better understand strengths and weakness of them before actually coding.
+ *
+ *
+ * + * Thread Safety: After configuring and starting process, this class can be regarded as thread-safe + * and used among multiple threads context. + *
+ */ public class DefaultMQProducer extends ClientConfig implements MQProducer { + + /** + * Wrapping internal implementations for virtually all methods presented in this class. + */ protected final transient DefaultMQProducerImpl defaultMQProducerImpl; + + /** + * Producer group conceptually aggregates all producer instances of exactly same role, which is particularly + * important when transactional messages are involved. + * + * + * For non-transactional messages, it does not matter as long as it's unique per process. + * + * + * See {@linktourl http://rocketmq.incubator.apache.org/docs/core-concept/} for more discussion. + */ private String producerGroup; + /** * Just for testing or demo program */ private String createTopicKey = MixAll.DEFAULT_TOPIC; + + /** + * Number of queues to create per default topic. + */ private volatile int defaultTopicQueueNums = 4; + + /** + * Timeout for sending messages. + */ private int sendMsgTimeout = 3000; + + /** + * Compress message body threshold, namely, message body larger than 4k will be compressed on default. + */ private int compressMsgBodyOverHowmuch = 1024 * 4; + + /** + * Maximum number of retry to perform internally before claiming sending failure in synchronous mode. + * + * + * This may potentially cause message duplication which is up to application developers to resolve. + */ private int retryTimesWhenSendFailed = 2; + + /** + * Maximum number of retry to perform internally before claiming sending failure in asynchronous mode. + * + * + * This may potentially cause message duplication which is up to application developers to resolve. + */ private int retryTimesWhenSendAsyncFailed = 2; + /** + * Indicate whether to retry another broker on sending failure internally. + */ private boolean retryAnotherBrokerWhenNotStoreOK = false; + + /** + * Maximum allowed message size in bytes. + */ private int maxMessageSize = 1024 * 1024 * 4; // 4M + /** + * Default constructor. + */ public DefaultMQProducer() { this(MixAll.DEFAULT_PRODUCER_GROUP, null); } + /** + * Constructor specifying both producer group and RPC hook. + * + * @param producerGroup Producer group, see the name-sake field. + * @param rpcHook RPC hook to execute per each remoting command execution. + */ public DefaultMQProducer(final String producerGroup, RPCHook rpcHook) { this.producerGroup = producerGroup; defaultMQProducerImpl = new DefaultMQProducerImpl(this, rpcHook); } + /** + * Constructor specifying producer group. + * @param producerGroup Producer group, see the name-sake field. + */ public DefaultMQProducer(final String producerGroup) { this(producerGroup, null); } + /** + * Constructor specifying the RPC hook. + * @param rpcHook RPC hook to execute per each remoting command execution. + */ public DefaultMQProducer(RPCHook rpcHook) { this(MixAll.DEFAULT_PRODUCER_GROUP, rpcHook); } + /** + * Start this producer instance. + * + * + * + * Much internal initializing procedures are carried out to make this instance prepared, thus, it's a must to invoke + * this method before sending or querying messages. + * + * + * + * @throws MQClientException if there is any unexpected error. + */ @Override public void start() throws MQClientException { this.defaultMQProducerImpl.start(); } + /** + * This method shuts down this producer instance and releases related resources. + */ @Override public void shutdown() { this.defaultMQProducerImpl.shutdown(); } + /** + * Fetch message queues of topictopic, to which we may send/publish messages.
+ * @param topic Topic to fetch.
+ * @return List of message queues readily to send messages to
+ * @throws MQClientException if there is any client error.
+ */
@Override
public ListsendCallback will be executed.
+ *
+ *
+ * Similar to {@link #send(Message)}, internal implementation would potentially retry up to
+ * {@link #retryTimesWhenSendAsyncFailed} times before claiming sending failure, which may yield message duplication
+ * and application developers are the one to resolve this potential issue.
+ * @param msg Message to send.
+ * @param sendCallback Callback to execute on sending completed, either successful or unsuccessful.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public void send(Message msg, SendCallback sendCallback) throws MQClientException, RemotingException, InterruptedException {
this.defaultMQProducerImpl.send(msg, sendCallback);
}
+ /**
+ * Same to {@link #send(Message, SendCallback)} with send timeout specified in addition.
+ * @param msg message to send.
+ * @param sendCallback Callback to execute.
+ * @param timeout send timeout.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public void send(Message msg, SendCallback sendCallback, long timeout)
throws MQClientException, RemotingException, InterruptedException {
this.defaultMQProducerImpl.send(msg, sendCallback, timeout);
}
+ /**
+ * Similar to UDP, this method won't wait for
+ * acknowledgement from broker before return. Obviously, it has maximums throughput yet potentials of message loss.
+ * @param msg Message to send.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public void sendOneway(Message msg) throws MQClientException, RemotingException, InterruptedException {
this.defaultMQProducerImpl.sendOneway(msg);
}
+ /**
+ * Same to {@link #send(Message)} with target message queue specified in addition.
+ * @param msg Message to send.
+ * @param mq Target message queue.
+ * @return {@link SendResult} instance to inform senders details of the deliverable, say Message ID of the message,
+ * {@link SendStatus} indicating broker storage/replication status, message queue sent to, etc.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws MQBrokerException if there is any error with broker.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public SendResult send(Message msg, MessageQueue mq)
throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
return this.defaultMQProducerImpl.send(msg, mq);
}
+ /**
+ * Same to {@link #send(Message)} with target message queue and send timeout specified.
+ *
+ * @param msg Message to send.
+ * @param mq Target message queue.
+ * @param timeout send timeout.
+ * @return {@link SendResult} instance to inform senders details of the deliverable, say Message ID of the message,
+ * {@link SendStatus} indicating broker storage/replication status, message queue sent to, etc.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws MQBrokerException if there is any error with broker.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public SendResult send(Message msg, MessageQueue mq, long timeout)
throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
return this.defaultMQProducerImpl.send(msg, mq, timeout);
}
+ /**
+ * Same to {@link #send(Message, SendCallback)} with target message queue specified.
+ *
+ * @param msg Message to send.
+ * @param mq Target message queue.
+ * @param sendCallback Callback to execute on sending completed, either successful or unsuccessful.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public void send(Message msg, MessageQueue mq, SendCallback sendCallback)
throws MQClientException, RemotingException, InterruptedException {
this.defaultMQProducerImpl.send(msg, mq, sendCallback);
}
+ /**
+ * Same to {@link #send(Message, SendCallback)} with target message queue and send timeout specified.
+ * @param msg Message to send.
+ * @param mq Target message queue.
+ * @param sendCallback Callback to execute on sending completed, either successful or unsuccessful.
+ * @param timeout Send timeout.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public void send(Message msg, MessageQueue mq, SendCallback sendCallback, long timeout)
throws MQClientException, RemotingException, InterruptedException {
this.defaultMQProducerImpl.send(msg, mq, sendCallback, timeout);
}
+ /**
+ * Same to {@link #sendOneway(Message)} with target message queue specified.
+ * @param msg Message to send.
+ * @param mq Target message queue.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public void sendOneway(Message msg, MessageQueue mq) throws MQClientException, RemotingException, InterruptedException {
this.defaultMQProducerImpl.sendOneway(msg, mq);
}
+ /**
+ * Same to {@link #send(Message)} with message queue selector specified.
+ *
+ * @param msg Message to send.
+ * @param selector Message queue selector, through which we get target message queue to deliver message to.
+ * @param arg Argument to work along with message queue selector.
+ * @return {@link SendResult} instance to inform senders details of the deliverable, say Message ID of the message,
+ * {@link SendStatus} indicating broker storage/replication status, message queue sent to, etc.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws MQBrokerException if there is any error with broker.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public SendResult send(Message msg, MessageQueueSelector selector, Object arg)
throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
return this.defaultMQProducerImpl.send(msg, selector, arg);
}
+ /**
+ * Same to {@link #send(Message, MessageQueueSelector, Object)} with send timeout specified.
+ *
+ * @param msg Message to send.
+ * @param selector Message queue selector, through which we get target message queue to deliver message to.
+ * @param arg Argument to work along with message queue selector.
+ * @param timeout Send timeout.
+ * @return {@link SendResult} instance to inform senders details of the deliverable, say Message ID of the message,
+ * {@link SendStatus} indicating broker storage/replication status, message queue sent to, etc.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws MQBrokerException if there is any error with broker.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public SendResult send(Message msg, MessageQueueSelector selector, Object arg, long timeout)
throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
return this.defaultMQProducerImpl.send(msg, selector, arg, timeout);
}
+ /**
+ * Same to {@link #send(Message, SendCallback)} with message queue selector specified.
+ *
+ * @param msg Message to send.
+ * @param selector Message selector through which to get target message queue.
+ * @param arg Argument used along with message queue selector.
+ * @param sendCallback callback to execute on sending completion.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public void send(Message msg, MessageQueueSelector selector, Object arg, SendCallback sendCallback)
throws MQClientException, RemotingException, InterruptedException {
this.defaultMQProducerImpl.send(msg, selector, arg, sendCallback);
}
+ /**
+ * Same to {@link #send(Message, MessageQueueSelector, Object, SendCallback)} with timeout specified.
+ *
+ * @param msg Message to send.
+ * @param selector Message selector through which to get target message queue.
+ * @param arg Argument used along with message queue selector.
+ * @param sendCallback callback to execute on sending completion.
+ * @param timeout Send timeout.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public void send(Message msg, MessageQueueSelector selector, Object arg, SendCallback sendCallback, long timeout)
throws MQClientException, RemotingException, InterruptedException {
this.defaultMQProducerImpl.send(msg, selector, arg, sendCallback, timeout);
}
+ /**
+ * Same to {@link #sendOneway(Message)} with message queue selector specified.
+ * @param msg Message to send.
+ * @param selector Message queue selector, through which to determine target message queue to deliver message
+ * @param arg Argument used along with message queue selector.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public void sendOneway(Message msg, MessageQueueSelector selector, Object arg)
throws MQClientException, RemotingException, InterruptedException {
this.defaultMQProducerImpl.sendOneway(msg, selector, arg);
}
+ /**
+ * This method is to send transactional messages.
+ *
+ * @param msg Transactional message to send.
+ * @param tranExecuter local transaction executor.
+ * @param arg Argument used along with local transaction executor.
+ * @return Transaction result.
+ * @throws MQClientException if there is any client error.
+ */
@Override
public TransactionSendResult sendMessageInTransaction(Message msg, LocalTransactionExecuter tranExecuter, final Object arg)
throws MQClientException {
throw new RuntimeException("sendMessageInTransaction not implement, please use TransactionMQProducer class");
}
+ /**
+ * Create a topic on broker.
+ * @param key accesskey
+ * @param newTopic topic name
+ * @param queueNum topic's queue number
+ * @throws MQClientException if there is any client error.
+ */
@Override
public void createTopic(String key, String newTopic, int queueNum) throws MQClientException {
createTopic(key, newTopic, queueNum, 0);
}
+ /**
+ * Create a topic on broker.
+ * @param key accesskey
+ * @param newTopic topic name
+ * @param queueNum topic's queue number
+ * @param topicSysFlag topic system flag
+ * @throws MQClientException if there is any client error.
+ */
@Override
public void createTopic(String key, String newTopic, int queueNum, int topicSysFlag) throws MQClientException {
this.defaultMQProducerImpl.createTopic(key, newTopic, queueNum, topicSysFlag);
}
+ /**
+ * Search consume queue offset of the given time stamp.
+ * @param mq Instance of MessageQueue
+ * @param timestamp from when in milliseconds.
+ * @return Consume queue offset.
+ * @throws MQClientException if there is any client error.
+ */
@Override
public long searchOffset(MessageQueue mq, long timestamp) throws MQClientException {
return this.defaultMQProducerImpl.searchOffset(mq, timestamp);
}
+ /**
+ * Query maximum offset of the given message queue.
+ *
+ * @param mq Instance of MessageQueue
+ * @return maximum offset of the given consume queue.
+ * @throws MQClientException if there is any client error.
+ */
@Override
public long maxOffset(MessageQueue mq) throws MQClientException {
return this.defaultMQProducerImpl.maxOffset(mq);
}
+ /**
+ * Query minimum offset of the given message queue.
+ * @param mq Instance of MessageQueue
+ * @return minimum offset of the given message queue.
+ * @throws MQClientException if there is any client error.
+ */
@Override
public long minOffset(MessageQueue mq) throws MQClientException {
return this.defaultMQProducerImpl.minOffset(mq);
}
+ /**
+ * Query earliest message store time.
+ * @param mq Instance of MessageQueue
+ * @return earliest message store time.
+ * @throws MQClientException if there is any client error.
+ */
@Override
public long earliestMsgStoreTime(MessageQueue mq) throws MQClientException {
return this.defaultMQProducerImpl.earliestMsgStoreTime(mq);
}
+ /**
+ * Query message of the given offset message ID.
+ * @param offsetMsgId message id
+ * @return Message specified.
+ * @throws MQBrokerException if there is any broker error.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public MessageExt viewMessage(String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
return this.defaultMQProducerImpl.viewMessage(offsetMsgId);
}
+ /**
+ * Query message by key.
+ * @param topic message topic
+ * @param key message key index word
+ * @param maxNum max message number
+ * @param begin from when
+ * @param end to when
+ * @return QueryResult instance contains matched messages.
+ * @throws MQClientException if there is any client error.
+ * @throws InterruptedException if the thread is interrupted.
+ */
@Override
public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end)
throws MQClientException, InterruptedException {
return this.defaultMQProducerImpl.queryMessage(topic, key, maxNum, begin, end);
}
+ /**
+ * Query message of the given message ID.
+ *
+ * @param topic Topic
+ * @param msgId Message ID
+ * @return Message specified.
+ * @throws MQBrokerException if there is any broker error.
+ * @throws MQClientException if there is any client error.
+ * @throws RemotingException if there is any network-tier error.
+ * @throws InterruptedException if the sending thread is interrupted.
+ */
@Override
public MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
try {
diff --git a/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java b/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java
index 6ddb9e11d03..f79f7267c8c 100644
--- a/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java
+++ b/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java
@@ -91,7 +91,7 @@ public class BrokerConfig {
private boolean slaveReadEnable = false;
private boolean disableConsumeIfConsumerReadSlowly = false;
- private long consumerFallbehindThreshold = 1024 * 1024 * 1024 * 16;
+ private long consumerFallbehindThreshold = 1024L * 1024 * 1024 * 16;
private long waitTimeMillsInSendQueue = 200;
diff --git a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
index 56015b36d56..016da0b44c5 100644
--- a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
+++ b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
@@ -183,17 +183,16 @@ public static double getDiskPartitionSpaceUsedPercent(final String path) {
try {
File file = new File(path);
- if (!file.exists()) {
- boolean result = file.mkdirs();
- if (!result) {
- //TO DO
- }
- }
+
+ if (!file.exists())
+ return -1;
long totalSpace = file.getTotalSpace();
- long freeSpace = file.getFreeSpace();
- long usedSpace = totalSpace - freeSpace;
+
if (totalSpace > 0) {
+ long freeSpace = file.getFreeSpace();
+ long usedSpace = totalSpace - freeSpace;
+
return usedSpace / (double) totalSpace;
}
} catch (Exception e) {
diff --git a/common/src/test/java/org/apache/rocketmq/common/BrokerConfigTest.java b/common/src/test/java/org/apache/rocketmq/common/BrokerConfigTest.java
new file mode 100644
index 00000000000..c8cdaaf609e
--- /dev/null
+++ b/common/src/test/java/org/apache/rocketmq/common/BrokerConfigTest.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.common;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BrokerConfigTest {
+
+ @Test
+ public void testConsumerFallBehindThresholdOverflow() {
+ long expect = 1024L * 1024 * 1024 * 16;
+ Assert.assertEquals(expect, new BrokerConfig().getConsumerFallbehindThreshold());
+ }
+
+}
\ No newline at end of file
diff --git a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
index 8d8cf79600b..0db84fe461f 100644
--- a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
+++ b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
@@ -21,6 +21,8 @@
import java.util.Properties;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
public class UtilAllTest {
@@ -78,6 +80,17 @@ public void test_getpid() {
assertTrue(pid > 0);
}
+ @Test
+ public void test_getDiskPartitionSpaceUsedPercent() {
+ assertEquals(-1, UtilAll.getDiskPartitionSpaceUsedPercent(null), 0);
+ assertEquals(-1, UtilAll.getDiskPartitionSpaceUsedPercent(""), 0);
+
+ assertEquals(-1, UtilAll.getDiskPartitionSpaceUsedPercent("nonExistingPath"), 0);
+
+ String tmpDir = System.getProperty("java.io.tmpdir");
+ assertNotEquals(-1, UtilAll.getDiskPartitionSpaceUsedPercent(tmpDir), 0);
+ }
+
@Test
public void test_isBlank() {
{
diff --git a/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java
index 7b79b370e8e..d63435b5923 100644
--- a/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java
+++ b/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java
@@ -16,6 +16,7 @@
*/
package org.apache.rocketmq.example.filter;
+import java.io.File;
import java.util.List;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
@@ -30,8 +31,11 @@ public class Consumer {
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4");
- String filterCode = MixAll.file2String("/home/admin/MessageFilterImpl.java");
- consumer.subscribe("TopicFilter7", "org.apache.rocketmq.example.filter.MessageFilterImpl",
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ File classFile = new File(classLoader.getResource("MessageFilterImpl.java").getFile());
+
+ String filterCode = MixAll.file2String(classFile);
+ consumer.subscribe("TopicTest", "org.apache.rocketmq.example.filter.MessageFilterImpl",
filterCode);
consumer.registerMessageListener(new MessageListenerConcurrently() {
diff --git a/example/src/main/resources/MessageFilterImpl.java b/example/src/main/resources/MessageFilterImpl.java
index 83ca00ef2cb..23e4a79b942 100644
--- a/example/src/main/resources/MessageFilterImpl.java
+++ b/example/src/main/resources/MessageFilterImpl.java
@@ -17,13 +17,14 @@
package org.apache.rocketmq.example.filter;
+import org.apache.rocketmq.common.filter.FilterContext;
import org.apache.rocketmq.common.filter.MessageFilter;
import org.apache.rocketmq.common.message.MessageExt;
public class MessageFilterImpl implements MessageFilter {
@Override
- public boolean match(MessageExt msg) {
+ public boolean match(MessageExt msg, FilterContext context) {
String property = msg.getProperty("SequenceId");
if (property != null) {
int id = Integer.parseInt(property);
diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java
index 69b64ca7ef3..16b7847ae92 100644
--- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java
+++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java
@@ -610,7 +610,7 @@ public byte[] getSystemTopicList() {
while (it.hasNext()) {
BrokerData bd = brokerAddrTable.get(it.next());
HashMap