提交 c6096a14 编写于 作者: K King 提交者: Heng Du

Polish lite pull consumer (#1381)

* fix unsubscribe code

* fix commit consumed offset

* fix commit consumed offset

* fix commit consumed offset

* fix commit consumed offset

* polish commit consumed offset

* pass checkstyle

* pass checkstyle

* polish LiteMQPullConsumer

* add flow control and polish commit logic

* fix bug

* polish code

* fix commit consumed offset back

* refactor litePullConsumer

* development save

* development save

* Refactor DefaultLitePullConsumer and DefaultLitePullConsumerImpl.

* Polish lite pull consumer

* polish lite pull consumer

* polish lite pull consumer

* fix seek

* fix seek function

* polish lite pull consumer

* add apache header

* add test

* polish test

* Make broadcast model work for litePullConsumer

* Revert example/broadcast/PushConsumer.java

* Add delay time when no new message

* Enable long polling mode

* Fix subscribe bug when rebalance

* Delete useless consumeMessageHook

* Implement TopicMessageQueueChangeListener interface

* Lite pull consumer support namespace

* Make sql92 filter work
上级 46288abb
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
*/ */
package org.apache.rocketmq.client; package org.apache.rocketmq.client;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.UtilAll;
...@@ -95,7 +97,6 @@ public class ClientConfig { ...@@ -95,7 +97,6 @@ public class ClientConfig {
} }
} }
public String withNamespace(String resource) { public String withNamespace(String resource) {
return NamespaceUtil.wrapNamespace(this.getNamespace(), resource); return NamespaceUtil.wrapNamespace(this.getNamespace(), resource);
} }
...@@ -124,9 +125,21 @@ public class ClientConfig { ...@@ -124,9 +125,21 @@ public class ClientConfig {
if (StringUtils.isEmpty(this.getNamespace())) { if (StringUtils.isEmpty(this.getNamespace())) {
return queue; return queue;
} }
return new MessageQueue(withNamespace(queue.getTopic()), queue.getBrokerName(), queue.getQueueId()); return new MessageQueue(withNamespace(queue.getTopic()), queue.getBrokerName(), queue.getQueueId());
} }
public Collection<MessageQueue> queuesWithNamespace(Collection<MessageQueue> queues) {
if (StringUtils.isEmpty(this.getNamespace())) {
return queues;
}
Iterator<MessageQueue> iter = queues.iterator();
while (iter.hasNext()) {
MessageQueue queue = iter.next();
queue.setTopic(withNamespace(queue.getTopic()));
}
return queues;
}
public void resetClientConfig(final ClientConfig cc) { public void resetClientConfig(final ClientConfig cc) {
this.namesrvAddr = cc.namesrvAddr; this.namesrvAddr = cc.namesrvAddr;
this.clientIP = cc.clientIP; this.clientIP = cc.clientIP;
...@@ -170,6 +183,7 @@ public class ClientConfig { ...@@ -170,6 +183,7 @@ public class ClientConfig {
/** /**
* Domain name mode access way does not support the delimiter(;), and only one domain name can be set. * Domain name mode access way does not support the delimiter(;), and only one domain name can be set.
*
* @param namesrvAddr name server address * @param namesrvAddr name server address
*/ */
public void setNamesrvAddr(String namesrvAddr) { public void setNamesrvAddr(String namesrvAddr) {
......
...@@ -176,17 +176,22 @@ public class DefaultLitePullConsumer extends ClientConfig implements LitePullCon ...@@ -176,17 +176,22 @@ public class DefaultLitePullConsumer extends ClientConfig implements LitePullCon
@Override @Override
public void subscribe(String topic, String subExpression) throws MQClientException { public void subscribe(String topic, String subExpression) throws MQClientException {
this.defaultLitePullConsumerImpl.subscribe(topic, subExpression); this.defaultLitePullConsumerImpl.subscribe(withNamespace(topic), subExpression);
}
@Override
public void subscribe(String topic, MessageSelector messageSelector) throws MQClientException {
this.defaultLitePullConsumerImpl.subscribe(withNamespace(topic), messageSelector);
} }
@Override @Override
public void unsubscribe(String topic) { public void unsubscribe(String topic) {
this.defaultLitePullConsumerImpl.unsubscribe(topic); this.defaultLitePullConsumerImpl.unsubscribe(withNamespace(topic));
} }
@Override @Override
public void assign(Collection<MessageQueue> messageQueues) { public void assign(Collection<MessageQueue> messageQueues) {
defaultLitePullConsumerImpl.assign(messageQueues); defaultLitePullConsumerImpl.assign(queuesWithNamespace(messageQueues));
} }
@Override @Override
...@@ -201,17 +206,17 @@ public class DefaultLitePullConsumer extends ClientConfig implements LitePullCon ...@@ -201,17 +206,17 @@ public class DefaultLitePullConsumer extends ClientConfig implements LitePullCon
@Override @Override
public void seek(MessageQueue messageQueue, long offset) throws MQClientException { public void seek(MessageQueue messageQueue, long offset) throws MQClientException {
this.defaultLitePullConsumerImpl.seek(messageQueue, offset); this.defaultLitePullConsumerImpl.seek(queueWithNamespace(messageQueue), offset);
} }
@Override @Override
public void pause(Collection<MessageQueue> messageQueues) { public void pause(Collection<MessageQueue> messageQueues) {
this.defaultLitePullConsumerImpl.pause(messageQueues); this.defaultLitePullConsumerImpl.pause(queuesWithNamespace(messageQueues));
} }
@Override @Override
public void resume(Collection<MessageQueue> messageQueues) { public void resume(Collection<MessageQueue> messageQueues) {
this.defaultLitePullConsumerImpl.resume(messageQueues); this.defaultLitePullConsumerImpl.resume(queuesWithNamespace(messageQueues));
} }
@Override @Override
...@@ -221,7 +226,12 @@ public class DefaultLitePullConsumer extends ClientConfig implements LitePullCon ...@@ -221,7 +226,12 @@ public class DefaultLitePullConsumer extends ClientConfig implements LitePullCon
@Override @Override
public Long offsetForTimestamp(MessageQueue messageQueue, Long timestamp) throws MQClientException { public Long offsetForTimestamp(MessageQueue messageQueue, Long timestamp) throws MQClientException {
return this.defaultLitePullConsumerImpl.searchOffset(messageQueue, timestamp); return this.defaultLitePullConsumerImpl.searchOffset(queueWithNamespace(messageQueue), timestamp);
}
public void registerTopicMessageQueueChangeListener(String topic,
TopicMessageQueueChangeListener topicMessageQueueChangeListener) throws MQClientException {
this.defaultLitePullConsumerImpl.registerTopicMessageQueueChangeListener(withNamespace(topic), topicMessageQueueChangeListener);
} }
@Override @Override
...@@ -390,5 +400,4 @@ public class DefaultLitePullConsumer extends ClientConfig implements LitePullCon ...@@ -390,5 +400,4 @@ public class DefaultLitePullConsumer extends ClientConfig implements LitePullCon
public void setPullDelayTimeMills(long pullDelayTimeMills) { public void setPullDelayTimeMills(long pullDelayTimeMills) {
this.pullDelayTimeMills = pullDelayTimeMills; this.pullDelayTimeMills = pullDelayTimeMills;
} }
} }
...@@ -36,13 +36,20 @@ public interface LitePullConsumer { ...@@ -36,13 +36,20 @@ public interface LitePullConsumer {
void shutdown(); void shutdown();
/** /**
* Subscribe some topic * Subscribe some topic with subExpression
* *
* @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3" <br> if * @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3" <br> if
* null or * expression,meaning subscribe all * null or * expression,meaning subscribe all
*/ */
void subscribe(final String topic, final String subExpression) throws MQClientException; void subscribe(final String topic, final String subExpression) throws MQClientException;
/**
* Subscribe some topic with selector.
*
* @param selector message selector({@link MessageSelector}), can be null.
*/
void subscribe(final String topic, final MessageSelector selector) throws MQClientException;
/** /**
* Unsubscribe consumption some topic * Unsubscribe consumption some topic
* *
......
/*
* 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.client.consumer;
import java.util.Set;
import org.apache.rocketmq.common.message.MessageQueue;
public interface TopicMessageQueueChangeListener {
/**
* This method will be invoked in the condition of queue numbers changed, These scenarios occur when the topic is
* expanded or shrunk.
*
* @param messageQueues
*/
void onChanged(String topic, Set<MessageQueue> messageQueues);
}
...@@ -138,7 +138,6 @@ public class AssignedMessageQueue { ...@@ -138,7 +138,6 @@ public class AssignedMessageQueue {
Map.Entry<MessageQueue, MessageQueueStat> next = it.next(); Map.Entry<MessageQueue, MessageQueueStat> next = it.next();
if (next.getKey().getTopic().equals(topic)) { if (next.getKey().getTopic().equals(topic)) {
if (!assigned.contains(next.getKey())) { if (!assigned.contains(next.getKey())) {
System.out.printf("MessageQueue-%s is removed %n", next.getKey());
next.getValue().getProcessQueue().setDropped(true); next.getValue().getProcessQueue().setDropped(true);
it.remove(); it.remove();
} }
...@@ -167,7 +166,6 @@ public class AssignedMessageQueue { ...@@ -167,7 +166,6 @@ public class AssignedMessageQueue {
if (!this.assignedMessageQueueState.containsKey(messageQueue)) { if (!this.assignedMessageQueueState.containsKey(messageQueue)) {
MessageQueueStat messageQueueStat; MessageQueueStat messageQueueStat;
if (rebalanceImpl != null && rebalanceImpl.getProcessQueueTable().get(messageQueue) != null) { if (rebalanceImpl != null && rebalanceImpl.getProcessQueueTable().get(messageQueue) != null) {
System.out.printf("MessageQueue-%s is added %n", messageQueue);
messageQueueStat = new MessageQueueStat(messageQueue, rebalanceImpl.getProcessQueueTable().get(messageQueue)); messageQueueStat = new MessageQueueStat(messageQueue, rebalanceImpl.getProcessQueueTable().get(messageQueue));
} else { } else {
ProcessQueue processQueue = new ProcessQueue(); ProcessQueue processQueue = new ProcessQueue();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册