mirror of
https://github.com/apache/rocketmq.git
synced 2026-08-30 18:10:44 +08:00
Merge branch 'develop'
This commit is contained in:
-13
@@ -14,10 +14,6 @@ matrix:
|
||||
# On Linux, run with specific JDKs only.
|
||||
- os: linux
|
||||
env: CUSTOM_JDK="oraclejdk8"
|
||||
- os: linux
|
||||
env: CUSTOM_JDK="oraclejdk7"
|
||||
- os: linux
|
||||
env: CUSTOM_JDK="openjdk7"
|
||||
|
||||
before_install:
|
||||
- echo 'MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -XX:MaxPermSize=512m -XX:+BytecodeVerificationLocal"' >> ~/.mavenrc
|
||||
@@ -25,15 +21,6 @@ before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export JAVA_HOME=$(/usr/libexec/java_home); fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then jdk_switcher use "$CUSTOM_JDK"; fi
|
||||
|
||||
#os:
|
||||
# - linux
|
||||
# - osx
|
||||
#jdk:
|
||||
# - oraclejdk8
|
||||
# - oraclejdk7
|
||||
# - openjdk7
|
||||
|
||||
|
||||
script:
|
||||
- travis_retry mvn -B clean apache-rat:check
|
||||
- travis_retry mvn -B package jacoco:report coveralls:report
|
||||
|
||||
@@ -135,11 +135,11 @@ public class BrokerController {
|
||||
private BrokerFastFailure brokerFastFailure;
|
||||
private Configuration configuration;
|
||||
|
||||
public BrokerController(//
|
||||
final BrokerConfig brokerConfig, //
|
||||
final NettyServerConfig nettyServerConfig, //
|
||||
final NettyClientConfig nettyClientConfig, //
|
||||
final MessageStoreConfig messageStoreConfig //
|
||||
public BrokerController(
|
||||
final BrokerConfig brokerConfig,
|
||||
final NettyServerConfig nettyServerConfig,
|
||||
final NettyClientConfig nettyClientConfig,
|
||||
final MessageStoreConfig messageStoreConfig
|
||||
) {
|
||||
this.brokerConfig = brokerConfig;
|
||||
this.nettyServerConfig = nettyServerConfig;
|
||||
@@ -255,7 +255,6 @@ public class BrokerController {
|
||||
|
||||
this.registerProcessor();
|
||||
|
||||
// TODO remove in future
|
||||
final long initialDelay = UtilAll.computNextMorningTimeMillis() - System.currentTimeMillis();
|
||||
final long period = 1000 * 60 * 60 * 24;
|
||||
this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.apache.rocketmq.broker;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
public class BrokerPathConfigHelper {
|
||||
private static String brokerConfigPath = System.getProperty("user.home") + File.separator + "store"
|
||||
+ File.separator + "config" + File.separator + "broker.properties";
|
||||
|
||||
@@ -190,10 +190,10 @@ public class BrokerStartup {
|
||||
MixAll.printObjectProperties(log, nettyClientConfig);
|
||||
MixAll.printObjectProperties(log, messageStoreConfig);
|
||||
|
||||
final BrokerController controller = new BrokerController(//
|
||||
brokerConfig, //
|
||||
nettyServerConfig, //
|
||||
nettyClientConfig, //
|
||||
final BrokerController controller = new BrokerController(
|
||||
brokerConfig,
|
||||
nettyServerConfig,
|
||||
nettyClientConfig,
|
||||
messageStoreConfig);
|
||||
// remember all configs to prevent discard
|
||||
controller.getConfiguration().registerConfig(properties);
|
||||
|
||||
@@ -122,7 +122,8 @@ public class ConsumerManager {
|
||||
return r1 || r2;
|
||||
}
|
||||
|
||||
public void unregisterConsumer(final String group, final ClientChannelInfo clientChannelInfo, boolean isNotifyConsumerIdsChangedEnable) {
|
||||
public void unregisterConsumer(final String group, final ClientChannelInfo clientChannelInfo,
|
||||
boolean isNotifyConsumerIdsChangedEnable) {
|
||||
ConsumerGroupInfo consumerGroupInfo = this.consumerTable.get(group);
|
||||
if (null != consumerGroupInfo) {
|
||||
consumerGroupInfo.unregisterChannel(clientChannelInfo);
|
||||
|
||||
+22
-22
@@ -52,9 +52,9 @@ public class RebalanceLockManager {
|
||||
lockEntry = new LockEntry();
|
||||
lockEntry.setClientId(clientId);
|
||||
groupValue.put(mq, lockEntry);
|
||||
log.info("tryLock, message queue not locked, I got it. Group: {} NewClientId: {} {}", //
|
||||
group, //
|
||||
clientId, //
|
||||
log.info("tryLock, message queue not locked, I got it. Group: {} NewClientId: {} {}",
|
||||
group,
|
||||
clientId,
|
||||
mq);
|
||||
}
|
||||
|
||||
@@ -69,19 +69,19 @@ public class RebalanceLockManager {
|
||||
lockEntry.setClientId(clientId);
|
||||
lockEntry.setLastUpdateTimestamp(System.currentTimeMillis());
|
||||
log.warn(
|
||||
"tryLock, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", //
|
||||
group, //
|
||||
oldClientId, //
|
||||
clientId, //
|
||||
"tryLock, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}",
|
||||
group,
|
||||
oldClientId,
|
||||
clientId,
|
||||
mq);
|
||||
return true;
|
||||
}
|
||||
|
||||
log.warn(
|
||||
"tryLock, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", //
|
||||
group, //
|
||||
oldClientId, //
|
||||
clientId, //
|
||||
"tryLock, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}",
|
||||
group,
|
||||
oldClientId,
|
||||
clientId,
|
||||
mq);
|
||||
return false;
|
||||
} finally {
|
||||
@@ -144,9 +144,9 @@ public class RebalanceLockManager {
|
||||
lockEntry.setClientId(clientId);
|
||||
groupValue.put(mq, lockEntry);
|
||||
log.info(
|
||||
"tryLockBatch, message queue not locked, I got it. Group: {} NewClientId: {} {}", //
|
||||
group, //
|
||||
clientId, //
|
||||
"tryLockBatch, message queue not locked, I got it. Group: {} NewClientId: {} {}",
|
||||
group,
|
||||
clientId,
|
||||
mq);
|
||||
}
|
||||
|
||||
@@ -162,20 +162,20 @@ public class RebalanceLockManager {
|
||||
lockEntry.setClientId(clientId);
|
||||
lockEntry.setLastUpdateTimestamp(System.currentTimeMillis());
|
||||
log.warn(
|
||||
"tryLockBatch, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", //
|
||||
group, //
|
||||
oldClientId, //
|
||||
clientId, //
|
||||
"tryLockBatch, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}",
|
||||
group,
|
||||
oldClientId,
|
||||
clientId,
|
||||
mq);
|
||||
lockedMqs.add(mq);
|
||||
continue;
|
||||
}
|
||||
|
||||
log.warn(
|
||||
"tryLockBatch, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", //
|
||||
group, //
|
||||
oldClientId, //
|
||||
clientId, //
|
||||
"tryLockBatch, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}",
|
||||
group,
|
||||
oldClientId,
|
||||
clientId,
|
||||
mq);
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -54,9 +54,6 @@ public class ConsumerFilterData {
|
||||
|
||||
/**
|
||||
* Check this filter data has been used to calculate bit map when msg was stored in server.
|
||||
*
|
||||
* @param msgStoreTime
|
||||
* @return
|
||||
*/
|
||||
public boolean isMsgInLive(long msgStoreTime) {
|
||||
return msgStoreTime > getBornTime();
|
||||
|
||||
@@ -72,16 +72,11 @@ public class ConsumerFilterManager extends ConfigManager {
|
||||
/**
|
||||
* Build consumer filter data.Be care, bloom filter data is not included.
|
||||
*
|
||||
* @param topic
|
||||
* @param consumerGroup
|
||||
* @param expression
|
||||
* @param type
|
||||
* @param clientVersion
|
||||
* @return maybe null
|
||||
*/
|
||||
public static ConsumerFilterData build(final String topic, final String consumerGroup,
|
||||
final String expression, final String type,
|
||||
final long clientVersion) {
|
||||
final String expression, final String type,
|
||||
final long clientVersion) {
|
||||
if (ExpressionType.isTagType(type)) {
|
||||
return null;
|
||||
}
|
||||
@@ -140,7 +135,7 @@ public class ConsumerFilterManager extends ConfigManager {
|
||||
}
|
||||
|
||||
public boolean register(final String topic, final String consumerGroup, final String expression,
|
||||
final String type, final long clientVersion) {
|
||||
final String type, final long clientVersion) {
|
||||
if (ExpressionType.isTagType(type)) {
|
||||
return false;
|
||||
}
|
||||
@@ -357,7 +352,8 @@ public class ConsumerFilterManager extends ConfigManager {
|
||||
data.setDeadTime(now);
|
||||
}
|
||||
|
||||
public boolean register(String consumerGroup, String expression, String type, BloomFilterData bloomFilterData, long clientVersion) {
|
||||
public boolean register(String consumerGroup, String expression, String type, BloomFilterData bloomFilterData,
|
||||
long clientVersion) {
|
||||
ConsumerFilterData old = this.groupFilterData.get(consumerGroup);
|
||||
|
||||
if (old == null) {
|
||||
|
||||
+2
-2
@@ -17,7 +17,6 @@
|
||||
|
||||
package org.apache.rocketmq.broker.filter;
|
||||
|
||||
|
||||
import org.apache.rocketmq.common.MixAll;
|
||||
import org.apache.rocketmq.common.filter.ExpressionType;
|
||||
import org.apache.rocketmq.common.message.MessageConst;
|
||||
@@ -32,7 +31,8 @@ import java.util.Map;
|
||||
* <br>It will decode properties first in order to get real topic.
|
||||
*/
|
||||
public class ExpressionForRetryMessageFilter extends ExpressionMessageFilter {
|
||||
public ExpressionForRetryMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData, ConsumerFilterManager consumerFilterManager) {
|
||||
public ExpressionForRetryMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData,
|
||||
ConsumerFilterManager consumerFilterManager) {
|
||||
super(subscriptionData, consumerFilterData, consumerFilterManager);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ExpressionMessageFilter implements MessageFilter {
|
||||
protected final boolean bloomDataValid;
|
||||
|
||||
public ExpressionMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData,
|
||||
ConsumerFilterManager consumerFilterManager) {
|
||||
ConsumerFilterManager consumerFilterManager) {
|
||||
this.subscriptionData = subscriptionData;
|
||||
this.consumerFilterData = consumerFilterData;
|
||||
this.consumerFilterManager = consumerFilterManager;
|
||||
|
||||
@@ -111,9 +111,6 @@ public class FilterServerManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
public void scanNotActiveChannel() {
|
||||
|
||||
Iterator<Entry<Channel, FilterServerInfo>> it = this.filterServerTable.entrySet().iterator();
|
||||
|
||||
@@ -103,6 +103,7 @@ public class BrokerFastFailure {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.scheduledExecutorService.shutdown();
|
||||
}
|
||||
|
||||
+10
-5
@@ -25,23 +25,28 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BrokerFixedThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit,
|
||||
public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime,
|
||||
final TimeUnit unit,
|
||||
final BlockingQueue<Runnable> workQueue) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
|
||||
}
|
||||
|
||||
public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit,
|
||||
public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime,
|
||||
final TimeUnit unit,
|
||||
final BlockingQueue<Runnable> workQueue, final ThreadFactory threadFactory) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
|
||||
}
|
||||
|
||||
public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit,
|
||||
public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime,
|
||||
final TimeUnit unit,
|
||||
final BlockingQueue<Runnable> workQueue, final RejectedExecutionHandler handler) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
|
||||
}
|
||||
|
||||
public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit,
|
||||
final BlockingQueue<Runnable> workQueue, final ThreadFactory threadFactory, final RejectedExecutionHandler handler) {
|
||||
public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime,
|
||||
final TimeUnit unit,
|
||||
final BlockingQueue<Runnable> workQueue, final ThreadFactory threadFactory,
|
||||
final RejectedExecutionHandler handler) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class NotifyMessageArrivingListener implements MessageArrivingListener {
|
||||
|
||||
@Override
|
||||
public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
|
||||
long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
|
||||
long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
|
||||
this.pullRequestHoldService.notifyMessageArriving(topic, queueId, logicOffset, tagsCode,
|
||||
msgStoreTime, filterBitMap, properties);
|
||||
}
|
||||
|
||||
+1
-1
@@ -114,7 +114,7 @@ public class PullRequestHoldService extends ServiceThread {
|
||||
}
|
||||
|
||||
public void notifyMessageArriving(final String topic, final int queueId, final long maxOffset, final Long tagsCode,
|
||||
long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
|
||||
long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
|
||||
String key = this.buildKey(topic, queueId);
|
||||
ManyPullRequest mpr = this.pullRequestTable.get(key);
|
||||
if (mpr != null) {
|
||||
|
||||
@@ -118,7 +118,8 @@ public class ConsumerOffsetManager extends ConfigManager {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset) {
|
||||
public void commitOffset(final String clientHost, final String group, final String topic, final int queueId,
|
||||
final long offset) {
|
||||
// topic@group
|
||||
String key = topic + TOPIC_GROUP_SEPARATOR + group;
|
||||
this.commitOffset(clientHost, key, queueId, offset);
|
||||
|
||||
@@ -231,7 +231,8 @@ public class BrokerOuterAPI {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public TopicConfigSerializeWrapper getAllTopicConfig(final String addr) throws RemotingConnectException, RemotingSendRequestException,
|
||||
public TopicConfigSerializeWrapper getAllTopicConfig(
|
||||
final String addr) throws RemotingConnectException, RemotingSendRequestException,
|
||||
RemotingTimeoutException, InterruptedException, MQBrokerException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null);
|
||||
|
||||
@@ -248,7 +249,8 @@ public class BrokerOuterAPI {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public ConsumerOffsetSerializeWrapper getAllConsumerOffset(final String addr) throws InterruptedException, RemotingTimeoutException,
|
||||
public ConsumerOffsetSerializeWrapper getAllConsumerOffset(
|
||||
final String addr) throws InterruptedException, RemotingTimeoutException,
|
||||
RemotingSendRequestException, RemotingConnectException, MQBrokerException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_CONSUMER_OFFSET, null);
|
||||
RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
|
||||
@@ -264,7 +266,8 @@ public class BrokerOuterAPI {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public String getAllDelayOffset(final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException,
|
||||
public String getAllDelayOffset(
|
||||
final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException,
|
||||
RemotingConnectException, MQBrokerException, UnsupportedEncodingException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_DELAY_OFFSET, null);
|
||||
RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
|
||||
@@ -280,7 +283,8 @@ public class BrokerOuterAPI {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(final String addr) throws InterruptedException, RemotingTimeoutException,
|
||||
public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(
|
||||
final String addr) throws InterruptedException, RemotingTimeoutException,
|
||||
RemotingSendRequestException, RemotingConnectException, MQBrokerException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
|
||||
RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
|
||||
|
||||
@@ -28,7 +28,9 @@ public class ManyMessageTransfer extends AbstractReferenceCounted implements Fil
|
||||
private final ByteBuffer byteBufferHeader;
|
||||
private final GetMessageResult getMessageResult;
|
||||
|
||||
/** Bytes which were transferred already. */
|
||||
/**
|
||||
* Bytes which were transferred already.
|
||||
*/
|
||||
private long transferred;
|
||||
|
||||
public ManyMessageTransfer(ByteBuffer byteBufferHeader, GetMessageResult getMessageResult) {
|
||||
|
||||
@@ -27,7 +27,9 @@ public class OneMessageTransfer extends AbstractReferenceCounted implements File
|
||||
private final ByteBuffer byteBufferHeader;
|
||||
private final SelectMappedBufferResult selectMappedBufferResult;
|
||||
|
||||
/** Bytes which were transferred already. */
|
||||
/**
|
||||
* Bytes which were transferred already.
|
||||
*/
|
||||
private long transferred;
|
||||
|
||||
public OneMessageTransfer(ByteBuffer byteBufferHeader, SelectMappedBufferResult selectMappedBufferResult) {
|
||||
|
||||
@@ -28,7 +28,9 @@ public class QueryMessageTransfer extends AbstractReferenceCounted implements Fi
|
||||
private final ByteBuffer byteBufferHeader;
|
||||
private final QueryMessageResult queryMessageResult;
|
||||
|
||||
/** Bytes which were transferred already. */
|
||||
/**
|
||||
* Bytes which were transferred already.
|
||||
*/
|
||||
private long transferred;
|
||||
|
||||
public QueryMessageTransfer(ByteBuffer byteBufferHeader, QueryMessageResult queryMessageResult) {
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public abstract class AbstractPluginMessageStore implements MessageStore {
|
||||
|
||||
@Override
|
||||
public GetMessageResult getMessage(String group, String topic, int queueId, long offset,
|
||||
int maxMsgNums, final MessageFilter messageFilter) {
|
||||
int maxMsgNums, final MessageFilter messageFilter) {
|
||||
return next.getMessage(group, topic, queueId, offset, maxMsgNums, messageFilter);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -189,10 +189,10 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces
|
||||
}
|
||||
|
||||
log.warn("the topic {} not exist, producer: {}", requestHeader.getTopic(), ctx.channel().remoteAddress());
|
||||
topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageMethod(//
|
||||
requestHeader.getTopic(), //
|
||||
requestHeader.getDefaultTopic(), //
|
||||
RemotingHelper.parseChannelRemoteAddr(ctx.channel()), //
|
||||
topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageMethod(
|
||||
requestHeader.getTopic(),
|
||||
requestHeader.getDefaultTopic(),
|
||||
RemotingHelper.parseChannelRemoteAddr(ctx.channel()),
|
||||
requestHeader.getDefaultTopicQueueNums(), topicSysFlag);
|
||||
|
||||
if (null == topicConfig) {
|
||||
|
||||
+72
-57
@@ -125,7 +125,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand processRequest(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
switch (request.getCode()) {
|
||||
case RequestCode.UPDATE_AND_CREATE_TOPIC:
|
||||
return this.updateAndCreateTopic(ctx, request);
|
||||
@@ -211,7 +212,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
private RemotingCommand updateAndCreateTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand updateAndCreateTopic(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
final CreateTopicRequestHeader requestHeader =
|
||||
(CreateTopicRequestHeader) request.decodeCommandCustomHeader(CreateTopicRequestHeader.class);
|
||||
@@ -248,7 +250,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
private RemotingCommand deleteTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand deleteTopic(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
DeleteTopicRequestHeader requestHeader =
|
||||
(DeleteTopicRequestHeader) request.decodeCommandCustomHeader(DeleteTopicRequestHeader.class);
|
||||
@@ -354,7 +357,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(SearchOffsetResponseHeader.class);
|
||||
final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response.readCustomHeader();
|
||||
final SearchOffsetRequestHeader requestHeader =
|
||||
@@ -370,7 +374,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand getMaxOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getMaxOffset(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(GetMaxOffsetResponseHeader.class);
|
||||
final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader) response.readCustomHeader();
|
||||
final GetMaxOffsetRequestHeader requestHeader =
|
||||
@@ -385,7 +390,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand getMinOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getMinOffset(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(GetMinOffsetResponseHeader.class);
|
||||
final GetMinOffsetResponseHeader responseHeader = (GetMinOffsetResponseHeader) response.readCustomHeader();
|
||||
final GetMinOffsetRequestHeader requestHeader =
|
||||
@@ -399,7 +405,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand getEarliestMsgStoretime(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getEarliestMsgStoretime(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(GetEarliestMsgStoretimeResponseHeader.class);
|
||||
final GetEarliestMsgStoretimeResponseHeader responseHeader = (GetEarliestMsgStoretimeResponseHeader) response.readCustomHeader();
|
||||
final GetEarliestMsgStoretimeRequestHeader requestHeader =
|
||||
@@ -428,13 +435,14 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
LockBatchRequestBody requestBody = LockBatchRequestBody.decode(request.getBody(), LockBatchRequestBody.class);
|
||||
|
||||
Set<MessageQueue> lockOKMQSet = this.brokerController.getRebalanceLockManager().tryLockBatch(//
|
||||
requestBody.getConsumerGroup(), //
|
||||
requestBody.getMqSet(), //
|
||||
Set<MessageQueue> lockOKMQSet = this.brokerController.getRebalanceLockManager().tryLockBatch(
|
||||
requestBody.getConsumerGroup(),
|
||||
requestBody.getMqSet(),
|
||||
requestBody.getClientId());
|
||||
|
||||
LockBatchResponseBody responseBody = new LockBatchResponseBody();
|
||||
@@ -446,13 +454,14 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand unlockBatchMQ(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand unlockBatchMQ(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
UnlockBatchRequestBody requestBody = UnlockBatchRequestBody.decode(request.getBody(), UnlockBatchRequestBody.class);
|
||||
|
||||
this.brokerController.getRebalanceLockManager().unlockBatch(//
|
||||
requestBody.getConsumerGroup(), //
|
||||
requestBody.getMqSet(), //
|
||||
this.brokerController.getRebalanceLockManager().unlockBatch(
|
||||
requestBody.getConsumerGroup(),
|
||||
requestBody.getMqSet(),
|
||||
requestBody.getClientId());
|
||||
|
||||
response.setCode(ResponseCode.SUCCESS);
|
||||
@@ -476,7 +485,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
String content = this.brokerController.getSubscriptionGroupManager().encode();
|
||||
if (content != null && content.length() > 0) {
|
||||
@@ -502,7 +512,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand deleteSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand deleteSubscriptionGroup(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
DeleteSubscriptionGroupRequestHeader requestHeader =
|
||||
(DeleteSubscriptionGroupRequestHeader) request.decodeCommandCustomHeader(DeleteSubscriptionGroupRequestHeader.class);
|
||||
@@ -516,7 +527,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
final GetTopicStatsInfoRequestHeader requestHeader =
|
||||
(GetTopicStatsInfoRequestHeader) request.decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class);
|
||||
@@ -564,7 +576,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
final GetConsumerConnectionListRequestHeader requestHeader =
|
||||
(GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class);
|
||||
@@ -603,7 +616,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
final GetProducerConnectionListRequestHeader requestHeader =
|
||||
(GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class);
|
||||
@@ -636,7 +650,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getConsumeStats(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
final GetConsumeStatsRequestHeader requestHeader =
|
||||
(GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class);
|
||||
@@ -657,14 +672,11 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
{
|
||||
SubscriptionData findSubscriptionData =
|
||||
this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic);
|
||||
|
||||
if (null == findSubscriptionData //
|
||||
if (null == findSubscriptionData
|
||||
&& this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) {
|
||||
log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic);
|
||||
continue;
|
||||
@@ -683,9 +695,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
if (brokerOffset < 0)
|
||||
brokerOffset = 0;
|
||||
|
||||
long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(//
|
||||
requestHeader.getConsumerGroup(), //
|
||||
topic, //
|
||||
long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(
|
||||
requestHeader.getConsumerGroup(),
|
||||
topic,
|
||||
i);
|
||||
if (consumerOffset < 0)
|
||||
consumerOffset = 0;
|
||||
@@ -771,7 +783,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
public RemotingCommand resetOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand resetOffset(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final ResetOffsetRequestHeader requestHeader =
|
||||
(ResetOffsetRequestHeader) request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class);
|
||||
log.info("[reset-offset] reset offset started by {}. topic={}, group={}, timestamp={}, isForce={}",
|
||||
@@ -788,7 +801,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
requestHeader.getTimestamp(), requestHeader.isForce(), isC);
|
||||
}
|
||||
|
||||
public RemotingCommand getConsumerStatus(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand getConsumerStatus(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final GetConsumerStatusRequestHeader requestHeader =
|
||||
(GetConsumerStatusRequestHeader) request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class);
|
||||
|
||||
@@ -799,7 +813,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
requestHeader.getClientAddr());
|
||||
}
|
||||
|
||||
private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
QueryTopicConsumeByWhoRequestHeader requestHeader =
|
||||
(QueryTopicConsumeByWhoRequestHeader) request.decodeCommandCustomHeader(QueryTopicConsumeByWhoRequestHeader.class);
|
||||
@@ -821,7 +836,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand registerFilterServer(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand registerFilterServer(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterFilterServerResponseHeader.class);
|
||||
final RegisterFilterServerResponseHeader responseHeader = (RegisterFilterServerResponseHeader) response.readCustomHeader();
|
||||
final RegisterFilterServerRequestHeader requestHeader =
|
||||
@@ -837,7 +853,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
QueryConsumeTimeSpanRequestHeader requestHeader =
|
||||
(QueryConsumeTimeSpanRequestHeader) request.decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class);
|
||||
@@ -925,10 +942,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final GetConsumerRunningInfoRequestHeader requestHeader =
|
||||
(GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class);
|
||||
|
||||
@@ -936,7 +951,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
requestHeader.getClientId());
|
||||
}
|
||||
|
||||
private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
QueryCorrectionOffsetHeader requestHeader =
|
||||
(QueryCorrectionOffsetHeader) request.decodeCommandCustomHeader(QueryCorrectionOffsetHeader.class);
|
||||
@@ -963,7 +979,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request
|
||||
.decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);
|
||||
|
||||
@@ -987,7 +1004,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
requestHeader.getClientId());
|
||||
}
|
||||
|
||||
private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
CloneGroupOffsetRequestHeader requestHeader =
|
||||
(CloneGroupOffsetRequestHeader) request.decodeCommandCustomHeader(CloneGroupOffsetRequestHeader.class);
|
||||
@@ -1007,9 +1025,6 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
if (!requestHeader.isOffline()) {
|
||||
|
||||
SubscriptionData findSubscriptionData =
|
||||
@@ -1030,7 +1045,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final ViewBrokerStatsDataRequestHeader requestHeader =
|
||||
(ViewBrokerStatsDataRequestHeader) request.decodeCommandCustomHeader(ViewBrokerStatsDataRequestHeader.class);
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
@@ -1107,13 +1123,11 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
if (isOrder && !topicConfig.isOrder()) {
|
||||
continue;
|
||||
}
|
||||
/**
|
||||
|
||||
*/
|
||||
{
|
||||
SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(group, topic);
|
||||
|
||||
if (null == findSubscriptionData //
|
||||
if (null == findSubscriptionData
|
||||
&& this.brokerController.getConsumerManager().findSubscriptionDataCount(group) > 0) {
|
||||
log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", group, topic);
|
||||
continue;
|
||||
@@ -1129,9 +1143,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i);
|
||||
if (brokerOffset < 0)
|
||||
brokerOffset = 0;
|
||||
long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(//
|
||||
group, //
|
||||
topic, //
|
||||
long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(
|
||||
group,
|
||||
topic,
|
||||
i);
|
||||
if (consumerOffset < 0)
|
||||
consumerOffset = 0;
|
||||
@@ -1215,10 +1229,10 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
return runtimeInfo;
|
||||
}
|
||||
|
||||
private RemotingCommand callConsumer(//
|
||||
final int requestCode, //
|
||||
final RemotingCommand request, //
|
||||
final String consumerGroup, //
|
||||
private RemotingCommand callConsumer(
|
||||
final int requestCode,
|
||||
final RemotingCommand request,
|
||||
final String consumerGroup,
|
||||
final String clientId) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
ClientChannelInfo clientChannelInfo = this.brokerController.getConsumerManager().findChannel(consumerGroup, clientId);
|
||||
@@ -1231,8 +1245,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
|
||||
if (clientChannelInfo.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
|
||||
response.setCode(ResponseCode.SYSTEM_ERROR);
|
||||
response.setRemark(String.format("The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", //
|
||||
clientId, //
|
||||
response.setRemark(String.format("The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT",
|
||||
clientId,
|
||||
MQVersion.getVersionDesc(clientChannelInfo.getVersion())));
|
||||
return response;
|
||||
}
|
||||
@@ -1256,7 +1270,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
QueryConsumeQueueRequestHeader requestHeader =
|
||||
(QueryConsumeQueueRequestHeader) request.decodeCommandCustomHeader(QueryConsumeQueueRequestHeader.class);
|
||||
|
||||
|
||||
+2
-1
@@ -46,7 +46,8 @@ public class EndTransactionProcessor implements NettyRequestProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand processRequest(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
final EndTransactionRequestHeader requestHeader =
|
||||
(EndTransactionRequestHeader) request.decodeCommandCustomHeader(EndTransactionRequestHeader.class);
|
||||
|
||||
+22
-19
@@ -76,7 +76,8 @@ public class PullMessageProcessor implements NettyRequestProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemotingCommand processRequest(final ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand processRequest(final ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
return this.processRequest(ctx.channel(), request, true);
|
||||
}
|
||||
|
||||
@@ -138,7 +139,7 @@ public class PullMessageProcessor implements NettyRequestProcessor {
|
||||
|
||||
if (requestHeader.getQueueId() < 0 || requestHeader.getQueueId() >= topicConfig.getReadQueueNums()) {
|
||||
String errorInfo = String.format("queueId[%d] is illegal, topic:[%s] topicConfig.readQueueNums:[%d] consumer:[%s]",
|
||||
requestHeader.getQueueId(), requestHeader.getTopic(), topicConfig.getReadQueueNums(), channel.remoteAddress());
|
||||
requestHeader.getQueueId(), requestHeader.getTopic(), topicConfig.getReadQueueNums(), channel.remoteAddress());
|
||||
log.warn(errorInfo);
|
||||
response.setCode(ResponseCode.SYSTEM_ERROR);
|
||||
response.setRemark(errorInfo);
|
||||
@@ -160,7 +161,7 @@ public class PullMessageProcessor implements NettyRequestProcessor {
|
||||
assert consumerFilterData != null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Parse the consumer's subscription[{}] failed, group: {}", requestHeader.getSubscription(), //
|
||||
log.warn("Parse the consumer's subscription[{}] failed, group: {}", requestHeader.getSubscription(),
|
||||
requestHeader.getConsumerGroup());
|
||||
response.setCode(ResponseCode.SUBSCRIPTION_PARSE_FAILED);
|
||||
response.setRemark("parse the consumer's subscription failed");
|
||||
@@ -176,7 +177,7 @@ public class PullMessageProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
if (!subscriptionGroupConfig.isConsumeBroadcastEnable() //
|
||||
if (!subscriptionGroupConfig.isConsumeBroadcastEnable()
|
||||
&& consumerGroupInfo.getMessageModel() == MessageModel.BROADCASTING) {
|
||||
response.setCode(ResponseCode.NO_PERMISSION);
|
||||
response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] can not consume by broadcast way");
|
||||
@@ -285,12 +286,12 @@ public class PullMessageProcessor implements NettyRequestProcessor {
|
||||
response.setCode(ResponseCode.PULL_OFFSET_MOVED);
|
||||
|
||||
// XXX: warn and notify me
|
||||
log.info("the broker store no queue data, fix the request offset {} to {}, Topic: {} QueueId: {} Consumer Group: {}", //
|
||||
requestHeader.getQueueOffset(), //
|
||||
getMessageResult.getNextBeginOffset(), //
|
||||
requestHeader.getTopic(), //
|
||||
requestHeader.getQueueId(), //
|
||||
requestHeader.getConsumerGroup()//
|
||||
log.info("the broker store no queue data, fix the request offset {} to {}, Topic: {} QueueId: {} Consumer Group: {}",
|
||||
requestHeader.getQueueOffset(),
|
||||
getMessageResult.getNextBeginOffset(),
|
||||
requestHeader.getTopic(),
|
||||
requestHeader.getQueueId(),
|
||||
requestHeader.getConsumerGroup()
|
||||
);
|
||||
} else {
|
||||
response.setCode(ResponseCode.PULL_NOT_FOUND);
|
||||
@@ -314,8 +315,8 @@ public class PullMessageProcessor implements NettyRequestProcessor {
|
||||
case OFFSET_TOO_SMALL:
|
||||
response.setCode(ResponseCode.PULL_OFFSET_MOVED);
|
||||
log.info("the request offset too small. group={}, topic={}, requestOffset={}, brokerMinOffset={}, clientIp={}",
|
||||
requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueOffset(),
|
||||
getMessageResult.getMinOffset(), channel.remoteAddress());
|
||||
requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueOffset(),
|
||||
getMessageResult.getMinOffset(), channel.remoteAddress());
|
||||
break;
|
||||
default:
|
||||
assert false;
|
||||
@@ -437,15 +438,15 @@ public class PullMessageProcessor implements NettyRequestProcessor {
|
||||
event.setOffsetNew(getMessageResult.getNextBeginOffset());
|
||||
this.generateOffsetMovedEvent(event);
|
||||
log.warn(
|
||||
"PULL_OFFSET_MOVED:correction offset. topic={}, groupId={}, requestOffset={}, newOffset={}, suggestBrokerId={}",
|
||||
requestHeader.getTopic(), requestHeader.getConsumerGroup(), event.getOffsetRequest(), event.getOffsetNew(),
|
||||
responseHeader.getSuggestWhichBrokerId());
|
||||
"PULL_OFFSET_MOVED:correction offset. topic={}, groupId={}, requestOffset={}, newOffset={}, suggestBrokerId={}",
|
||||
requestHeader.getTopic(), requestHeader.getConsumerGroup(), event.getOffsetRequest(), event.getOffsetNew(),
|
||||
responseHeader.getSuggestWhichBrokerId());
|
||||
} else {
|
||||
responseHeader.setSuggestWhichBrokerId(subscriptionGroupConfig.getBrokerId());
|
||||
response.setCode(ResponseCode.PULL_RETRY_IMMEDIATELY);
|
||||
log.warn("PULL_OFFSET_MOVED:none correction. topic={}, groupId={}, requestOffset={}, suggestBrokerId={}",
|
||||
requestHeader.getTopic(), requestHeader.getConsumerGroup(), requestHeader.getQueueOffset(),
|
||||
responseHeader.getSuggestWhichBrokerId());
|
||||
requestHeader.getTopic(), requestHeader.getConsumerGroup(), requestHeader.getQueueOffset(),
|
||||
responseHeader.getSuggestWhichBrokerId());
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -483,7 +484,8 @@ public class PullMessageProcessor implements NettyRequestProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic, final int queueId) {
|
||||
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic,
|
||||
final int queueId) {
|
||||
final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize());
|
||||
|
||||
long storeTimestamp = 0;
|
||||
@@ -528,7 +530,8 @@ public class PullMessageProcessor implements NettyRequestProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public void executeRequestWhenWakeup(final Channel channel, final RemotingCommand request) throws RemotingCommandException {
|
||||
public void executeRequestWhenWakeup(final Channel channel,
|
||||
final RemotingCommand request) throws RemotingCommandException {
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
+27
-28
@@ -60,7 +60,8 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand processRequest(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
SendMessageContext mqtraceContext;
|
||||
switch (request.getCode()) {
|
||||
case RequestCode.CONSUMER_SEND_MSG_BACK:
|
||||
@@ -139,9 +140,9 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
topicSysFlag = TopicSysFlag.buildSysFlag(false, true);
|
||||
}
|
||||
|
||||
TopicConfig topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(//
|
||||
newTopic, //
|
||||
subscriptionGroupConfig.getRetryQueueNums(), //
|
||||
TopicConfig topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(
|
||||
newTopic,
|
||||
subscriptionGroupConfig.getRetryQueueNums(),
|
||||
PermName.PERM_WRITE | PermName.PERM_READ, topicSysFlag);
|
||||
if (null == topicConfig) {
|
||||
response.setCode(ResponseCode.SYSTEM_ERROR);
|
||||
@@ -175,13 +176,13 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
maxReconsumeTimes = requestHeader.getMaxReconsumeTimes();
|
||||
}
|
||||
|
||||
if (msgExt.getReconsumeTimes() >= maxReconsumeTimes//
|
||||
if (msgExt.getReconsumeTimes() >= maxReconsumeTimes
|
||||
|| delayLevel < 0) {
|
||||
newTopic = MixAll.getDLQTopic(requestHeader.getGroup());
|
||||
queueIdInt = Math.abs(this.random.nextInt() % 99999999) % DLQ_NUMS_PER_GROUP;
|
||||
|
||||
topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, //
|
||||
DLQ_NUMS_PER_GROUP, //
|
||||
topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic,
|
||||
DLQ_NUMS_PER_GROUP,
|
||||
PermName.PERM_WRITE, 0
|
||||
);
|
||||
if (null == topicConfig) {
|
||||
@@ -245,8 +246,8 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
private boolean handleRetryAndDLQ(SendMessageRequestHeader requestHeader, RemotingCommand response, RemotingCommand request,
|
||||
private boolean handleRetryAndDLQ(SendMessageRequestHeader requestHeader, RemotingCommand response,
|
||||
RemotingCommand request,
|
||||
MessageExt msg, TopicConfig topicConfig) {
|
||||
String newTopic = requestHeader.getTopic();
|
||||
if (null != newTopic && newTopic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
|
||||
@@ -268,8 +269,8 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
if (reconsumeTimes >= maxReconsumeTimes) {
|
||||
newTopic = MixAll.getDLQTopic(groupName);
|
||||
int queueIdInt = Math.abs(this.random.nextInt() % 99999999) % DLQ_NUMS_PER_GROUP;
|
||||
topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, //
|
||||
DLQ_NUMS_PER_GROUP, //
|
||||
topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic,
|
||||
DLQ_NUMS_PER_GROUP,
|
||||
PermName.PERM_WRITE, 0
|
||||
);
|
||||
msg.setTopic(newTopic);
|
||||
@@ -289,9 +290,9 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
return true;
|
||||
}
|
||||
|
||||
private RemotingCommand sendMessage(final ChannelHandlerContext ctx, //
|
||||
final RemotingCommand request, //
|
||||
final SendMessageContext sendMessageContext, //
|
||||
private RemotingCommand sendMessage(final ChannelHandlerContext ctx,
|
||||
final RemotingCommand request,
|
||||
final SendMessageContext sendMessageContext,
|
||||
final SendMessageRequestHeader requestHeader) throws RemotingCommandException {
|
||||
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class);
|
||||
@@ -319,8 +320,6 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
|
||||
final byte[] body = request.getBody();
|
||||
|
||||
|
||||
|
||||
int queueIdInt = requestHeader.getQueueId();
|
||||
TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(requestHeader.getTopic());
|
||||
|
||||
@@ -361,13 +360,14 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
|
||||
}
|
||||
|
||||
|
||||
private RemotingCommand handlePutMessageResult(PutMessageResult putMessageResult, RemotingCommand response, RemotingCommand request, MessageExt msg,
|
||||
SendMessageResponseHeader responseHeader, SendMessageContext sendMessageContext, ChannelHandlerContext ctx, int queueIdInt) {
|
||||
private RemotingCommand handlePutMessageResult(PutMessageResult putMessageResult, RemotingCommand response,
|
||||
RemotingCommand request, MessageExt msg,
|
||||
SendMessageResponseHeader responseHeader, SendMessageContext sendMessageContext, ChannelHandlerContext ctx,
|
||||
int queueIdInt) {
|
||||
if (putMessageResult == null) {
|
||||
response.setCode(ResponseCode.SYSTEM_ERROR);
|
||||
response.setRemark("store putMessage return null");
|
||||
return response;
|
||||
return response;
|
||||
}
|
||||
boolean sendOK = false;
|
||||
|
||||
@@ -462,17 +462,17 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
sendMessageContext.setCommercialOwner(owner);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
return response;
|
||||
}
|
||||
private RemotingCommand sendBatchMessage(final ChannelHandlerContext ctx, //
|
||||
final RemotingCommand request, //
|
||||
final SendMessageContext sendMessageContext, //
|
||||
final SendMessageRequestHeader requestHeader) throws RemotingCommandException {
|
||||
|
||||
private RemotingCommand sendBatchMessage(final ChannelHandlerContext ctx,
|
||||
final RemotingCommand request,
|
||||
final SendMessageContext sendMessageContext,
|
||||
final SendMessageRequestHeader requestHeader) throws RemotingCommandException {
|
||||
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class);
|
||||
final SendMessageResponseHeader responseHeader = (SendMessageResponseHeader) response.readCustomHeader();
|
||||
|
||||
|
||||
response.setOpaque(request.getOpaque());
|
||||
|
||||
response.addExtField(MessageConst.PROPERTY_MSG_REGION, this.brokerController.getBrokerConfig().getRegionId());
|
||||
@@ -493,7 +493,6 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
int queueIdInt = requestHeader.getQueueId();
|
||||
TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(requestHeader.getTopic());
|
||||
|
||||
@@ -509,7 +508,7 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement
|
||||
|
||||
if (requestHeader.getTopic() != null && requestHeader.getTopic().startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
|
||||
response.setCode(ResponseCode.MESSAGE_ILLEGAL);
|
||||
response.setRemark("batch request does not support retry group " + requestHeader.getTopic());
|
||||
response.setRemark("batch request does not support retry group " + requestHeader.getTopic());
|
||||
return response;
|
||||
}
|
||||
MessageExtBatch messageExtBatch = new MessageExtBatch();
|
||||
|
||||
+1
-1
@@ -143,7 +143,7 @@ public class SubscriptionGroupManager extends ConfigManager {
|
||||
@Override
|
||||
public String configFilePath() {
|
||||
return BrokerPathConfigHelper.getSubscriptionGroupPath(this.brokerController.getMessageStoreConfig()
|
||||
.getStorePathRootDir());
|
||||
.getStorePathRootDir());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -272,7 +272,7 @@ public class TopicConfigManager extends ConfigManager {
|
||||
}
|
||||
|
||||
log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
|
||||
topicConfig.getTopicSysFlag());
|
||||
topicConfig.getTopicSysFlag());
|
||||
|
||||
this.topicConfigTable.put(topic, topicConfig);
|
||||
|
||||
@@ -292,7 +292,7 @@ public class TopicConfigManager extends ConfigManager {
|
||||
}
|
||||
|
||||
log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
|
||||
topicConfig.getTopicSysFlag());
|
||||
topicConfig.getTopicSysFlag());
|
||||
|
||||
this.topicConfigTable.put(topic, topicConfig);
|
||||
|
||||
@@ -384,7 +384,7 @@ public class TopicConfigManager extends ConfigManager {
|
||||
@Override
|
||||
public String configFilePath() {
|
||||
return BrokerPathConfigHelper.getTopicConfigPath(this.brokerController.getMessageStoreConfig()
|
||||
.getStorePathRootDir());
|
||||
.getStorePathRootDir());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,11 +18,15 @@
|
||||
package org.apache.rocketmq.broker;
|
||||
|
||||
import org.apache.rocketmq.common.BrokerConfig;
|
||||
import org.apache.rocketmq.common.UtilAll;
|
||||
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
|
||||
import org.apache.rocketmq.remoting.netty.NettyServerConfig;
|
||||
import org.apache.rocketmq.store.config.MessageStoreConfig;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BrokerControllerTest {
|
||||
@@ -33,15 +37,18 @@ public class BrokerControllerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testBrokerRestart() throws Exception {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
BrokerController brokerController = new BrokerController(//
|
||||
new BrokerConfig(), //
|
||||
new NettyServerConfig(), //
|
||||
new NettyClientConfig(), //
|
||||
new MessageStoreConfig());
|
||||
assertThat(brokerController.initialize());
|
||||
brokerController.start();
|
||||
brokerController.shutdown();
|
||||
}
|
||||
BrokerController brokerController = new BrokerController(
|
||||
new BrokerConfig(),
|
||||
new NettyServerConfig(),
|
||||
new NettyClientConfig(),
|
||||
new MessageStoreConfig());
|
||||
assertThat(brokerController.initialize());
|
||||
brokerController.start();
|
||||
brokerController.shutdown();
|
||||
}
|
||||
|
||||
@After
|
||||
public void destory() {
|
||||
UtilAll.deleteFile(new File(new MessageStoreConfig().getStorePathRootDir()));
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -51,7 +51,6 @@ public class CommitLogDispatcherCalcBitMapTest {
|
||||
ConsumerFilterData nullBloomData = filterManager.get("topic0", "CID_1");
|
||||
nullBloomData.setBloomFilterData(null);
|
||||
|
||||
|
||||
CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig,
|
||||
filterManager);
|
||||
|
||||
|
||||
+3
-17
@@ -17,6 +17,7 @@
|
||||
|
||||
package org.apache.rocketmq.broker.filter;
|
||||
|
||||
import org.apache.rocketmq.common.UtilAll;
|
||||
import org.apache.rocketmq.common.filter.ExpressionType;
|
||||
import org.apache.rocketmq.common.filter.FilterAPI;
|
||||
import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData;
|
||||
@@ -232,7 +233,7 @@ public class ConsumerFilterManagerTest {
|
||||
assertThat(filterData.isDead()).isTrue();
|
||||
assertThat(filterData.getCompiledExpression()).isNotNull();
|
||||
} finally {
|
||||
deleteDirectory("./unit_test");
|
||||
UtilAll.deleteFile(new File("./unit_test"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,23 +270,8 @@ public class ConsumerFilterManagerTest {
|
||||
|
||||
assertThat(topicData).isNullOrEmpty();
|
||||
} finally {
|
||||
deleteDirectory("./unit_test");
|
||||
UtilAll.deleteFile(new File("./unit_test"));
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteDirectory(String rootPath) {
|
||||
File file = new File(rootPath);
|
||||
deleteFile(file);
|
||||
}
|
||||
|
||||
protected void deleteFile(File file) {
|
||||
File[] subFiles = file.listFiles();
|
||||
if (subFiles != null) {
|
||||
for (File sub : subFiles) {
|
||||
deleteFile(sub);
|
||||
}
|
||||
}
|
||||
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
+137
-157
@@ -18,6 +18,7 @@
|
||||
package org.apache.rocketmq.broker.filter;
|
||||
|
||||
import org.apache.rocketmq.common.BrokerConfig;
|
||||
import org.apache.rocketmq.common.UtilAll;
|
||||
import org.apache.rocketmq.common.filter.ExpressionType;
|
||||
import org.apache.rocketmq.common.message.MessageDecoder;
|
||||
import org.apache.rocketmq.common.message.MessageExt;
|
||||
@@ -32,6 +33,8 @@ import org.apache.rocketmq.store.MessageExtBrokerInner;
|
||||
import org.apache.rocketmq.store.PutMessageResult;
|
||||
import org.apache.rocketmq.store.config.MessageStoreConfig;
|
||||
import org.apache.rocketmq.store.stats.BrokerStatsManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@@ -62,6 +65,14 @@ public class MessageStoreWithFilterTest {
|
||||
|
||||
private static SocketAddress StoreHost;
|
||||
|
||||
private DefaultMessageStore master;
|
||||
|
||||
private ConsumerFilterManager filterManager;
|
||||
|
||||
private int topicCount = 3;
|
||||
|
||||
private int msgPerTopic = 30;
|
||||
|
||||
static {
|
||||
try {
|
||||
StoreHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123);
|
||||
@@ -75,6 +86,24 @@ public class MessageStoreWithFilterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic);
|
||||
try {
|
||||
master = gen(filterManager);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertThat(true).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
master.shutdown();
|
||||
master.destroy();
|
||||
UtilAll.deleteFile(new File(storePath));
|
||||
}
|
||||
|
||||
public MessageExtBrokerInner buildMessage() {
|
||||
MessageExtBrokerInner msg = new MessageExtBrokerInner();
|
||||
msg.setTopic(topic);
|
||||
@@ -96,7 +125,7 @@ public class MessageStoreWithFilterTest {
|
||||
}
|
||||
|
||||
public MessageStoreConfig buildStoreConfig(int commitLogFileSize, int cqFileSize,
|
||||
boolean enableCqExt, int cqExtFileSize) {
|
||||
boolean enableCqExt, int cqExtFileSize) {
|
||||
MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
|
||||
messageStoreConfig.setMapedFileSizeCommitLog(commitLogFileSize);
|
||||
messageStoreConfig.setMapedFileSizeConsumeQueue(cqFileSize);
|
||||
@@ -126,7 +155,7 @@ public class MessageStoreWithFilterTest {
|
||||
new MessageArrivingListener() {
|
||||
@Override
|
||||
public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
|
||||
long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
|
||||
long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
|
||||
// System.out.println(String.format("Msg coming: %s, %d, %d, %d",
|
||||
// topic, queueId, logicOffset, tagsCode));
|
||||
}
|
||||
@@ -153,7 +182,8 @@ public class MessageStoreWithFilterTest {
|
||||
return master;
|
||||
}
|
||||
|
||||
protected List<MessageExtBrokerInner> putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception {
|
||||
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;
|
||||
@@ -174,22 +204,6 @@ public class MessageStoreWithFilterTest {
|
||||
return msgs;
|
||||
}
|
||||
|
||||
protected void deleteDirectory(String rootPath) {
|
||||
File file = new File(rootPath);
|
||||
deleteFile(file);
|
||||
}
|
||||
|
||||
protected void deleteFile(File file) {
|
||||
File[] subFiles = file.listFiles();
|
||||
if (subFiles != null) {
|
||||
for (File sub : subFiles) {
|
||||
deleteFile(sub);
|
||||
}
|
||||
}
|
||||
|
||||
file.delete();
|
||||
}
|
||||
|
||||
protected List<MessageExtBrokerInner> filtered(List<MessageExtBrokerInner> msgs, ConsumerFilterData filterData) {
|
||||
List<MessageExtBrokerInner> filteredMsgs = new ArrayList<MessageExtBrokerInner>();
|
||||
|
||||
@@ -216,177 +230,143 @@ public class MessageStoreWithFilterTest {
|
||||
|
||||
@Test
|
||||
public void testGetMessage_withFilterBitMapAndConsumerChanged() {
|
||||
int topicCount = 10, msgPerTopic = 10;
|
||||
ConsumerFilterManager filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic);
|
||||
|
||||
DefaultMessageStore master = null;
|
||||
List<MessageExtBrokerInner> msgs = null;
|
||||
try {
|
||||
master = gen(filterManager);
|
||||
msgs = putMsg(master, topicCount, msgPerTopic);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertThat(true).isFalse();
|
||||
}
|
||||
|
||||
// sleep to wait for consume queue has been constructed.
|
||||
try {
|
||||
List<MessageExtBrokerInner> msgs = null;
|
||||
Thread.sleep(200);
|
||||
} 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 {
|
||||
msgs = putMsg(master, topicCount, msgPerTopic);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertThat(true).isFalse();
|
||||
}
|
||||
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));
|
||||
|
||||
// sleep to wait for consume queue has been constructed.
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
assertThat(true).isFalse();
|
||||
assertThat(normalGetResult).isNotNull();
|
||||
assertThat(normalGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size());
|
||||
} finally {
|
||||
normalGetResult.release();
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMessage_withFilterBitMap() {
|
||||
int topicCount = 10, msgPerTopic = 500;
|
||||
ConsumerFilterManager filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic);
|
||||
|
||||
DefaultMessageStore master = null;
|
||||
List<MessageExtBrokerInner> msgs = null;
|
||||
try {
|
||||
master = gen(filterManager);
|
||||
msgs = putMsg(master, topicCount, msgPerTopic);
|
||||
// sleep to wait for consume queue has been constructed.
|
||||
Thread.sleep(200);
|
||||
} 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 i = 0; i < topicCount; i++) {
|
||||
String realTopic = topic + i;
|
||||
for (int j = 0; j < msgPerTopic; j++) {
|
||||
String group = "CID_" + j;
|
||||
|
||||
for (int j = 0; j < msgPerTopic; j++) {
|
||||
String group = "CID_" + j;
|
||||
ConsumerFilterData filterData = filterManager.get(realTopic, group);
|
||||
assertThat(filterData).isNotNull();
|
||||
|
||||
ConsumerFilterData filterData = filterManager.get(realTopic, group);
|
||||
assertThat(filterData).isNotNull();
|
||||
List<MessageExtBrokerInner> filteredMsgs = filtered(msgs, filterData);
|
||||
|
||||
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());
|
||||
|
||||
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());
|
||||
|
||||
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();
|
||||
|
||||
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();
|
||||
Object evlRet = null;
|
||||
try {
|
||||
evlRet = filterData.getCompiledExpression().evaluate(new MessageEvaluationContext(messageExt.getProperties()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertThat(true).isFalse();
|
||||
}
|
||||
} finally {
|
||||
getMessageResult.release();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -142,15 +142,18 @@ public class PullMessageProcessorTest {
|
||||
List<ConsumeMessageHook> consumeMessageHookList = new ArrayList<>();
|
||||
final ConsumeMessageContext[] messageContext = new ConsumeMessageContext[1];
|
||||
ConsumeMessageHook consumeMessageHook = new ConsumeMessageHook() {
|
||||
@Override public String hookName() {
|
||||
@Override
|
||||
public String hookName() {
|
||||
return "TestHook";
|
||||
}
|
||||
|
||||
@Override public void consumeMessageBefore(ConsumeMessageContext context) {
|
||||
@Override
|
||||
public void consumeMessageBefore(ConsumeMessageContext context) {
|
||||
messageContext[0] = context;
|
||||
}
|
||||
|
||||
@Override public void consumeMessageAfter(ConsumeMessageContext context) {
|
||||
@Override
|
||||
public void consumeMessageAfter(ConsumeMessageContext context) {
|
||||
}
|
||||
};
|
||||
consumeMessageHookList.add(consumeMessageHook);
|
||||
|
||||
+8
-5
@@ -94,15 +94,18 @@ public class SendMessageProcessorTest {
|
||||
List<SendMessageHook> sendMessageHookList = new ArrayList<>();
|
||||
final SendMessageContext[] sendMessageContext = new SendMessageContext[1];
|
||||
SendMessageHook sendMessageHook = new SendMessageHook() {
|
||||
@Override public String hookName() {
|
||||
@Override
|
||||
public String hookName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public void sendMessageBefore(SendMessageContext context) {
|
||||
@Override
|
||||
public void sendMessageBefore(SendMessageContext context) {
|
||||
sendMessageContext[0] = context;
|
||||
}
|
||||
|
||||
@Override public void sendMessageAfter(SendMessageContext context) {
|
||||
@Override
|
||||
public void sendMessageAfter(SendMessageContext context) {
|
||||
|
||||
}
|
||||
};
|
||||
@@ -115,7 +118,6 @@ public class SendMessageProcessorTest {
|
||||
assertThat(sendMessageContext[0].getProducerGroup()).isEqualTo(group);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testProcessRequest_FlushTimeOut() throws RemotingCommandException {
|
||||
when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult(PutMessageStatus.FLUSH_DISK_TIMEOUT, new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR)));
|
||||
@@ -210,7 +212,8 @@ public class SendMessageProcessorTest {
|
||||
final RemotingCommand request = createSendMsgCommand(RequestCode.SEND_MESSAGE);
|
||||
final RemotingCommand[] response = new RemotingCommand[1];
|
||||
doAnswer(new Answer() {
|
||||
@Override public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
response[0] = invocation.getArgument(0);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
<configuration>
|
||||
|
||||
<appender name="DefaultAppender" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<append>true</append>
|
||||
<encoder>
|
||||
<pattern>%d{yyy-MM-dd HH\:mm\:ss,GMT+8} %p %t - %m%n</pattern>
|
||||
<charset class="java.nio.charset.Charset">UTF-8</charset>
|
||||
|
||||
@@ -32,7 +32,6 @@ public interface MQAdmin {
|
||||
* @param key accesskey
|
||||
* @param newTopic topic name
|
||||
* @param queueNum topic's queue number
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void createTopic(final String key, final String newTopic, final int queueNum)
|
||||
throws MQClientException;
|
||||
@@ -44,7 +43,6 @@ public interface MQAdmin {
|
||||
* @param newTopic topic name
|
||||
* @param queueNum topic's queue number
|
||||
* @param topicSysFlag topic system flag
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void createTopic(String key, String newTopic, int queueNum, int topicSysFlag)
|
||||
throws MQClientException;
|
||||
@@ -56,7 +54,6 @@ public interface MQAdmin {
|
||||
* @param mq Instance of MessageQueue
|
||||
* @param timestamp from when in milliseconds.
|
||||
* @return offset
|
||||
* @throws MQClientException
|
||||
*/
|
||||
long searchOffset(final MessageQueue mq, final long timestamp) throws MQClientException;
|
||||
|
||||
@@ -65,7 +62,6 @@ public interface MQAdmin {
|
||||
*
|
||||
* @param mq Instance of MessageQueue
|
||||
* @return the max offset
|
||||
* @throws MQClientException
|
||||
*/
|
||||
long maxOffset(final MessageQueue mq) throws MQClientException;
|
||||
|
||||
@@ -74,7 +70,6 @@ public interface MQAdmin {
|
||||
*
|
||||
* @param mq Instance of MessageQueue
|
||||
* @return the minimum offset
|
||||
* @throws MQClientException
|
||||
*/
|
||||
long minOffset(final MessageQueue mq) throws MQClientException;
|
||||
|
||||
@@ -83,7 +78,6 @@ public interface MQAdmin {
|
||||
*
|
||||
* @param mq Instance of MessageQueue
|
||||
* @return the time in microseconds
|
||||
* @throws MQClientException
|
||||
*/
|
||||
long earliestMsgStoreTime(final MessageQueue mq) throws MQClientException;
|
||||
|
||||
@@ -92,10 +86,6 @@ public interface MQAdmin {
|
||||
*
|
||||
* @param offsetMsgId message id
|
||||
* @return message
|
||||
* @throws InterruptedException
|
||||
* @throws MQBrokerException
|
||||
* @throws RemotingException
|
||||
* @throws MQClientException
|
||||
*/
|
||||
MessageExt viewMessage(final String offsetMsgId) throws RemotingException, MQBrokerException,
|
||||
InterruptedException, MQClientException;
|
||||
@@ -109,21 +99,14 @@ public interface MQAdmin {
|
||||
* @param begin from when
|
||||
* @param end to when
|
||||
* @return Instance of QueryResult
|
||||
* @throws MQClientException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
QueryResult queryMessage(final String topic, final String key, final int maxNum, final long begin,
|
||||
final long end) throws MQClientException, InterruptedException;
|
||||
|
||||
/**
|
||||
* @param topic
|
||||
* @param msgId
|
||||
* @return The {@code MessageExt} of given msgId
|
||||
* @throws RemotingException
|
||||
* @throws MQBrokerException
|
||||
* @throws InterruptedException
|
||||
* @throws MQClientException
|
||||
*/
|
||||
MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException;
|
||||
MessageExt viewMessage(String topic,
|
||||
String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException;
|
||||
|
||||
}
|
||||
@@ -41,7 +41,6 @@ public class MQHelper {
|
||||
* @param consumerGroup consumer group
|
||||
* @param topic topic
|
||||
* @param timestamp time
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void resetOffsetByTimestamp(
|
||||
final MessageModel messageModel,
|
||||
|
||||
@@ -35,8 +35,6 @@ public class Validators {
|
||||
public static final int CHARACTER_MAX_LENGTH = 255;
|
||||
|
||||
/**
|
||||
* @param origin
|
||||
* @param patternStr
|
||||
* @return The resulting {@code String}
|
||||
*/
|
||||
public static String getGroupWithRegularExpression(String origin, String patternStr) {
|
||||
@@ -50,9 +48,6 @@ public class Validators {
|
||||
|
||||
/**
|
||||
* Validate group
|
||||
*
|
||||
* @param group
|
||||
* @throws MQClientException
|
||||
*/
|
||||
public static void checkGroup(String group) throws MQClientException {
|
||||
if (UtilAll.isBlank(group)) {
|
||||
@@ -69,8 +64,6 @@ public class Validators {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param origin
|
||||
* @param pattern
|
||||
* @return <tt>true</tt> if, and only if, the entire origin sequence matches this matcher's pattern
|
||||
*/
|
||||
public static boolean regularExpressionMatcher(String origin, Pattern pattern) {
|
||||
@@ -83,10 +76,6 @@ public class Validators {
|
||||
|
||||
/**
|
||||
* Validate message
|
||||
*
|
||||
* @param msg
|
||||
* @param defaultMQProducer
|
||||
* @throws MQClientException
|
||||
*/
|
||||
public static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer)
|
||||
throws MQClientException {
|
||||
@@ -113,9 +102,6 @@ public class Validators {
|
||||
|
||||
/**
|
||||
* Validate topic
|
||||
*
|
||||
* @param topic
|
||||
* @throws MQClientException
|
||||
*/
|
||||
public static void checkTopic(String topic) throws MQClientException {
|
||||
if (UtilAll.isBlank(topic)) {
|
||||
|
||||
@@ -264,7 +264,8 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pull(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback, long timeout)
|
||||
public void pull(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback,
|
||||
long timeout)
|
||||
throws MQClientException, RemotingException, InterruptedException {
|
||||
this.defaultMQPullConsumerImpl.pull(mq, subExpression, offset, maxNums, pullCallback, timeout);
|
||||
}
|
||||
@@ -276,7 +277,8 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback)
|
||||
public void pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums,
|
||||
PullCallback pullCallback)
|
||||
throws MQClientException, RemotingException, InterruptedException {
|
||||
this.defaultMQPullConsumerImpl.pullBlockIfNotFound(mq, subExpression, offset, maxNums, pullCallback);
|
||||
}
|
||||
@@ -297,7 +299,8 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageExt viewMessage(String topic, String uniqKey) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
public MessageExt viewMessage(String topic,
|
||||
String uniqKey) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
try {
|
||||
MessageDecoder.decodeMessageId(uniqKey);
|
||||
return this.viewMessage(uniqKey);
|
||||
|
||||
+40
-33
@@ -51,7 +51,7 @@ import org.apache.rocketmq.remoting.exception.RemotingException;
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <strong>Thread Safety:</strong> After initialization, the instance can be regarded as thread-safe.
|
||||
* <strong>Thread Safety:</strong> After initialization, the instance can be regarded as thread-safe.
|
||||
* </p>
|
||||
*/
|
||||
public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsumer {
|
||||
@@ -90,29 +90,29 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
*
|
||||
* There are three consuming points:
|
||||
* <ul>
|
||||
* <li>
|
||||
* <code>CONSUME_FROM_LAST_OFFSET</code>: 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:
|
||||
* <ol>
|
||||
* <li>
|
||||
* if the consumer group is created so recently that the earliest message being subscribed has yet
|
||||
* expired, which means the consumer group represents a lately launched business, consuming will
|
||||
* start from the very beginning;
|
||||
* </li>
|
||||
* <li>
|
||||
* if the earliest message being subscribed has expired, consuming will start from the latest
|
||||
* messages, meaning messages born prior to the booting timestamp would be ignored.
|
||||
* </li>
|
||||
* </ol>
|
||||
* </li>
|
||||
* <li>
|
||||
* <code>CONSUME_FROM_FIRST_OFFSET</code>: Consumer client will start from earliest messages available.
|
||||
* </li>
|
||||
* <li>
|
||||
* <code>CONSUME_FROM_TIMESTAMP</code>: Consumer client will start from specified timestamp, which means
|
||||
* messages born prior to {@link #consumeTimestamp} will be ignored
|
||||
* </li>
|
||||
* <li>
|
||||
* <code>CONSUME_FROM_LAST_OFFSET</code>: 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:
|
||||
* <ol>
|
||||
* <li>
|
||||
* if the consumer group is created so recently that the earliest message being subscribed has yet
|
||||
* expired, which means the consumer group represents a lately launched business, consuming will
|
||||
* start from the very beginning;
|
||||
* </li>
|
||||
* <li>
|
||||
* if the earliest message being subscribed has expired, consuming will start from the latest
|
||||
* messages, meaning messages born prior to the booting timestamp would be ignored.
|
||||
* </li>
|
||||
* </ol>
|
||||
* </li>
|
||||
* <li>
|
||||
* <code>CONSUME_FROM_FIRST_OFFSET</code>: Consumer client will start from earliest messages available.
|
||||
* </li>
|
||||
* <li>
|
||||
* <code>CONSUME_FROM_TIMESTAMP</code>: Consumer client will start from specified timestamp, which means
|
||||
* messages born prior to {@link #consumeTimestamp} will be ignored
|
||||
* </li>
|
||||
* </ul>
|
||||
*/
|
||||
private ConsumeFromWhere consumeFromWhere = ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET;
|
||||
@@ -223,11 +223,13 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
|
||||
/**
|
||||
* Constructor specifying consumer group, RPC hook and message queue allocating algorithm.
|
||||
*
|
||||
* @param consumerGroup Consume queue.
|
||||
* @param rpcHook RPC hook to execute before each remoting command.
|
||||
* @param allocateMessageQueueStrategy message queue allocating algorithm.
|
||||
*/
|
||||
public DefaultMQPushConsumer(final String consumerGroup, RPCHook rpcHook, AllocateMessageQueueStrategy allocateMessageQueueStrategy) {
|
||||
public DefaultMQPushConsumer(final String consumerGroup, RPCHook rpcHook,
|
||||
AllocateMessageQueueStrategy allocateMessageQueueStrategy) {
|
||||
this.consumerGroup = consumerGroup;
|
||||
this.allocateMessageQueueStrategy = allocateMessageQueueStrategy;
|
||||
defaultMQPushConsumerImpl = new DefaultMQPushConsumerImpl(this, rpcHook);
|
||||
@@ -235,6 +237,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
|
||||
/**
|
||||
* Constructor specifying RPC hook.
|
||||
*
|
||||
* @param rpcHook RPC hook to execute before each remoting command.
|
||||
*/
|
||||
public DefaultMQPushConsumer(RPCHook rpcHook) {
|
||||
@@ -243,6 +246,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
|
||||
/**
|
||||
* Constructor specifying consumer group.
|
||||
*
|
||||
* @param consumerGroup Consumer group.
|
||||
*/
|
||||
public DefaultMQPushConsumer(final String consumerGroup) {
|
||||
@@ -280,7 +284,8 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageExt viewMessage(String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
public MessageExt viewMessage(
|
||||
String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
return this.defaultMQPushConsumerImpl.viewMessage(offsetMsgId);
|
||||
}
|
||||
|
||||
@@ -291,7 +296,8 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
public MessageExt viewMessage(String topic,
|
||||
String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
try {
|
||||
MessageDecoder.decodeMessageId(msgId);
|
||||
return this.viewMessage(msgId);
|
||||
@@ -411,6 +417,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
|
||||
/**
|
||||
* Send message back to broker which will be re-delivered in future.
|
||||
*
|
||||
* @param msg Message to send back.
|
||||
* @param delayLevel delay level.
|
||||
* @throws RemotingException if there is any network-tier error.
|
||||
@@ -449,6 +456,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
|
||||
/**
|
||||
* This method gets internal infrastructure readily to serve. Instances must call this method after configuration.
|
||||
*
|
||||
* @throws MQClientException if there is any client error.
|
||||
*/
|
||||
@Override
|
||||
@@ -498,7 +506,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
*
|
||||
* @param topic topic to subscribe.
|
||||
* @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3" <br>
|
||||
* if null or * expression,meaning subscribe all
|
||||
* if null or * expression,meaning subscribe all
|
||||
* @throws MQClientException if there is any client error.
|
||||
*/
|
||||
@Override
|
||||
@@ -508,10 +516,10 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
|
||||
/**
|
||||
* Subscribe a topic to consuming subscription.
|
||||
*
|
||||
* @param topic topic to consume.
|
||||
* @param fullClassName full class name,must extend org.apache.rocketmq.common.filter. MessageFilter
|
||||
* @param filterClassSource class source code,used UTF-8 file encoding,must be responsible for your code safety
|
||||
* @throws MQClientException
|
||||
*/
|
||||
@Override
|
||||
public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException {
|
||||
@@ -521,12 +529,10 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
/**
|
||||
* Subscribe a topic by message selector.
|
||||
*
|
||||
* @see org.apache.rocketmq.client.consumer.MessageSelector#bySql
|
||||
* @see org.apache.rocketmq.client.consumer.MessageSelector#byTag
|
||||
*
|
||||
* @param topic topic to consume.
|
||||
* @param messageSelector {@link org.apache.rocketmq.client.consumer.MessageSelector}
|
||||
* @throws MQClientException
|
||||
* @see org.apache.rocketmq.client.consumer.MessageSelector#bySql
|
||||
* @see org.apache.rocketmq.client.consumer.MessageSelector#byTag
|
||||
*/
|
||||
@Override
|
||||
public void subscribe(final String topic, final MessageSelector messageSelector) throws MQClientException {
|
||||
@@ -535,6 +541,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
|
||||
|
||||
/**
|
||||
* Un-subscribe the specified topic from subscription.
|
||||
*
|
||||
* @param topic message topic
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -30,13 +30,6 @@ import org.apache.rocketmq.remoting.exception.RemotingException;
|
||||
public interface MQConsumer extends MQAdmin {
|
||||
/**
|
||||
* If consuming failure,message will be send back to the brokers,and delay consuming some time
|
||||
*
|
||||
* @param msg
|
||||
* @param delayLevel
|
||||
* @throws InterruptedException
|
||||
* @throws MQBrokerException
|
||||
* @throws RemotingException
|
||||
* @throws MQClientException
|
||||
*/
|
||||
@Deprecated
|
||||
void sendMessageBack(final MessageExt msg, final int delayLevel) throws RemotingException,
|
||||
@@ -44,14 +37,6 @@ public interface MQConsumer extends MQAdmin {
|
||||
|
||||
/**
|
||||
* If consuming failure,message will be send back to the broker,and delay consuming some time
|
||||
*
|
||||
* @param msg
|
||||
* @param delayLevel
|
||||
* @param brokerName
|
||||
* @throws RemotingException
|
||||
* @throws MQBrokerException
|
||||
* @throws InterruptedException
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void sendMessageBack(final MessageExt msg, final int delayLevel, final String brokerName)
|
||||
throws RemotingException, MQBrokerException, InterruptedException, MQClientException;
|
||||
@@ -61,7 +46,6 @@ public interface MQConsumer extends MQAdmin {
|
||||
*
|
||||
* @param topic message topic
|
||||
* @return queue set
|
||||
* @throws MQClientException
|
||||
*/
|
||||
Set<MessageQueue> fetchSubscribeMessageQueues(final String topic) throws MQClientException;
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ import org.apache.rocketmq.remoting.exception.RemotingException;
|
||||
public interface MQPullConsumer extends MQConsumer {
|
||||
/**
|
||||
* Start the consumer
|
||||
*
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void start() throws MQClientException;
|
||||
|
||||
@@ -41,9 +39,6 @@ public interface MQPullConsumer extends MQConsumer {
|
||||
|
||||
/**
|
||||
* Register the message queue listener
|
||||
*
|
||||
* @param topic
|
||||
* @param listener
|
||||
*/
|
||||
void registerMessageQueueListener(final String topic, final MessageQueueListener listener);
|
||||
|
||||
@@ -51,15 +46,12 @@ public interface MQPullConsumer extends MQConsumer {
|
||||
* Pulling the messages,not blocking
|
||||
*
|
||||
* @param mq from which message queue
|
||||
* @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3" <br> if null or * expression,meaning subscribe
|
||||
* @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3" <br> if
|
||||
* null or * expression,meaning subscribe
|
||||
* all
|
||||
* @param offset from where to pull
|
||||
* @param maxNums max pulling numbers
|
||||
* @return The resulting {@code PullRequest}
|
||||
* @throws MQClientException
|
||||
* @throws InterruptedException
|
||||
* @throws MQBrokerException
|
||||
* @throws RemotingException
|
||||
*/
|
||||
PullResult pull(final MessageQueue mq, final String subExpression, final long offset,
|
||||
final int maxNums) throws MQClientException, RemotingException, MQBrokerException,
|
||||
@@ -68,16 +60,7 @@ public interface MQPullConsumer extends MQConsumer {
|
||||
/**
|
||||
* Pulling the messages in the specified timeout
|
||||
*
|
||||
* @param mq
|
||||
* @param subExpression
|
||||
* @param offset
|
||||
* @param maxNums
|
||||
* @param timeout
|
||||
* @return The resulting {@code PullRequest}
|
||||
* @throws MQClientException
|
||||
* @throws RemotingException
|
||||
* @throws MQBrokerException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
PullResult pull(final MessageQueue mq, final String subExpression, final long offset,
|
||||
final int maxNums, final long timeout) throws MQClientException, RemotingException,
|
||||
@@ -85,15 +68,6 @@ public interface MQPullConsumer extends MQConsumer {
|
||||
|
||||
/**
|
||||
* Pulling the messages in a async. way
|
||||
*
|
||||
* @param mq
|
||||
* @param subExpression
|
||||
* @param offset
|
||||
* @param maxNums
|
||||
* @param pullCallback
|
||||
* @throws MQClientException
|
||||
* @throws RemotingException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
void pull(final MessageQueue mq, final String subExpression, final long offset, final int maxNums,
|
||||
final PullCallback pullCallback) throws MQClientException, RemotingException,
|
||||
@@ -101,16 +75,6 @@ public interface MQPullConsumer extends MQConsumer {
|
||||
|
||||
/**
|
||||
* Pulling the messages in a async. way
|
||||
*
|
||||
* @param mq
|
||||
* @param subExpression
|
||||
* @param offset
|
||||
* @param maxNums
|
||||
* @param pullCallback
|
||||
* @param timeout
|
||||
* @throws MQClientException
|
||||
* @throws RemotingException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
void pull(final MessageQueue mq, final String subExpression, final long offset, final int maxNums,
|
||||
final PullCallback pullCallback, long timeout) throws MQClientException, RemotingException,
|
||||
@@ -119,15 +83,7 @@ public interface MQPullConsumer extends MQConsumer {
|
||||
/**
|
||||
* Pulling the messages,if no message arrival,blocking some time
|
||||
*
|
||||
* @param mq
|
||||
* @param subExpression
|
||||
* @param offset
|
||||
* @param maxNums
|
||||
* @return The resulting {@code PullRequest}
|
||||
* @throws MQClientException
|
||||
* @throws RemotingException
|
||||
* @throws MQBrokerException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
PullResult pullBlockIfNotFound(final MessageQueue mq, final String subExpression,
|
||||
final long offset, final int maxNums) throws MQClientException, RemotingException,
|
||||
@@ -135,15 +91,6 @@ public interface MQPullConsumer extends MQConsumer {
|
||||
|
||||
/**
|
||||
* Pulling the messages through callback function,if no message arrival,blocking.
|
||||
*
|
||||
* @param mq
|
||||
* @param subExpression
|
||||
* @param offset
|
||||
* @param maxNums
|
||||
* @param pullCallback
|
||||
* @throws MQClientException
|
||||
* @throws RemotingException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
void pullBlockIfNotFound(final MessageQueue mq, final String subExpression, final long offset,
|
||||
final int maxNums, final PullCallback pullCallback) throws MQClientException, RemotingException,
|
||||
@@ -151,20 +98,13 @@ public interface MQPullConsumer extends MQConsumer {
|
||||
|
||||
/**
|
||||
* Update the offset
|
||||
*
|
||||
* @param mq
|
||||
* @param offset
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void updateConsumeOffset(final MessageQueue mq, final long offset) throws MQClientException;
|
||||
|
||||
/**
|
||||
* Fetch the offset
|
||||
*
|
||||
* @param mq
|
||||
* @param fromStore
|
||||
* @return The fetched offset of given queue
|
||||
* @throws MQClientException
|
||||
*/
|
||||
long fetchConsumeOffset(final MessageQueue mq, final boolean fromStore) throws MQClientException;
|
||||
|
||||
@@ -173,22 +113,12 @@ public interface MQPullConsumer extends MQConsumer {
|
||||
*
|
||||
* @param topic message topic
|
||||
* @return message queue set
|
||||
* @throws MQClientException
|
||||
*/
|
||||
Set<MessageQueue> fetchMessageQueuesInBalance(final String topic) throws MQClientException;
|
||||
|
||||
/**
|
||||
* If consuming failure,message will be send back to the broker,and delay consuming in some time later.<br>
|
||||
* Mind! message can only be consumed in the same group.
|
||||
*
|
||||
* @param msg
|
||||
* @param delayLevel
|
||||
* @param brokerName
|
||||
* @param consumerGroup
|
||||
* @throws RemotingException
|
||||
* @throws MQBrokerException
|
||||
* @throws InterruptedException
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void sendMessageBack(MessageExt msg, int delayLevel, String brokerName, String consumerGroup)
|
||||
throws RemotingException, MQBrokerException, InterruptedException, MQClientException;
|
||||
|
||||
@@ -27,8 +27,6 @@ import org.apache.rocketmq.client.exception.MQClientException;
|
||||
public interface MQPushConsumer extends MQConsumer {
|
||||
/**
|
||||
* Start the consumer
|
||||
*
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void start() throws MQClientException;
|
||||
|
||||
@@ -39,8 +37,6 @@ public interface MQPushConsumer extends MQConsumer {
|
||||
|
||||
/**
|
||||
* Register the message listener
|
||||
*
|
||||
* @param messageListener
|
||||
*/
|
||||
@Deprecated
|
||||
void registerMessageListener(MessageListener messageListener);
|
||||
@@ -52,22 +48,20 @@ public interface MQPushConsumer extends MQConsumer {
|
||||
/**
|
||||
* Subscribe some topic
|
||||
*
|
||||
* @param topic
|
||||
* @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3" <br> if null or * expression,meaning subscribe
|
||||
* @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3" <br> if
|
||||
* null or * expression,meaning subscribe
|
||||
* all
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void subscribe(final String topic, final String subExpression) throws MQClientException;
|
||||
|
||||
/**
|
||||
* Subscribe some topic
|
||||
*
|
||||
* @param topic
|
||||
* @param fullClassName full class name,must extend org.apache.rocketmq.common.filter. MessageFilter
|
||||
* @param filterClassSource class source code,used UTF-8 file encoding,must be responsible for your code safety
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void subscribe(final String topic, final String fullClassName, final String filterClassSource) throws MQClientException;
|
||||
void subscribe(final String topic, final String fullClassName,
|
||||
final String filterClassSource) throws MQClientException;
|
||||
|
||||
/**
|
||||
* Subscribe some topic with selector.
|
||||
@@ -84,9 +78,7 @@ public interface MQPushConsumer extends MQConsumer {
|
||||
* Choose SQL92: {@link MessageSelector#bySql(java.lang.String)}
|
||||
* </p>
|
||||
*
|
||||
* @param topic
|
||||
* @param selector message selector({@link MessageSelector}), can be null.
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void subscribe(final String topic, final MessageSelector selector) throws MQClientException;
|
||||
|
||||
@@ -99,8 +91,6 @@ public interface MQPushConsumer extends MQConsumer {
|
||||
|
||||
/**
|
||||
* Update the consumer thread pool size Dynamically
|
||||
*
|
||||
* @param corePoolSize
|
||||
*/
|
||||
void updateCorePoolSize(int corePoolSize);
|
||||
|
||||
|
||||
@@ -20,14 +20,13 @@ package org.apache.rocketmq.client.consumer;
|
||||
import org.apache.rocketmq.common.filter.ExpressionType;
|
||||
|
||||
/**
|
||||
*
|
||||
* Message selector: select message at server.
|
||||
* <p>
|
||||
* Now, support:
|
||||
* <li>Tag: {@link org.apache.rocketmq.common.filter.ExpressionType#TAG}
|
||||
* </li>
|
||||
* <li>SQL92: {@link org.apache.rocketmq.common.filter.ExpressionType#SQL92}
|
||||
* </li>
|
||||
* Now, support:
|
||||
* <li>Tag: {@link org.apache.rocketmq.common.filter.ExpressionType#TAG}
|
||||
* </li>
|
||||
* <li>SQL92: {@link org.apache.rocketmq.common.filter.ExpressionType#SQL92}
|
||||
* </li>
|
||||
* </p>
|
||||
*/
|
||||
public class MessageSelector {
|
||||
@@ -51,7 +50,6 @@ public class MessageSelector {
|
||||
* Use SLQ92 to select message.
|
||||
*
|
||||
* @param sql if null or empty, will be treated as select all message.
|
||||
* @return
|
||||
*/
|
||||
public static MessageSelector bySql(String sql) {
|
||||
return new MessageSelector(ExpressionType.SQL92, sql);
|
||||
@@ -61,7 +59,6 @@ public class MessageSelector {
|
||||
* Use tag to select message.
|
||||
*
|
||||
* @param tag if null or empty or "*", will be treated as select all message.
|
||||
* @return
|
||||
*/
|
||||
public static MessageSelector byTag(String tag) {
|
||||
return new MessageSelector(ExpressionType.TAG, tag);
|
||||
|
||||
+2
-2
@@ -24,10 +24,10 @@ import org.apache.rocketmq.common.message.MessageExt;
|
||||
*/
|
||||
public interface MessageListenerConcurrently extends MessageListener {
|
||||
/**
|
||||
* It is not recommend to throw exception,rather than returning ConsumeConcurrentlyStatus.RECONSUME_LATER if consumption failure
|
||||
* It is not recommend to throw exception,rather than returning ConsumeConcurrentlyStatus.RECONSUME_LATER if
|
||||
* consumption failure
|
||||
*
|
||||
* @param msgs msgs.size() >= 1<br> DefaultMQPushConsumer.consumeMessageBatchMaxSize=1,you can modify here
|
||||
* @param context
|
||||
* @return The consume status
|
||||
*/
|
||||
ConsumeConcurrentlyStatus consumeMessage(final List<MessageExt> msgs,
|
||||
|
||||
+4
-3
@@ -20,14 +20,15 @@ import java.util.List;
|
||||
import org.apache.rocketmq.common.message.MessageExt;
|
||||
|
||||
/**
|
||||
* A MessageListenerConcurrently object is used to receive asynchronously delivered messages orderly.one queue,one thread
|
||||
* A MessageListenerConcurrently object is used to receive asynchronously delivered messages orderly.one queue,one
|
||||
* thread
|
||||
*/
|
||||
public interface MessageListenerOrderly extends MessageListener {
|
||||
/**
|
||||
* It is not recommend to throw exception,rather than returning ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT if consumption failure
|
||||
* It is not recommend to throw exception,rather than returning ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT
|
||||
* if consumption failure
|
||||
*
|
||||
* @param msgs msgs.size() >= 1<br> DefaultMQPushConsumer.consumeMessageBatchMaxSize=1,you can modify here
|
||||
* @param context
|
||||
* @return The consume status
|
||||
*/
|
||||
ConsumeOrderlyStatus consumeMessage(final List<MessageExt> msgs,
|
||||
|
||||
+2
-6
@@ -30,7 +30,7 @@ import org.slf4j.Logger;
|
||||
/**
|
||||
* Consistent Hashing queue algorithm
|
||||
*/
|
||||
public class AllocateMessageQueueConsistentHash implements AllocateMessageQueueStrategy {
|
||||
public class AllocateMessageQueueConsistentHash implements AllocateMessageQueueStrategy {
|
||||
private final Logger log = ClientLogger.getLog();
|
||||
|
||||
private final int virtualNodeCnt;
|
||||
@@ -41,7 +41,7 @@ public class AllocateMessageQueueConsistentHash implements AllocateMessageQueue
|
||||
}
|
||||
|
||||
public AllocateMessageQueueConsistentHash(int virtualNodeCnt) {
|
||||
this(virtualNodeCnt,null);
|
||||
this(virtualNodeCnt, null);
|
||||
}
|
||||
|
||||
public AllocateMessageQueueConsistentHash(int virtualNodeCnt, HashFunction customHashFunction) {
|
||||
@@ -75,7 +75,6 @@ public class AllocateMessageQueueConsistentHash implements AllocateMessageQueue
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Collection<ClientNode> cidNodes = new ArrayList<ClientNode>();
|
||||
for (String cid : cidAll) {
|
||||
cidNodes.add(new ClientNode(cid));
|
||||
@@ -105,7 +104,6 @@ public class AllocateMessageQueueConsistentHash implements AllocateMessageQueue
|
||||
return "CONSISTENT_HASH";
|
||||
}
|
||||
|
||||
|
||||
private static class ClientNode implements Node {
|
||||
private final String clientID;
|
||||
|
||||
@@ -119,6 +117,4 @@ public class AllocateMessageQueueConsistentHash implements AllocateMessageQueue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -52,9 +52,9 @@ public class LocalFileOffsetStore implements OffsetStore {
|
||||
public LocalFileOffsetStore(MQClientInstance mQClientFactory, String groupName) {
|
||||
this.mQClientFactory = mQClientFactory;
|
||||
this.groupName = groupName;
|
||||
this.storePath = LOCAL_OFFSET_STORE_DIR + File.separator + //
|
||||
this.mQClientFactory.getClientId() + File.separator + //
|
||||
this.groupName + File.separator + //
|
||||
this.storePath = LOCAL_OFFSET_STORE_DIR + File.separator +
|
||||
this.mQClientFactory.getClientId() + File.separator +
|
||||
this.groupName + File.separator +
|
||||
"offsets.json";
|
||||
}
|
||||
|
||||
@@ -217,8 +217,8 @@ public class LocalFileOffsetStore implements OffsetStore {
|
||||
OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class);
|
||||
} catch (Exception e) {
|
||||
log.warn("readLocalOffset Exception", e);
|
||||
throw new MQClientException("readLocalOffset Exception, maybe fastjson version too low" //
|
||||
+ FAQUrl.suggestTodo(FAQUrl.LOAD_JSON_EXCEPTION), //
|
||||
throw new MQClientException("readLocalOffset Exception, maybe fastjson version too low"
|
||||
+ FAQUrl.suggestTodo(FAQUrl.LOAD_JSON_EXCEPTION),
|
||||
e);
|
||||
}
|
||||
return offsetSerializeWrapper;
|
||||
|
||||
@@ -29,52 +29,37 @@ import org.apache.rocketmq.remoting.exception.RemotingException;
|
||||
public interface OffsetStore {
|
||||
/**
|
||||
* Load
|
||||
*
|
||||
* @throws MQClientException
|
||||
*/
|
||||
void load() throws MQClientException;
|
||||
|
||||
/**
|
||||
* Update the offset,store it in memory
|
||||
*
|
||||
* @param mq
|
||||
* @param offset
|
||||
* @param increaseOnly
|
||||
*/
|
||||
void updateOffset(final MessageQueue mq, final long offset, final boolean increaseOnly);
|
||||
|
||||
/**
|
||||
* Get offset from local storage
|
||||
*
|
||||
* @param mq
|
||||
* @param type
|
||||
* @return The fetched offset
|
||||
*/
|
||||
long readOffset(final MessageQueue mq, final ReadOffsetType type);
|
||||
|
||||
/**
|
||||
* Persist all offsets,may be in local storage or remote name server
|
||||
*
|
||||
* @param mqs
|
||||
*/
|
||||
void persistAll(final Set<MessageQueue> mqs);
|
||||
|
||||
/**
|
||||
* Persist the offset,may be in local storage or remote name server
|
||||
*
|
||||
* @param mq
|
||||
*/
|
||||
void persist(final MessageQueue mq);
|
||||
|
||||
/**
|
||||
* Remove offset
|
||||
*
|
||||
* @param mq
|
||||
*/
|
||||
void removeOffset(MessageQueue mq);
|
||||
|
||||
/**
|
||||
* @param topic
|
||||
* @return The cloned offset table of given topic
|
||||
*/
|
||||
Map<MessageQueue, Long> cloneOffsetTable(String topic);
|
||||
|
||||
+2
-2
@@ -204,7 +204,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
|
||||
MQBrokerException, InterruptedException, MQClientException {
|
||||
FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
|
||||
if (null == findBrokerResult) {
|
||||
// TODO Here may be heavily overhead for Name Server,need tuning
|
||||
|
||||
this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
|
||||
findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
|
||||
}
|
||||
@@ -232,7 +232,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
|
||||
InterruptedException, MQClientException {
|
||||
FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
|
||||
if (null == findBrokerResult) {
|
||||
// TODO Here may be heavily overhead for Name Server,need tuning
|
||||
|
||||
this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
|
||||
findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
|
||||
}
|
||||
|
||||
@@ -55,7 +55,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand processRequest(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
switch (request.getCode()) {
|
||||
case RequestCode.CHECK_TRANSACTION_STATE:
|
||||
return this.checkTransactionState(ctx, request);
|
||||
@@ -82,7 +83,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
public RemotingCommand checkTransactionState(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand checkTransactionState(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final CheckTransactionStateRequestHeader requestHeader =
|
||||
(CheckTransactionStateRequestHeader) request.decodeCommandCustomHeader(CheckTransactionStateRequestHeader.class);
|
||||
final ByteBuffer byteBuffer = ByteBuffer.wrap(request.getBody());
|
||||
@@ -107,7 +109,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
public RemotingCommand notifyConsumerIdsChanged(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand notifyConsumerIdsChanged(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
try {
|
||||
final NotifyConsumerIdsChangedRequestHeader requestHeader =
|
||||
(NotifyConsumerIdsChangedRequestHeader) request.decodeCommandCustomHeader(NotifyConsumerIdsChangedRequestHeader.class);
|
||||
@@ -121,12 +124,13 @@ public class ClientRemotingProcessor implements NettyRequestProcessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
public RemotingCommand resetOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand resetOffset(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final ResetOffsetRequestHeader requestHeader =
|
||||
(ResetOffsetRequestHeader) request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class);
|
||||
log.info("invoke reset offset operation from broker. brokerAddr={}, topic={}, group={}, timestamp={}",
|
||||
RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(),
|
||||
requestHeader.getTimestamp());
|
||||
RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(),
|
||||
requestHeader.getTimestamp());
|
||||
Map<MessageQueue, Long> offsetTable = new HashMap<MessageQueue, Long>();
|
||||
if (request.getBody() != null) {
|
||||
ResetOffsetBody body = ResetOffsetBody.decode(request.getBody(), ResetOffsetBody.class);
|
||||
@@ -137,7 +141,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public RemotingCommand getConsumeStatus(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
public RemotingCommand getConsumeStatus(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
final GetConsumerStatusRequestHeader requestHeader =
|
||||
(GetConsumerStatusRequestHeader) request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class);
|
||||
@@ -150,7 +155,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
final GetConsumerRunningInfoRequestHeader requestHeader =
|
||||
(GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class);
|
||||
@@ -173,7 +179,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor {
|
||||
return response;
|
||||
}
|
||||
|
||||
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
|
||||
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
|
||||
RemotingCommand request) throws RemotingCommandException {
|
||||
final RemotingCommand response = RemotingCommand.createResponseCommand(null);
|
||||
final ConsumeMessageDirectlyResultRequestHeader requestHeader =
|
||||
(ConsumeMessageDirectlyResultRequestHeader) request
|
||||
|
||||
@@ -159,7 +159,7 @@ public class MQAdminImpl {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new MQClientException(
|
||||
"Can not find Message Queue for this topic, " + topic + FAQUrl.suggestTodo(FAQUrl.MQLIST_NOT_EXIST), //
|
||||
"Can not find Message Queue for this topic, " + topic + FAQUrl.suggestTodo(FAQUrl.MQLIST_NOT_EXIST),
|
||||
e);
|
||||
}
|
||||
|
||||
@@ -240,7 +240,8 @@ public class MQAdminImpl {
|
||||
throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
|
||||
}
|
||||
|
||||
public MessageExt viewMessage(String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
public MessageExt viewMessage(
|
||||
String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
|
||||
MessageId messageId = null;
|
||||
try {
|
||||
@@ -252,12 +253,14 @@ public class MQAdminImpl {
|
||||
messageId.getOffset(), timeoutMillis);
|
||||
}
|
||||
|
||||
public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) throws MQClientException,
|
||||
public QueryResult queryMessage(String topic, String key, int maxNum, long begin,
|
||||
long end) throws MQClientException,
|
||||
InterruptedException {
|
||||
return queryMessage(topic, key, maxNum, begin, end, false);
|
||||
}
|
||||
|
||||
public MessageExt queryMessageByUniqKey(String topic, String uniqKey) throws InterruptedException, MQClientException {
|
||||
public MessageExt queryMessageByUniqKey(String topic,
|
||||
String uniqKey) throws InterruptedException, MQClientException {
|
||||
|
||||
QueryResult qr = this.queryMessage(topic, uniqKey, 32,
|
||||
MessageClientIDSetter.getNearlyTimeFromID(uniqKey).getTime() - 1000, Long.MAX_VALUE, true);
|
||||
@@ -268,7 +271,8 @@ public class MQAdminImpl {
|
||||
}
|
||||
}
|
||||
|
||||
protected QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end, boolean isUniqKey) throws MQClientException,
|
||||
protected QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end,
|
||||
boolean isUniqKey) throws MQClientException,
|
||||
InterruptedException {
|
||||
TopicRouteData topicRouteData = this.mQClientFactory.getAnExistTopicRouteData(topic);
|
||||
if (null == topicRouteData) {
|
||||
|
||||
@@ -18,14 +18,14 @@ package org.apache.rocketmq.client.impl;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.Iterator;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.apache.rocketmq.client.ClientConfig;
|
||||
import org.apache.rocketmq.client.consumer.PullCallback;
|
||||
@@ -49,12 +49,12 @@ import org.apache.rocketmq.common.UtilAll;
|
||||
import org.apache.rocketmq.common.admin.ConsumeStats;
|
||||
import org.apache.rocketmq.common.admin.TopicStatsTable;
|
||||
import org.apache.rocketmq.common.message.Message;
|
||||
import org.apache.rocketmq.common.message.MessageBatch;
|
||||
import org.apache.rocketmq.common.message.MessageClientIDSetter;
|
||||
import org.apache.rocketmq.common.message.MessageExt;
|
||||
import org.apache.rocketmq.common.message.MessageQueue;
|
||||
import org.apache.rocketmq.common.message.MessageConst;
|
||||
import org.apache.rocketmq.common.message.MessageDecoder;
|
||||
import org.apache.rocketmq.common.message.MessageBatch;
|
||||
import org.apache.rocketmq.common.message.MessageExt;
|
||||
import org.apache.rocketmq.common.message.MessageQueue;
|
||||
import org.apache.rocketmq.common.namesrv.TopAddressing;
|
||||
import org.apache.rocketmq.common.protocol.RequestCode;
|
||||
import org.apache.rocketmq.common.protocol.ResponseCode;
|
||||
@@ -152,7 +152,6 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand;
|
||||
import org.apache.rocketmq.remoting.protocol.RemotingSerializable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
|
||||
public class MQClientAPIImpl {
|
||||
|
||||
private final static Logger log = ClientLogger.getLog();
|
||||
@@ -169,7 +168,8 @@ public class MQClientAPIImpl {
|
||||
private String nameSrvAddr = null;
|
||||
private ClientConfig clientConfig;
|
||||
|
||||
public MQClientAPIImpl(final NettyClientConfig nettyClientConfig, final ClientRemotingProcessor clientRemotingProcessor,
|
||||
public MQClientAPIImpl(final NettyClientConfig nettyClientConfig,
|
||||
final ClientRemotingProcessor clientRemotingProcessor,
|
||||
RPCHook rpcHook, final ClientConfig clientConfig) {
|
||||
this.clientConfig = clientConfig;
|
||||
topAddressing = new TopAddressing(MixAll.getWSAddr(), clientConfig.getUnitName());
|
||||
@@ -233,7 +233,8 @@ public class MQClientAPIImpl {
|
||||
this.remotingClient.shutdown();
|
||||
}
|
||||
|
||||
public void createSubscriptionGroup(final String addr, final SubscriptionGroupConfig config, final long timeoutMillis)
|
||||
public void createSubscriptionGroup(final String addr, final SubscriptionGroupConfig config,
|
||||
final long timeoutMillis)
|
||||
throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_AND_CREATE_SUBSCRIPTIONGROUP, null);
|
||||
|
||||
@@ -255,7 +256,8 @@ public class MQClientAPIImpl {
|
||||
|
||||
}
|
||||
|
||||
public void createTopic(final String addr, final String defaultTopic, final TopicConfig topicConfig, final long timeoutMillis)
|
||||
public void createTopic(final String addr, final String defaultTopic, final TopicConfig topicConfig,
|
||||
final long timeoutMillis)
|
||||
throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
CreateTopicRequestHeader requestHeader = new CreateTopicRequestHeader();
|
||||
requestHeader.setTopic(topicConfig.getTopicName());
|
||||
@@ -283,32 +285,32 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public SendResult sendMessage(//
|
||||
final String addr, // 1
|
||||
final String brokerName, // 2
|
||||
final Message msg, // 3
|
||||
final SendMessageRequestHeader requestHeader, // 4
|
||||
final long timeoutMillis, // 5
|
||||
final CommunicationMode communicationMode, // 6
|
||||
final SendMessageContext context, // 7
|
||||
final DefaultMQProducerImpl producer // 8
|
||||
public SendResult sendMessage(
|
||||
final String addr,
|
||||
final String brokerName,
|
||||
final Message msg,
|
||||
final SendMessageRequestHeader requestHeader,
|
||||
final long timeoutMillis,
|
||||
final CommunicationMode communicationMode,
|
||||
final SendMessageContext context,
|
||||
final DefaultMQProducerImpl producer
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
return sendMessage(addr, brokerName, msg, requestHeader, timeoutMillis, communicationMode, null, null, null, 0, context, producer);
|
||||
}
|
||||
|
||||
public SendResult sendMessage(//
|
||||
final String addr, // 1
|
||||
final String brokerName, // 2
|
||||
final Message msg, // 3
|
||||
final SendMessageRequestHeader requestHeader, // 4
|
||||
final long timeoutMillis, // 5
|
||||
final CommunicationMode communicationMode, // 6
|
||||
final SendCallback sendCallback, // 7
|
||||
final TopicPublishInfo topicPublishInfo, // 8
|
||||
final MQClientInstance instance, // 9
|
||||
final int retryTimesWhenSendFailed, // 10
|
||||
final SendMessageContext context, // 11
|
||||
final DefaultMQProducerImpl producer // 12
|
||||
public SendResult sendMessage(
|
||||
final String addr,
|
||||
final String brokerName,
|
||||
final Message msg,
|
||||
final SendMessageRequestHeader requestHeader,
|
||||
final long timeoutMillis,
|
||||
final CommunicationMode communicationMode,
|
||||
final SendCallback sendCallback,
|
||||
final TopicPublishInfo topicPublishInfo,
|
||||
final MQClientInstance instance,
|
||||
final int retryTimesWhenSendFailed,
|
||||
final SendMessageContext context,
|
||||
final DefaultMQProducerImpl producer
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
RemotingCommand request = null;
|
||||
if (sendSmartMsg || msg instanceof MessageBatch) {
|
||||
@@ -339,31 +341,31 @@ public class MQClientAPIImpl {
|
||||
return null;
|
||||
}
|
||||
|
||||
private SendResult sendMessageSync(//
|
||||
final String addr, //
|
||||
final String brokerName, //
|
||||
final Message msg, //
|
||||
final long timeoutMillis, //
|
||||
final RemotingCommand request//
|
||||
private SendResult sendMessageSync(
|
||||
final String addr,
|
||||
final String brokerName,
|
||||
final Message msg,
|
||||
final long timeoutMillis,
|
||||
final RemotingCommand request
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
|
||||
assert response != null;
|
||||
return this.processSendResponse(brokerName, msg, response);
|
||||
}
|
||||
|
||||
private void sendMessageAsync(//
|
||||
final String addr, //
|
||||
final String brokerName, //
|
||||
final Message msg, //
|
||||
final long timeoutMillis, //
|
||||
final RemotingCommand request, //
|
||||
final SendCallback sendCallback, //
|
||||
final TopicPublishInfo topicPublishInfo, //
|
||||
final MQClientInstance instance, //
|
||||
final int retryTimesWhenSendFailed, //
|
||||
final AtomicInteger times, //
|
||||
final SendMessageContext context, //
|
||||
final DefaultMQProducerImpl producer //
|
||||
private void sendMessageAsync(
|
||||
final String addr,
|
||||
final String brokerName,
|
||||
final Message msg,
|
||||
final long timeoutMillis,
|
||||
final RemotingCommand request,
|
||||
final SendCallback sendCallback,
|
||||
final TopicPublishInfo topicPublishInfo,
|
||||
final MQClientInstance instance,
|
||||
final int retryTimesWhenSendFailed,
|
||||
final AtomicInteger times,
|
||||
final SendMessageContext context,
|
||||
final DefaultMQProducerImpl producer
|
||||
) throws InterruptedException, RemotingException {
|
||||
this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() {
|
||||
@Override
|
||||
@@ -378,7 +380,6 @@ public class MQClientAPIImpl {
|
||||
context.getProducer().executeSendMessageHookAfter(context);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
//
|
||||
}
|
||||
|
||||
producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), false);
|
||||
@@ -426,19 +427,19 @@ public class MQClientAPIImpl {
|
||||
});
|
||||
}
|
||||
|
||||
private void onExceptionImpl(final String brokerName, //
|
||||
final Message msg, //
|
||||
final long timeoutMillis, //
|
||||
final RemotingCommand request, //
|
||||
final SendCallback sendCallback, //
|
||||
final TopicPublishInfo topicPublishInfo, //
|
||||
final MQClientInstance instance, //
|
||||
final int timesTotal, //
|
||||
final AtomicInteger curTimes, //
|
||||
final Exception e, //
|
||||
final SendMessageContext context, //
|
||||
final boolean needRetry, //
|
||||
final DefaultMQProducerImpl producer // 12
|
||||
private void onExceptionImpl(final String brokerName,
|
||||
final Message msg,
|
||||
final long timeoutMillis,
|
||||
final RemotingCommand request,
|
||||
final SendCallback sendCallback,
|
||||
final TopicPublishInfo topicPublishInfo,
|
||||
final MQClientInstance instance,
|
||||
final int timesTotal,
|
||||
final AtomicInteger curTimes,
|
||||
final Exception e,
|
||||
final SendMessageContext context,
|
||||
final boolean needRetry,
|
||||
final DefaultMQProducerImpl producer
|
||||
) {
|
||||
int tmp = curTimes.incrementAndGet();
|
||||
if (needRetry && tmp <= timesTotal) {
|
||||
@@ -483,16 +484,15 @@ public class MQClientAPIImpl {
|
||||
}
|
||||
}
|
||||
|
||||
private SendResult processSendResponse(//
|
||||
final String brokerName, //
|
||||
final Message msg, //
|
||||
final RemotingCommand response//
|
||||
private SendResult processSendResponse(
|
||||
final String brokerName,
|
||||
final Message msg,
|
||||
final RemotingCommand response
|
||||
) throws MQBrokerException, RemotingCommandException {
|
||||
switch (response.getCode()) {
|
||||
case ResponseCode.FLUSH_DISK_TIMEOUT:
|
||||
case ResponseCode.FLUSH_SLAVE_TIMEOUT:
|
||||
case ResponseCode.SLAVE_NOT_AVAILABLE: {
|
||||
// TODO LOG
|
||||
}
|
||||
case ResponseCode.SUCCESS: {
|
||||
SendStatus sendStatus = SendStatus.SEND_OK;
|
||||
@@ -551,12 +551,12 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public PullResult pullMessage(//
|
||||
final String addr, //
|
||||
final PullMessageRequestHeader requestHeader, //
|
||||
final long timeoutMillis, //
|
||||
final CommunicationMode communicationMode, //
|
||||
final PullCallback pullCallback//
|
||||
public PullResult pullMessage(
|
||||
final String addr,
|
||||
final PullMessageRequestHeader requestHeader,
|
||||
final long timeoutMillis,
|
||||
final CommunicationMode communicationMode,
|
||||
final PullCallback pullCallback
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader);
|
||||
|
||||
@@ -577,11 +577,11 @@ public class MQClientAPIImpl {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void pullMessageAsync(//
|
||||
final String addr, // 1
|
||||
final RemotingCommand request, //
|
||||
final long timeoutMillis, //
|
||||
final PullCallback pullCallback//
|
||||
private void pullMessageAsync(
|
||||
final String addr,
|
||||
final RemotingCommand request,
|
||||
final long timeoutMillis,
|
||||
final PullCallback pullCallback
|
||||
) throws RemotingException, InterruptedException {
|
||||
this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() {
|
||||
@Override
|
||||
@@ -609,17 +609,18 @@ public class MQClientAPIImpl {
|
||||
});
|
||||
}
|
||||
|
||||
private PullResult pullMessageSync(//
|
||||
final String addr, // 1
|
||||
final RemotingCommand request, // 2
|
||||
final long timeoutMillis// 3
|
||||
private PullResult pullMessageSync(
|
||||
final String addr,
|
||||
final RemotingCommand request,
|
||||
final long timeoutMillis
|
||||
) throws RemotingException, InterruptedException, MQBrokerException {
|
||||
RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
|
||||
assert response != null;
|
||||
return this.processPullResponse(response);
|
||||
}
|
||||
|
||||
private PullResult processPullResponse(final RemotingCommand response) throws MQBrokerException, RemotingCommandException {
|
||||
private PullResult processPullResponse(
|
||||
final RemotingCommand response) throws MQBrokerException, RemotingCommandException {
|
||||
PullStatus pullStatus = PullStatus.NO_NEW_MSG;
|
||||
switch (response.getCode()) {
|
||||
case ResponseCode.SUCCESS:
|
||||
@@ -668,7 +669,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public long searchOffset(final String addr, final String topic, final int queueId, final long timestamp, final long timeoutMillis)
|
||||
public long searchOffset(final String addr, final String topic, final int queueId, final long timestamp,
|
||||
final long timeoutMillis)
|
||||
throws RemotingException, MQBrokerException, InterruptedException {
|
||||
SearchOffsetRequestHeader requestHeader = new SearchOffsetRequestHeader();
|
||||
requestHeader.setTopic(topic);
|
||||
@@ -716,9 +718,9 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public List<String> getConsumerIdListByGroup(//
|
||||
final String addr, //
|
||||
final String consumerGroup, //
|
||||
public List<String> getConsumerIdListByGroup(
|
||||
final String addr,
|
||||
final String consumerGroup,
|
||||
final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException,
|
||||
MQBrokerException, InterruptedException {
|
||||
GetConsumerListByGroupRequestHeader requestHeader = new GetConsumerListByGroupRequestHeader();
|
||||
@@ -767,7 +769,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public long getEarliestMsgStoretime(final String addr, final String topic, final int queueId, final long timeoutMillis)
|
||||
public long getEarliestMsgStoretime(final String addr, final String topic, final int queueId,
|
||||
final long timeoutMillis)
|
||||
throws RemotingException, MQBrokerException, InterruptedException {
|
||||
GetEarliestMsgStoretimeRequestHeader requestHeader = new GetEarliestMsgStoretimeRequestHeader();
|
||||
requestHeader.setTopic(topic);
|
||||
@@ -791,10 +794,10 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public long queryConsumerOffset(//
|
||||
final String addr, //
|
||||
final QueryConsumerOffsetRequestHeader requestHeader, //
|
||||
final long timeoutMillis//
|
||||
public long queryConsumerOffset(
|
||||
final String addr,
|
||||
final QueryConsumerOffsetRequestHeader requestHeader,
|
||||
final long timeoutMillis
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUMER_OFFSET, requestHeader);
|
||||
|
||||
@@ -815,10 +818,10 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public void updateConsumerOffset(//
|
||||
final String addr, //
|
||||
final UpdateConsumerOffsetRequestHeader requestHeader, //
|
||||
final long timeoutMillis//
|
||||
public void updateConsumerOffset(
|
||||
final String addr,
|
||||
final UpdateConsumerOffsetRequestHeader requestHeader,
|
||||
final long timeoutMillis
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_CONSUMER_OFFSET, requestHeader);
|
||||
|
||||
@@ -836,10 +839,10 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public void updateConsumerOffsetOneway(//
|
||||
final String addr, //
|
||||
final UpdateConsumerOffsetRequestHeader requestHeader, //
|
||||
final long timeoutMillis//
|
||||
public void updateConsumerOffsetOneway(
|
||||
final String addr,
|
||||
final UpdateConsumerOffsetRequestHeader requestHeader,
|
||||
final long timeoutMillis
|
||||
) throws RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException,
|
||||
InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_CONSUMER_OFFSET, requestHeader);
|
||||
@@ -847,10 +850,10 @@ public class MQClientAPIImpl {
|
||||
this.remotingClient.invokeOneway(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
|
||||
}
|
||||
|
||||
public int sendHearbeat(//
|
||||
final String addr, //
|
||||
final HeartbeatData heartbeatData, //
|
||||
final long timeoutMillis//
|
||||
public int sendHearbeat(
|
||||
final String addr,
|
||||
final HeartbeatData heartbeatData,
|
||||
final long timeoutMillis
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.HEART_BEAT, null);
|
||||
|
||||
@@ -868,12 +871,12 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public void unregisterClient(//
|
||||
final String addr, //
|
||||
final String clientID, //
|
||||
final String producerGroup, //
|
||||
final String consumerGroup, //
|
||||
final long timeoutMillis//
|
||||
public void unregisterClient(
|
||||
final String addr,
|
||||
final String clientID,
|
||||
final String producerGroup,
|
||||
final String consumerGroup,
|
||||
final long timeoutMillis
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
final UnregisterClientRequestHeader requestHeader = new UnregisterClientRequestHeader();
|
||||
requestHeader.setClientID(clientID);
|
||||
@@ -894,11 +897,11 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public void endTransactionOneway(//
|
||||
final String addr, //
|
||||
final EndTransactionRequestHeader requestHeader, //
|
||||
final String remark, //
|
||||
final long timeoutMillis//
|
||||
public void endTransactionOneway(
|
||||
final String addr,
|
||||
final EndTransactionRequestHeader requestHeader,
|
||||
final String remark,
|
||||
final long timeoutMillis
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.END_TRANSACTION, requestHeader);
|
||||
|
||||
@@ -960,9 +963,9 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public Set<MessageQueue> lockBatchMQ(//
|
||||
final String addr, //
|
||||
final LockBatchRequestBody requestBody, //
|
||||
public Set<MessageQueue> lockBatchMQ(
|
||||
final String addr,
|
||||
final LockBatchRequestBody requestBody,
|
||||
final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null);
|
||||
|
||||
@@ -982,11 +985,11 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public void unlockBatchMQ(//
|
||||
final String addr, //
|
||||
final UnlockBatchRequestBody requestBody, //
|
||||
final long timeoutMillis, //
|
||||
final boolean oneway//
|
||||
public void unlockBatchMQ(
|
||||
final String addr,
|
||||
final UnlockBatchRequestBody requestBody,
|
||||
final long timeoutMillis,
|
||||
final boolean oneway
|
||||
) throws RemotingException, MQBrokerException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UNLOCK_BATCH_MQ, null);
|
||||
|
||||
@@ -1009,7 +1012,8 @@ public class MQClientAPIImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public TopicStatsTable getTopicStatsInfo(final String addr, final String topic, final long timeoutMillis) throws InterruptedException,
|
||||
public TopicStatsTable getTopicStatsInfo(final String addr, final String topic,
|
||||
final long timeoutMillis) throws InterruptedException,
|
||||
RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
|
||||
GetTopicStatsInfoRequestHeader requestHeader = new GetTopicStatsInfoRequestHeader();
|
||||
requestHeader.setTopic(topic);
|
||||
@@ -1036,7 +1040,8 @@ public class MQClientAPIImpl {
|
||||
return getConsumeStats(addr, consumerGroup, null, timeoutMillis);
|
||||
}
|
||||
|
||||
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic, final long timeoutMillis)
|
||||
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic,
|
||||
final long timeoutMillis)
|
||||
throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException,
|
||||
MQBrokerException {
|
||||
GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader();
|
||||
@@ -1059,7 +1064,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public ProducerConnection getProducerConnectionList(final String addr, final String producerGroup, final long timeoutMillis)
|
||||
public ProducerConnection getProducerConnectionList(final String addr, final String producerGroup,
|
||||
final long timeoutMillis)
|
||||
throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException,
|
||||
MQBrokerException {
|
||||
GetProducerConnectionListRequestHeader requestHeader = new GetProducerConnectionListRequestHeader();
|
||||
@@ -1080,7 +1086,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public ConsumerConnection getConsumerConnectionList(final String addr, final String consumerGroup, final long timeoutMillis)
|
||||
public ConsumerConnection getConsumerConnectionList(final String addr, final String consumerGroup,
|
||||
final long timeoutMillis)
|
||||
throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException,
|
||||
MQBrokerException {
|
||||
GetConsumerConnectionListRequestHeader requestHeader = new GetConsumerConnectionListRequestHeader();
|
||||
@@ -1160,7 +1167,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public ClusterInfo getBrokerClusterInfo(final long timeoutMillis) throws InterruptedException, RemotingTimeoutException,
|
||||
public ClusterInfo getBrokerClusterInfo(
|
||||
final long timeoutMillis) throws InterruptedException, RemotingTimeoutException,
|
||||
RemotingSendRequestException, RemotingConnectException, MQBrokerException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_INFO, null);
|
||||
|
||||
@@ -1179,33 +1187,18 @@ public class MQClientAPIImpl {
|
||||
|
||||
public TopicRouteData getDefaultTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis)
|
||||
throws RemotingException, MQClientException, InterruptedException {
|
||||
GetRouteInfoRequestHeader requestHeader = new GetRouteInfoRequestHeader();
|
||||
requestHeader.setTopic(topic);
|
||||
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ROUTEINTO_BY_TOPIC, requestHeader);
|
||||
|
||||
RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
|
||||
assert response != null;
|
||||
switch (response.getCode()) {
|
||||
case ResponseCode.TOPIC_NOT_EXIST: {
|
||||
// TODO LOG
|
||||
break;
|
||||
}
|
||||
case ResponseCode.SUCCESS: {
|
||||
byte[] body = response.getBody();
|
||||
if (body != null) {
|
||||
return TopicRouteData.decode(body, TopicRouteData.class);
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
return getTopicRouteInfoFromNameServer(topic, timeoutMillis, false);
|
||||
}
|
||||
|
||||
public TopicRouteData getTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis)
|
||||
throws RemotingException, MQClientException, InterruptedException {
|
||||
|
||||
return getTopicRouteInfoFromNameServer(topic, timeoutMillis, true);
|
||||
}
|
||||
|
||||
public TopicRouteData getTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis,
|
||||
boolean allowTopicNotExist) throws MQClientException, InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
|
||||
GetRouteInfoRequestHeader requestHeader = new GetRouteInfoRequestHeader();
|
||||
requestHeader.setTopic(topic);
|
||||
|
||||
@@ -1215,8 +1208,10 @@ public class MQClientAPIImpl {
|
||||
assert response != null;
|
||||
switch (response.getCode()) {
|
||||
case ResponseCode.TOPIC_NOT_EXIST: {
|
||||
if (!topic.equals(MixAll.DEFAULT_TOPIC))
|
||||
if (allowTopicNotExist && !topic.equals(MixAll.DEFAULT_TOPIC)) {
|
||||
log.warn("get Topic [{}] RouteInfoFromNameServer is not exist value", topic);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ResponseCode.SUCCESS: {
|
||||
@@ -1252,7 +1247,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public int wipeWritePermOfBroker(final String namesrvAddr, String brokerName, final long timeoutMillis) throws RemotingCommandException,
|
||||
public int wipeWritePermOfBroker(final String namesrvAddr, String brokerName,
|
||||
final long timeoutMillis) throws RemotingCommandException,
|
||||
RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException {
|
||||
WipeWritePermOfBrokerRequestHeader requestHeader = new WipeWritePermOfBrokerRequestHeader();
|
||||
requestHeader.setBrokerName(brokerName);
|
||||
@@ -1471,8 +1467,10 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public Map<String, Map<MessageQueue, Long>> invokeBrokerToGetConsumerStatus(final String addr, final String topic, final String group,
|
||||
final String clientAddr, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
|
||||
public Map<String, Map<MessageQueue, Long>> invokeBrokerToGetConsumerStatus(final String addr, final String topic,
|
||||
final String group,
|
||||
final String clientAddr,
|
||||
final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
|
||||
GetConsumerStatusRequestHeader requestHeader = new GetConsumerStatusRequestHeader();
|
||||
requestHeader.setTopic(topic);
|
||||
requestHeader.setGroup(group);
|
||||
@@ -1519,7 +1517,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public List<QueueTimeSpan> queryConsumeTimeSpan(final String addr, final String topic, final String group, final long timeoutMillis)
|
||||
public List<QueueTimeSpan> queryConsumeTimeSpan(final String addr, final String topic, final String group,
|
||||
final long timeoutMillis)
|
||||
throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException,
|
||||
MQBrokerException {
|
||||
QueryConsumeTimeSpanRequestHeader requestHeader = new QueryConsumeTimeSpanRequestHeader();
|
||||
@@ -1565,12 +1564,12 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public void registerMessageFilterClass(final String addr, //
|
||||
final String consumerGroup, //
|
||||
final String topic, //
|
||||
final String className, //
|
||||
final int classCRC, //
|
||||
final byte[] classBody, //
|
||||
public void registerMessageFilterClass(final String addr,
|
||||
final String consumerGroup,
|
||||
final String topic,
|
||||
final String className,
|
||||
final int classCRC,
|
||||
final byte[] classBody,
|
||||
final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException,
|
||||
InterruptedException, MQBrokerException {
|
||||
RegisterMessageFilterClassRequestHeader requestHeader = new RegisterMessageFilterClassRequestHeader();
|
||||
@@ -1593,7 +1592,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public TopicList getSystemTopicList(final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
|
||||
public TopicList getSystemTopicList(
|
||||
final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_SYSTEM_TOPIC_LIST_FROM_NS, null);
|
||||
|
||||
RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
|
||||
@@ -1642,7 +1642,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public boolean cleanExpiredConsumeQueue(final String addr, long timeoutMillis) throws MQClientException, RemotingConnectException,
|
||||
public boolean cleanExpiredConsumeQueue(final String addr,
|
||||
long timeoutMillis) throws MQClientException, RemotingConnectException,
|
||||
RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CLEAN_EXPIRED_CONSUMEQUEUE, null);
|
||||
RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
|
||||
@@ -1658,7 +1659,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public boolean cleanUnusedTopicByAddr(final String addr, long timeoutMillis) throws MQClientException, RemotingConnectException,
|
||||
public boolean cleanUnusedTopicByAddr(final String addr,
|
||||
long timeoutMillis) throws MQClientException, RemotingConnectException,
|
||||
RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CLEAN_UNUSED_TOPIC, null);
|
||||
RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
|
||||
@@ -1674,7 +1676,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public ConsumerRunningInfo getConsumerRunningInfo(final String addr, String consumerGroup, String clientId, boolean jstack,
|
||||
public ConsumerRunningInfo getConsumerRunningInfo(final String addr, String consumerGroup, String clientId,
|
||||
boolean jstack,
|
||||
final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
|
||||
GetConsumerRunningInfoRequestHeader requestHeader = new GetConsumerRunningInfoRequestHeader();
|
||||
requestHeader.setConsumerGroup(consumerGroup);
|
||||
@@ -1701,10 +1704,10 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public ConsumeMessageDirectlyResult consumeMessageDirectly(final String addr, //
|
||||
String consumerGroup, //
|
||||
String clientId, //
|
||||
String msgId, //
|
||||
public ConsumeMessageDirectlyResult consumeMessageDirectly(final String addr,
|
||||
String consumerGroup,
|
||||
String clientId,
|
||||
String msgId,
|
||||
final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
|
||||
ConsumeMessageDirectlyResultRequestHeader requestHeader = new ConsumeMessageDirectlyResultRequestHeader();
|
||||
requestHeader.setConsumerGroup(consumerGroup);
|
||||
@@ -1731,7 +1734,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public Map<Integer, Long> queryCorrectionOffset(final String addr, final String topic, final String group, Set<String> filterGroup,
|
||||
public Map<Integer, Long> queryCorrectionOffset(final String addr, final String topic, final String group,
|
||||
Set<String> filterGroup,
|
||||
long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException,
|
||||
InterruptedException {
|
||||
QueryCorrectionOffsetHeader requestHeader = new QueryCorrectionOffsetHeader();
|
||||
@@ -1854,7 +1858,8 @@ public class MQClientAPIImpl {
|
||||
}
|
||||
|
||||
public void cloneGroupOffset(final String addr, final String srcGroup, final String destGroup, final String topic,
|
||||
final boolean isOffline, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
|
||||
final boolean isOffline,
|
||||
final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
|
||||
CloneGroupOffsetRequestHeader requestHeader = new CloneGroupOffsetRequestHeader();
|
||||
requestHeader.setSrcGroup(srcGroup);
|
||||
requestHeader.setDestGroup(destGroup);
|
||||
@@ -1902,13 +1907,14 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public Set<String> getClusterList(String topic, long timeoutMillis) throws MQClientException, RemotingConnectException,
|
||||
public Set<String> getClusterList(String topic,
|
||||
long timeoutMillis) throws MQClientException, RemotingConnectException,
|
||||
RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
|
||||
// todo:jodie
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
|
||||
public ConsumeStatsList fetchConsumeStatsInBroker(String brokerAddr, boolean isOrder, long timeoutMillis) throws MQClientException,
|
||||
public ConsumeStatsList fetchConsumeStatsInBroker(String brokerAddr, boolean isOrder,
|
||||
long timeoutMillis) throws MQClientException,
|
||||
RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
|
||||
GetConsumeStatsInBrokerHeader requestHeader = new GetConsumeStatsInBrokerHeader();
|
||||
requestHeader.setIsOrder(isOrder);
|
||||
@@ -1932,7 +1938,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQClientException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException,
|
||||
public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr,
|
||||
long timeoutMillis) throws InterruptedException,
|
||||
RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
|
||||
RemotingCommand response = this.remotingClient
|
||||
@@ -1948,7 +1955,8 @@ public class MQClientAPIImpl {
|
||||
throw new MQBrokerException(response.getCode(), response.getRemark());
|
||||
}
|
||||
|
||||
public TopicConfigSerializeWrapper getAllTopicConfig(final String addr, long timeoutMillis) throws RemotingConnectException,
|
||||
public TopicConfigSerializeWrapper getAllTopicConfig(final String addr,
|
||||
long timeoutMillis) throws RemotingConnectException,
|
||||
RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null);
|
||||
|
||||
@@ -2028,9 +2036,10 @@ public class MQClientAPIImpl {
|
||||
return configMap;
|
||||
}
|
||||
|
||||
public QueryConsumeQueueResponseBody queryConsumeQueue(final String brokerAddr, final String topic, final int queueId,
|
||||
final long index, final int count, final String consumerGroup,
|
||||
final long timeoutMillis) throws InterruptedException,
|
||||
public QueryConsumeQueueResponseBody queryConsumeQueue(final String brokerAddr, final String topic,
|
||||
final int queueId,
|
||||
final long index, final int count, final String consumerGroup,
|
||||
final long timeoutMillis) throws InterruptedException,
|
||||
RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException {
|
||||
|
||||
QueryConsumeQueueRequestHeader requestHeader = new QueryConsumeQueueRequestHeader();
|
||||
@@ -2054,8 +2063,8 @@ public class MQClientAPIImpl {
|
||||
}
|
||||
|
||||
public void checkClientInBroker(final String brokerAddr, final String consumerGroup,
|
||||
final String clientId, final SubscriptionData subscriptionData,
|
||||
final long timeoutMillis)
|
||||
final String clientId, final SubscriptionData subscriptionData,
|
||||
final long timeoutMillis)
|
||||
throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException,
|
||||
RemotingConnectException, MQClientException {
|
||||
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CHECK_CLIENT_CONFIG, null);
|
||||
|
||||
+32
-34
@@ -69,12 +69,12 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
this.consumerGroup = this.defaultMQPushConsumer.getConsumerGroup();
|
||||
this.consumeRequestQueue = new LinkedBlockingQueue<Runnable>();
|
||||
|
||||
this.consumeExecutor = new ThreadPoolExecutor(//
|
||||
this.defaultMQPushConsumer.getConsumeThreadMin(), //
|
||||
this.defaultMQPushConsumer.getConsumeThreadMax(), //
|
||||
1000 * 60, //
|
||||
TimeUnit.MILLISECONDS, //
|
||||
this.consumeRequestQueue, //
|
||||
this.consumeExecutor = new ThreadPoolExecutor(
|
||||
this.defaultMQPushConsumer.getConsumeThreadMin(),
|
||||
this.defaultMQPushConsumer.getConsumeThreadMax(),
|
||||
1000 * 60,
|
||||
TimeUnit.MILLISECONDS,
|
||||
this.consumeRequestQueue,
|
||||
new ThreadFactoryImpl("ConsumeMessageThread_"));
|
||||
|
||||
this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("ConsumeMessageScheduledThread_"));
|
||||
@@ -100,8 +100,8 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
|
||||
@Override
|
||||
public void updateCorePoolSize(int corePoolSize) {
|
||||
if (corePoolSize > 0 //
|
||||
&& corePoolSize <= Short.MAX_VALUE //
|
||||
if (corePoolSize > 0
|
||||
&& corePoolSize <= Short.MAX_VALUE
|
||||
&& corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) {
|
||||
this.consumeExecutor.setCorePoolSize(corePoolSize);
|
||||
}
|
||||
@@ -115,11 +115,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
// this.consumeExecutor.setCorePoolSize(this.consumeExecutor.getCorePoolSize()
|
||||
// + 1);
|
||||
// }
|
||||
//
|
||||
// log.info("incCorePoolSize Concurrently from {} to {}, ConsumerGroup:
|
||||
// {}", //
|
||||
// corePoolSize,//
|
||||
// this.consumeExecutor.getCorePoolSize(),//
|
||||
// {}",
|
||||
// corePoolSize,
|
||||
// this.consumeExecutor.getCorePoolSize(),
|
||||
// this.consumerGroup);
|
||||
}
|
||||
|
||||
@@ -131,11 +130,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
// this.consumeExecutor.setCorePoolSize(this.consumeExecutor.getCorePoolSize()
|
||||
// - 1);
|
||||
// }
|
||||
//
|
||||
// log.info("decCorePoolSize Concurrently from {} to {}, ConsumerGroup:
|
||||
// {}", //
|
||||
// corePoolSize,//
|
||||
// this.consumeExecutor.getCorePoolSize(),//
|
||||
// {}",
|
||||
// corePoolSize,
|
||||
// this.consumeExecutor.getCorePoolSize(),
|
||||
// this.consumerGroup);
|
||||
}
|
||||
|
||||
@@ -185,10 +183,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
result.setConsumeResult(CMResult.CR_THROW_EXCEPTION);
|
||||
result.setRemark(RemotingHelper.exceptionSimpleDesc(e));
|
||||
|
||||
log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", //
|
||||
RemotingHelper.exceptionSimpleDesc(e), //
|
||||
ConsumeMessageConcurrentlyService.this.consumerGroup, //
|
||||
msgs, //
|
||||
log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s",
|
||||
RemotingHelper.exceptionSimpleDesc(e),
|
||||
ConsumeMessageConcurrentlyService.this.consumerGroup,
|
||||
msgs,
|
||||
mq), e);
|
||||
}
|
||||
|
||||
@@ -200,10 +198,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitConsumeRequest(//
|
||||
final List<MessageExt> msgs, //
|
||||
final ProcessQueue processQueue, //
|
||||
final MessageQueue messageQueue, //
|
||||
public void submitConsumeRequest(
|
||||
final List<MessageExt> msgs,
|
||||
final ProcessQueue processQueue,
|
||||
final MessageQueue messageQueue,
|
||||
final boolean dispatchToConsume) {
|
||||
final int consumeBatchSize = this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize();
|
||||
if (msgs.size() <= consumeBatchSize) {
|
||||
@@ -258,10 +256,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
}
|
||||
}
|
||||
|
||||
public void processConsumeResult(//
|
||||
final ConsumeConcurrentlyStatus status, //
|
||||
final ConsumeConcurrentlyContext context, //
|
||||
final ConsumeRequest consumeRequest//
|
||||
public void processConsumeResult(
|
||||
final ConsumeConcurrentlyStatus status,
|
||||
final ConsumeConcurrentlyContext context,
|
||||
final ConsumeRequest consumeRequest
|
||||
) {
|
||||
int ackIndex = context.getAckIndex();
|
||||
|
||||
@@ -338,10 +336,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
return false;
|
||||
}
|
||||
|
||||
private void submitConsumeRequestLater(//
|
||||
final List<MessageExt> msgs, //
|
||||
final ProcessQueue processQueue, //
|
||||
final MessageQueue messageQueue//
|
||||
private void submitConsumeRequestLater(
|
||||
final List<MessageExt> msgs,
|
||||
final ProcessQueue processQueue,
|
||||
final MessageQueue messageQueue
|
||||
) {
|
||||
|
||||
this.scheduledExecutorService.schedule(new Runnable() {
|
||||
@@ -353,7 +351,7 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
}, 5000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private void submitConsumeRequestLater(final ConsumeRequest consumeRequest//
|
||||
private void submitConsumeRequestLater(final ConsumeRequest consumeRequest
|
||||
) {
|
||||
|
||||
this.scheduledExecutorService.schedule(new Runnable() {
|
||||
@@ -419,7 +417,7 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService
|
||||
status = listener.consumeMessage(Collections.unmodifiableList(msgs), context);
|
||||
} catch (Throwable e) {
|
||||
log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}",
|
||||
RemotingHelper.exceptionSimpleDesc(e), //
|
||||
RemotingHelper.exceptionSimpleDesc(e),
|
||||
ConsumeMessageConcurrentlyService.this.consumerGroup,
|
||||
msgs,
|
||||
messageQueue);
|
||||
|
||||
+47
-45
@@ -62,7 +62,8 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
private final ScheduledExecutorService scheduledExecutorService;
|
||||
private volatile boolean stopped = false;
|
||||
|
||||
public ConsumeMessageOrderlyService(DefaultMQPushConsumerImpl defaultMQPushConsumerImpl, MessageListenerOrderly messageListener) {
|
||||
public ConsumeMessageOrderlyService(DefaultMQPushConsumerImpl defaultMQPushConsumerImpl,
|
||||
MessageListenerOrderly messageListener) {
|
||||
this.defaultMQPushConsumerImpl = defaultMQPushConsumerImpl;
|
||||
this.messageListener = messageListener;
|
||||
|
||||
@@ -70,12 +71,12 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
this.consumerGroup = this.defaultMQPushConsumer.getConsumerGroup();
|
||||
this.consumeRequestQueue = new LinkedBlockingQueue<Runnable>();
|
||||
|
||||
this.consumeExecutor = new ThreadPoolExecutor(//
|
||||
this.defaultMQPushConsumer.getConsumeThreadMin(), //
|
||||
this.defaultMQPushConsumer.getConsumeThreadMax(), //
|
||||
1000 * 60, //
|
||||
TimeUnit.MILLISECONDS, //
|
||||
this.consumeRequestQueue, //
|
||||
this.consumeExecutor = new ThreadPoolExecutor(
|
||||
this.defaultMQPushConsumer.getConsumeThreadMin(),
|
||||
this.defaultMQPushConsumer.getConsumeThreadMax(),
|
||||
1000 * 60,
|
||||
TimeUnit.MILLISECONDS,
|
||||
this.consumeRequestQueue,
|
||||
new ThreadFactoryImpl("ConsumeMessageThread_"));
|
||||
|
||||
this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("ConsumeMessageScheduledThread_"));
|
||||
@@ -107,8 +108,8 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
|
||||
@Override
|
||||
public void updateCorePoolSize(int corePoolSize) {
|
||||
if (corePoolSize > 0 //
|
||||
&& corePoolSize <= Short.MAX_VALUE //
|
||||
if (corePoolSize > 0
|
||||
&& corePoolSize <= Short.MAX_VALUE
|
||||
&& corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) {
|
||||
this.consumeExecutor.setCorePoolSize(corePoolSize);
|
||||
}
|
||||
@@ -171,10 +172,10 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
result.setConsumeResult(CMResult.CR_THROW_EXCEPTION);
|
||||
result.setRemark(RemotingHelper.exceptionSimpleDesc(e));
|
||||
|
||||
log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", //
|
||||
RemotingHelper.exceptionSimpleDesc(e), //
|
||||
ConsumeMessageOrderlyService.this.consumerGroup, //
|
||||
msgs, //
|
||||
log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s",
|
||||
RemotingHelper.exceptionSimpleDesc(e),
|
||||
ConsumeMessageOrderlyService.this.consumerGroup,
|
||||
msgs,
|
||||
mq), e);
|
||||
}
|
||||
|
||||
@@ -187,10 +188,10 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitConsumeRequest(//
|
||||
final List<MessageExt> msgs, //
|
||||
final ProcessQueue processQueue, //
|
||||
final MessageQueue messageQueue, //
|
||||
public void submitConsumeRequest(
|
||||
final List<MessageExt> msgs,
|
||||
final ProcessQueue processQueue,
|
||||
final MessageQueue messageQueue,
|
||||
final boolean dispathToConsume) {
|
||||
if (dispathToConsume) {
|
||||
ConsumeRequest consumeRequest = new ConsumeRequest(processQueue, messageQueue);
|
||||
@@ -204,7 +205,8 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
}
|
||||
}
|
||||
|
||||
public void tryLockLaterAndReconsume(final MessageQueue mq, final ProcessQueue processQueue, final long delayMills) {
|
||||
public void tryLockLaterAndReconsume(final MessageQueue mq, final ProcessQueue processQueue,
|
||||
final long delayMills) {
|
||||
this.scheduledExecutorService.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -226,10 +228,10 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void submitConsumeRequestLater(//
|
||||
final ProcessQueue processQueue, //
|
||||
final MessageQueue messageQueue, //
|
||||
final long suspendTimeMillis//
|
||||
private void submitConsumeRequestLater(
|
||||
final ProcessQueue processQueue,
|
||||
final MessageQueue messageQueue,
|
||||
final long suspendTimeMillis
|
||||
) {
|
||||
long timeMillis = suspendTimeMillis;
|
||||
if (timeMillis == -1) {
|
||||
@@ -251,11 +253,11 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
}, timeMillis, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public boolean processConsumeResult(//
|
||||
final List<MessageExt> msgs, //
|
||||
final ConsumeOrderlyStatus status, //
|
||||
final ConsumeOrderlyContext context, //
|
||||
final ConsumeRequest consumeRequest//
|
||||
public boolean processConsumeResult(
|
||||
final List<MessageExt> msgs,
|
||||
final ConsumeOrderlyStatus status,
|
||||
final ConsumeOrderlyContext context,
|
||||
final ConsumeRequest consumeRequest
|
||||
) {
|
||||
boolean continueConsume = true;
|
||||
long commitOffset = -1L;
|
||||
@@ -273,9 +275,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
this.getConsumerStatsManager().incConsumeFailedTPS(consumerGroup, consumeRequest.getMessageQueue().getTopic(), msgs.size());
|
||||
if (checkReconsumeTimes(msgs)) {
|
||||
consumeRequest.getProcessQueue().makeMessageToCosumeAgain(msgs);
|
||||
this.submitConsumeRequestLater(//
|
||||
consumeRequest.getProcessQueue(), //
|
||||
consumeRequest.getMessageQueue(), //
|
||||
this.submitConsumeRequestLater(
|
||||
consumeRequest.getProcessQueue(),
|
||||
consumeRequest.getMessageQueue(),
|
||||
context.getSuspendCurrentQueueTimeMillis());
|
||||
continueConsume = false;
|
||||
} else {
|
||||
@@ -295,9 +297,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
break;
|
||||
case ROLLBACK:
|
||||
consumeRequest.getProcessQueue().rollback();
|
||||
this.submitConsumeRequestLater(//
|
||||
consumeRequest.getProcessQueue(), //
|
||||
consumeRequest.getMessageQueue(), //
|
||||
this.submitConsumeRequestLater(
|
||||
consumeRequest.getProcessQueue(),
|
||||
consumeRequest.getMessageQueue(),
|
||||
context.getSuspendCurrentQueueTimeMillis());
|
||||
continueConsume = false;
|
||||
break;
|
||||
@@ -305,9 +307,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
this.getConsumerStatsManager().incConsumeFailedTPS(consumerGroup, consumeRequest.getMessageQueue().getTopic(), msgs.size());
|
||||
if (checkReconsumeTimes(msgs)) {
|
||||
consumeRequest.getProcessQueue().makeMessageToCosumeAgain(msgs);
|
||||
this.submitConsumeRequestLater(//
|
||||
consumeRequest.getProcessQueue(), //
|
||||
consumeRequest.getMessageQueue(), //
|
||||
this.submitConsumeRequestLater(
|
||||
consumeRequest.getProcessQueue(),
|
||||
consumeRequest.getMessageQueue(),
|
||||
context.getSuspendCurrentQueueTimeMillis());
|
||||
continueConsume = false;
|
||||
}
|
||||
@@ -468,22 +470,22 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService {
|
||||
|
||||
status = messageListener.consumeMessage(Collections.unmodifiableList(msgs), context);
|
||||
} catch (Throwable e) {
|
||||
log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}", //
|
||||
RemotingHelper.exceptionSimpleDesc(e), //
|
||||
ConsumeMessageOrderlyService.this.consumerGroup, //
|
||||
msgs, //
|
||||
log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}",
|
||||
RemotingHelper.exceptionSimpleDesc(e),
|
||||
ConsumeMessageOrderlyService.this.consumerGroup,
|
||||
msgs,
|
||||
messageQueue);
|
||||
hasException = true;
|
||||
} finally {
|
||||
this.processQueue.getLockConsume().unlock();
|
||||
}
|
||||
|
||||
if (null == status //
|
||||
|| ConsumeOrderlyStatus.ROLLBACK == status//
|
||||
if (null == status
|
||||
|| ConsumeOrderlyStatus.ROLLBACK == status
|
||||
|| ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT == status) {
|
||||
log.warn("consumeMessage Orderly return not OK, Group: {} Msgs: {} MQ: {}", //
|
||||
ConsumeMessageOrderlyService.this.consumerGroup, //
|
||||
msgs, //
|
||||
log.warn("consumeMessage Orderly return not OK, Group: {} Msgs: {} MQ: {}",
|
||||
ConsumeMessageOrderlyService.this.consumerGroup,
|
||||
msgs,
|
||||
messageQueue);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -36,9 +36,9 @@ public interface ConsumeMessageService {
|
||||
|
||||
ConsumeMessageDirectlyResult consumeMessageDirectly(final MessageExt msg, final String brokerName);
|
||||
|
||||
void submitConsumeRequest(//
|
||||
final List<MessageExt> msgs, //
|
||||
final ProcessQueue processQueue, //
|
||||
final MessageQueue messageQueue, //
|
||||
void submitConsumeRequest(
|
||||
final List<MessageExt> msgs,
|
||||
final ProcessQueue processQueue,
|
||||
final MessageQueue messageQueue,
|
||||
final boolean dispathToConsume);
|
||||
}
|
||||
|
||||
+52
-52
@@ -97,8 +97,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
|
||||
private void makeSureStateOK() throws MQClientException {
|
||||
if (this.serviceState != ServiceState.RUNNING) {
|
||||
throw new MQClientException("The consumer service state not OK, "//
|
||||
+ this.serviceState//
|
||||
throw new MQClientException("The consumer service state not OK, "
|
||||
+ this.serviceState
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK),
|
||||
null);
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
|
||||
SubscriptionData subscriptionData;
|
||||
try {
|
||||
subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), //
|
||||
subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(),
|
||||
mq.getTopic(), subExpression);
|
||||
} catch (Exception e) {
|
||||
throw new MQClientException("parse subscription error", e);
|
||||
@@ -193,18 +193,18 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
|
||||
long timeoutMillis = block ? this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() : timeout;
|
||||
|
||||
PullResult pullResult = this.pullAPIWrapper.pullKernelImpl(//
|
||||
mq, // 1
|
||||
subscriptionData.getSubString(), // 2
|
||||
0L, // 3
|
||||
offset, // 4
|
||||
maxNums, // 5
|
||||
sysFlag, // 6
|
||||
0, // 7
|
||||
this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), // 8
|
||||
timeoutMillis, // 9
|
||||
CommunicationMode.SYNC, // 10
|
||||
null// 11
|
||||
PullResult pullResult = this.pullAPIWrapper.pullKernelImpl(
|
||||
mq,
|
||||
subscriptionData.getSubString(),
|
||||
0L,
|
||||
offset,
|
||||
maxNums,
|
||||
sysFlag,
|
||||
0,
|
||||
this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(),
|
||||
timeoutMillis,
|
||||
CommunicationMode.SYNC,
|
||||
null
|
||||
);
|
||||
this.pullAPIWrapper.processPullResult(mq, pullResult, subscriptionData);
|
||||
if (!this.consumeMessageHookList.isEmpty()) {
|
||||
@@ -225,7 +225,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
public void subscriptionAutomatically(final String topic) {
|
||||
if (!this.rebalanceImpl.getSubscriptionInner().containsKey(topic)) {
|
||||
try {
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), //
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(),
|
||||
topic, SubscriptionData.SUB_ALL);
|
||||
this.rebalanceImpl.subscriptionInner.putIfAbsent(topic, subscriptionData);
|
||||
} catch (Exception ignore) {
|
||||
@@ -372,13 +372,13 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
this.pullAsyncImpl(mq, subExpression, offset, maxNums, pullCallback, false, timeout);
|
||||
}
|
||||
|
||||
private void pullAsyncImpl(//
|
||||
final MessageQueue mq, //
|
||||
final String subExpression, //
|
||||
final long offset, //
|
||||
final int maxNums, //
|
||||
final PullCallback pullCallback, //
|
||||
final boolean block, //
|
||||
private void pullAsyncImpl(
|
||||
final MessageQueue mq,
|
||||
final String subExpression,
|
||||
final long offset,
|
||||
final int maxNums,
|
||||
final PullCallback pullCallback,
|
||||
final boolean block,
|
||||
final long timeout) throws MQClientException, RemotingException, InterruptedException {
|
||||
this.makeSureStateOK();
|
||||
|
||||
@@ -405,7 +405,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
|
||||
final SubscriptionData subscriptionData;
|
||||
try {
|
||||
subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), //
|
||||
subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(),
|
||||
mq.getTopic(), subExpression);
|
||||
} catch (Exception e) {
|
||||
throw new MQClientException("parse subscription error", e);
|
||||
@@ -413,17 +413,17 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
|
||||
long timeoutMillis = block ? this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() : timeout;
|
||||
|
||||
this.pullAPIWrapper.pullKernelImpl(//
|
||||
mq, // 1
|
||||
subscriptionData.getSubString(), // 2
|
||||
0L, // 3
|
||||
offset, // 4
|
||||
maxNums, // 5
|
||||
sysFlag, // 6
|
||||
0, // 7
|
||||
this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), // 8
|
||||
timeoutMillis, // 9
|
||||
CommunicationMode.ASYNC, // 10
|
||||
this.pullAPIWrapper.pullKernelImpl(
|
||||
mq,
|
||||
subscriptionData.getSubString(),
|
||||
0L,
|
||||
offset,
|
||||
maxNums,
|
||||
sysFlag,
|
||||
0,
|
||||
this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(),
|
||||
timeoutMillis,
|
||||
CommunicationMode.ASYNC,
|
||||
new PullCallback() {
|
||||
|
||||
@Override
|
||||
@@ -551,8 +551,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
this.rebalanceImpl.setAllocateMessageQueueStrategy(this.defaultMQPullConsumer.getAllocateMessageQueueStrategy());
|
||||
this.rebalanceImpl.setmQClientFactory(this.mQClientFactory);
|
||||
|
||||
this.pullAPIWrapper = new PullAPIWrapper(//
|
||||
mQClientFactory, //
|
||||
this.pullAPIWrapper = new PullAPIWrapper(
|
||||
mQClientFactory,
|
||||
this.defaultMQPullConsumer.getConsumerGroup(), isUnitMode());
|
||||
this.pullAPIWrapper.registerFilterMessageHook(filterMessageHookList);
|
||||
|
||||
@@ -589,8 +589,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
case RUNNING:
|
||||
case START_FAILED:
|
||||
case SHUTDOWN_ALREADY:
|
||||
throw new MQClientException("The PullConsumer service state not OK, maybe started once, "//
|
||||
+ this.serviceState//
|
||||
throw new MQClientException("The PullConsumer service state not OK, maybe started once, "
|
||||
+ this.serviceState
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK),
|
||||
null);
|
||||
default:
|
||||
@@ -606,42 +606,42 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
// consumerGroup
|
||||
if (null == this.defaultMQPullConsumer.getConsumerGroup()) {
|
||||
throw new MQClientException(
|
||||
"consumerGroup is null" //
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
|
||||
"consumerGroup is null"
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),
|
||||
null);
|
||||
}
|
||||
|
||||
// consumerGroup
|
||||
if (this.defaultMQPullConsumer.getConsumerGroup().equals(MixAll.DEFAULT_CONSUMER_GROUP)) {
|
||||
throw new MQClientException(
|
||||
"consumerGroup can not equal "//
|
||||
+ MixAll.DEFAULT_CONSUMER_GROUP //
|
||||
+ ", please specify another one."//
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
|
||||
"consumerGroup can not equal "
|
||||
+ MixAll.DEFAULT_CONSUMER_GROUP
|
||||
+ ", please specify another one."
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),
|
||||
null);
|
||||
}
|
||||
|
||||
// messageModel
|
||||
if (null == this.defaultMQPullConsumer.getMessageModel()) {
|
||||
throw new MQClientException(
|
||||
"messageModel is null" //
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
|
||||
"messageModel is null"
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),
|
||||
null);
|
||||
}
|
||||
|
||||
// allocateMessageQueueStrategy
|
||||
if (null == this.defaultMQPullConsumer.getAllocateMessageQueueStrategy()) {
|
||||
throw new MQClientException(
|
||||
"allocateMessageQueueStrategy is null" //
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
|
||||
"allocateMessageQueueStrategy is null"
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),
|
||||
null);
|
||||
}
|
||||
|
||||
// allocateMessageQueueStrategy
|
||||
if (this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() < this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis()) {
|
||||
throw new MQClientException(
|
||||
"Long polling mode, the consumer consumerTimeoutMillisWhenSuspend must greater than brokerSuspendMaxTimeMillis" //
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), //
|
||||
"Long polling mode, the consumer consumerTimeoutMillisWhenSuspend must greater than brokerSuspendMaxTimeMillis"
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL),
|
||||
null);
|
||||
}
|
||||
}
|
||||
@@ -651,7 +651,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
|
||||
Set<String> registerTopics = this.defaultMQPullConsumer.getRegisterTopics();
|
||||
if (registerTopics != null) {
|
||||
for (final String topic : registerTopics) {
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), //
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(),
|
||||
topic, SubscriptionData.SUB_ALL);
|
||||
this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
|
||||
}
|
||||
|
||||
+31
-31
@@ -297,10 +297,10 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
pullRequest.getMessageQueue().getTopic(), pullResult.getMsgFoundList().size());
|
||||
|
||||
boolean dispathToConsume = processQueue.putMessage(pullResult.getMsgFoundList());
|
||||
DefaultMQPushConsumerImpl.this.consumeMessageService.submitConsumeRequest(//
|
||||
pullResult.getMsgFoundList(), //
|
||||
processQueue, //
|
||||
pullRequest.getMessageQueue(), //
|
||||
DefaultMQPushConsumerImpl.this.consumeMessageService.submitConsumeRequest(
|
||||
pullResult.getMsgFoundList(),
|
||||
processQueue,
|
||||
pullRequest.getMessageQueue(),
|
||||
dispathToConsume);
|
||||
|
||||
if (DefaultMQPushConsumerImpl.this.defaultMQPushConsumer.getPullInterval() > 0) {
|
||||
@@ -311,12 +311,12 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
}
|
||||
}
|
||||
|
||||
if (pullResult.getNextBeginOffset() < prevRequestOffset//
|
||||
if (pullResult.getNextBeginOffset() < prevRequestOffset
|
||||
|| firstMsgOffset < prevRequestOffset) {
|
||||
log.warn(
|
||||
"[BUG] pull message result maybe data wrong, nextBeginOffset: {} firstMsgOffset: {} prevRequestOffset: {}", //
|
||||
pullResult.getNextBeginOffset(), //
|
||||
firstMsgOffset, //
|
||||
"[BUG] pull message result maybe data wrong, nextBeginOffset: {} firstMsgOffset: {} prevRequestOffset: {}",
|
||||
pullResult.getNextBeginOffset(),
|
||||
firstMsgOffset,
|
||||
prevRequestOffset);
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
DefaultMQPushConsumerImpl.this.executePullRequestImmediately(pullRequest);
|
||||
break;
|
||||
case OFFSET_ILLEGAL:
|
||||
log.warn("the pull request offset illegal, {} {}", //
|
||||
log.warn("the pull request offset illegal, {} {}",
|
||||
pullRequest.toString(), pullResult.toString());
|
||||
pullRequest.setNextOffset(pullResult.getNextBeginOffset());
|
||||
|
||||
@@ -396,26 +396,26 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
classFilter = sd.isClassFilterMode();
|
||||
}
|
||||
|
||||
int sysFlag = PullSysFlag.buildSysFlag(//
|
||||
int sysFlag = PullSysFlag.buildSysFlag(
|
||||
commitOffsetEnable, // commitOffset
|
||||
true, // suspend
|
||||
subExpression != null, // subscription
|
||||
classFilter // class filter
|
||||
);
|
||||
try {
|
||||
this.pullAPIWrapper.pullKernelImpl(//
|
||||
pullRequest.getMessageQueue(), // 1
|
||||
subExpression, // 2
|
||||
subscriptionData.getExpressionType(), // 3
|
||||
subscriptionData.getSubVersion(), // 4
|
||||
pullRequest.getNextOffset(), // 5
|
||||
this.defaultMQPushConsumer.getPullBatchSize(), // 6
|
||||
sysFlag, // 7
|
||||
commitOffsetValue, // 8
|
||||
BROKER_SUSPEND_MAX_TIME_MILLIS, // 9
|
||||
CONSUMER_TIMEOUT_MILLIS_WHEN_SUSPEND, // 10
|
||||
CommunicationMode.ASYNC, // 11
|
||||
pullCallback // 12
|
||||
this.pullAPIWrapper.pullKernelImpl(
|
||||
pullRequest.getMessageQueue(),
|
||||
subExpression,
|
||||
subscriptionData.getExpressionType(),
|
||||
subscriptionData.getSubVersion(),
|
||||
pullRequest.getNextOffset(),
|
||||
this.defaultMQPushConsumer.getPullBatchSize(),
|
||||
sysFlag,
|
||||
commitOffsetValue,
|
||||
BROKER_SUSPEND_MAX_TIME_MILLIS,
|
||||
CONSUMER_TIMEOUT_MILLIS_WHEN_SUSPEND,
|
||||
CommunicationMode.ASYNC,
|
||||
pullCallback
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("pullKernelImpl exception", e);
|
||||
@@ -425,8 +425,8 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
|
||||
private void makeSureStateOK() throws MQClientException {
|
||||
if (this.serviceState != ServiceState.RUNNING) {
|
||||
throw new MQClientException("The consumer service state not OK, "//
|
||||
+ this.serviceState//
|
||||
throw new MQClientException("The consumer service state not OK, "
|
||||
+ this.serviceState
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK),
|
||||
null);
|
||||
}
|
||||
@@ -608,8 +608,8 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
case RUNNING:
|
||||
case START_FAILED:
|
||||
case SHUTDOWN_ALREADY:
|
||||
throw new MQClientException("The PushConsumer service state not OK, maybe started once, "//
|
||||
+ this.serviceState//
|
||||
throw new MQClientException("The PushConsumer service state not OK, maybe started once, "
|
||||
+ this.serviceState
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK),
|
||||
null);
|
||||
default:
|
||||
@@ -764,7 +764,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
for (final Map.Entry<String, String> entry : sub.entrySet()) {
|
||||
final String topic = entry.getKey();
|
||||
final String subString = entry.getValue();
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), //
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
|
||||
topic, subString);
|
||||
this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
|
||||
}
|
||||
@@ -779,7 +779,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
break;
|
||||
case CLUSTERING:
|
||||
final String retryTopic = MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup());
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), //
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
|
||||
retryTopic, SubscriptionData.SUB_ALL);
|
||||
this.rebalanceImpl.getSubscriptionInner().put(retryTopic, subscriptionData);
|
||||
break;
|
||||
@@ -811,7 +811,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
|
||||
public void subscribe(String topic, String subExpression) throws MQClientException {
|
||||
try {
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), //
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
|
||||
topic, subExpression);
|
||||
this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData);
|
||||
if (this.mQClientFactory != null) {
|
||||
@@ -824,7 +824,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner {
|
||||
|
||||
public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException {
|
||||
try {
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), //
|
||||
SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(),
|
||||
topic, "*");
|
||||
subscriptionData.setSubString(fullClassName);
|
||||
subscriptionData.setClassFilterMode(true);
|
||||
|
||||
@@ -55,7 +55,8 @@ public abstract class RebalanceImpl {
|
||||
protected AllocateMessageQueueStrategy allocateMessageQueueStrategy;
|
||||
protected MQClientInstance mQClientFactory;
|
||||
|
||||
public RebalanceImpl(String consumerGroup, MessageModel messageModel, AllocateMessageQueueStrategy allocateMessageQueueStrategy,
|
||||
public RebalanceImpl(String consumerGroup, MessageModel messageModel,
|
||||
AllocateMessageQueueStrategy allocateMessageQueueStrategy,
|
||||
MQClientInstance mQClientFactory) {
|
||||
this.consumerGroup = consumerGroup;
|
||||
this.messageModel = messageModel;
|
||||
@@ -73,9 +74,9 @@ public abstract class RebalanceImpl {
|
||||
|
||||
try {
|
||||
this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway);
|
||||
log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}", //
|
||||
this.consumerGroup, //
|
||||
this.mQClientFactory.getClientId(), //
|
||||
log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}",
|
||||
this.consumerGroup,
|
||||
this.mQClientFactory.getClientId(),
|
||||
mq);
|
||||
} catch (Exception e) {
|
||||
log.error("unlockBatchMQ exception, " + mq, e);
|
||||
@@ -245,10 +246,10 @@ public abstract class RebalanceImpl {
|
||||
boolean changed = this.updateProcessQueueTableInRebalance(topic, mqSet, isOrder);
|
||||
if (changed) {
|
||||
this.messageQueueChanged(topic, mqSet, mqSet);
|
||||
log.info("messageQueueChanged {} {} {} {}", //
|
||||
consumerGroup, //
|
||||
topic, //
|
||||
mqSet, //
|
||||
log.info("messageQueueChanged {} {} {} {}",
|
||||
consumerGroup,
|
||||
topic,
|
||||
mqSet,
|
||||
mqSet);
|
||||
}
|
||||
} else {
|
||||
@@ -280,10 +281,10 @@ public abstract class RebalanceImpl {
|
||||
|
||||
List<MessageQueue> allocateResult = null;
|
||||
try {
|
||||
allocateResult = strategy.allocate(//
|
||||
this.consumerGroup, //
|
||||
this.mQClientFactory.getClientId(), //
|
||||
mqAll, //
|
||||
allocateResult = strategy.allocate(
|
||||
this.consumerGroup,
|
||||
this.mQClientFactory.getClientId(),
|
||||
mqAll,
|
||||
cidAll);
|
||||
} catch (Throwable e) {
|
||||
log.error("AllocateMessageQueueStrategy.allocate Exception. allocateMessageQueueStrategyName={}", strategy.getName(),
|
||||
@@ -327,7 +328,8 @@ public abstract class RebalanceImpl {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateProcessQueueTableInRebalance(final String topic, final Set<MessageQueue> mqSet, final boolean isOrder) {
|
||||
private boolean updateProcessQueueTableInRebalance(final String topic, final Set<MessageQueue> mqSet,
|
||||
final boolean isOrder) {
|
||||
boolean changed = false;
|
||||
|
||||
Iterator<Entry<MessageQueue, ProcessQueue>> it = this.processQueueTable.entrySet().iterator();
|
||||
@@ -400,7 +402,8 @@ public abstract class RebalanceImpl {
|
||||
return changed;
|
||||
}
|
||||
|
||||
public abstract void messageQueueChanged(final String topic, final Set<MessageQueue> mqAll, final Set<MessageQueue> mqDivided);
|
||||
public abstract void messageQueueChanged(final String topic, final Set<MessageQueue> mqAll,
|
||||
final Set<MessageQueue> mqDivided);
|
||||
|
||||
public abstract boolean removeUnnecessaryMessageQueue(final MessageQueue mq, final ProcessQueue pq);
|
||||
|
||||
|
||||
+2
-1
@@ -32,7 +32,8 @@ public class RebalancePullImpl extends RebalanceImpl {
|
||||
this(null, null, null, null, defaultMQPullConsumerImpl);
|
||||
}
|
||||
|
||||
public RebalancePullImpl(String consumerGroup, MessageModel messageModel, AllocateMessageQueueStrategy allocateMessageQueueStrategy,
|
||||
public RebalancePullImpl(String consumerGroup, MessageModel messageModel,
|
||||
AllocateMessageQueueStrategy allocateMessageQueueStrategy,
|
||||
MQClientInstance mQClientFactory, DefaultMQPullConsumerImpl defaultMQPullConsumerImpl) {
|
||||
super(consumerGroup, messageModel, allocateMessageQueueStrategy, mQClientFactory);
|
||||
this.defaultMQPullConsumerImpl = defaultMQPullConsumerImpl;
|
||||
|
||||
+4
-3
@@ -40,7 +40,8 @@ public class RebalancePushImpl extends RebalanceImpl {
|
||||
this(null, null, null, null, defaultMQPushConsumerImpl);
|
||||
}
|
||||
|
||||
public RebalancePushImpl(String consumerGroup, MessageModel messageModel, AllocateMessageQueueStrategy allocateMessageQueueStrategy,
|
||||
public RebalancePushImpl(String consumerGroup, MessageModel messageModel,
|
||||
AllocateMessageQueueStrategy allocateMessageQueueStrategy,
|
||||
MQClientInstance mQClientFactory, DefaultMQPushConsumerImpl defaultMQPushConsumerImpl) {
|
||||
super(consumerGroup, messageModel, allocateMessageQueueStrategy, mQClientFactory);
|
||||
this.defaultMQPushConsumerImpl = defaultMQPushConsumerImpl;
|
||||
@@ -74,8 +75,8 @@ public class RebalancePushImpl extends RebalanceImpl {
|
||||
pq.getLockConsume().unlock();
|
||||
}
|
||||
} else {
|
||||
log.warn("[WRONG]mq is consuming, so can not unlock it, {}. maybe hanged for a while, {}", //
|
||||
mq, //
|
||||
log.warn("[WRONG]mq is consuming, so can not unlock it, {}. maybe hanged for a while, {}",
|
||||
mq,
|
||||
pq.getTryUnlockTimes());
|
||||
|
||||
pq.incTryUnlockTimes();
|
||||
|
||||
@@ -21,9 +21,6 @@ import org.apache.rocketmq.client.log.ClientLogger;
|
||||
import org.apache.rocketmq.common.ServiceThread;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* Rebalance Service
|
||||
*/
|
||||
public class RebalanceService extends ServiceThread {
|
||||
private static long waitInterval =
|
||||
Long.parseLong(System.getProperty(
|
||||
|
||||
+17
-16
@@ -148,10 +148,10 @@ public class MQClientInstance {
|
||||
|
||||
this.consumerStatsManager = new ConsumerStatsManager(this.scheduledExecutorService);
|
||||
|
||||
log.info("created a new client Instance, FactoryIndex: {} ClinetID: {} {} {}, serializeType={}", //
|
||||
this.instanceIndex, //
|
||||
this.clientId, //
|
||||
this.clientConfig, //
|
||||
log.info("created a new client Instance, FactoryIndex: {} ClinetID: {} {} {}, serializeType={}",
|
||||
this.instanceIndex,
|
||||
this.clientId,
|
||||
this.clientConfig,
|
||||
MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION), RemotingCommand.getSerializeTypeConfigInThisServer());
|
||||
}
|
||||
|
||||
@@ -584,7 +584,8 @@ public class MQClientInstance {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateTopicRouteInfoFromNameServer(final String topic, boolean isDefault, DefaultMQProducer defaultMQProducer) {
|
||||
public boolean updateTopicRouteInfoFromNameServer(final String topic, boolean isDefault,
|
||||
DefaultMQProducer defaultMQProducer) {
|
||||
try {
|
||||
if (this.lockNamesrv.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
|
||||
try {
|
||||
@@ -719,7 +720,8 @@ public class MQClientInstance {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void uploadFilterClassToAllFilterServer(final String consumerGroup, final String fullClassName, final String topic,
|
||||
private void uploadFilterClassToAllFilterServer(final String consumerGroup, final String fullClassName,
|
||||
final String topic,
|
||||
final String filterClassSource) throws UnsupportedEncodingException {
|
||||
byte[] classBody = null;
|
||||
int classCRC = 0;
|
||||
@@ -727,13 +729,13 @@ public class MQClientInstance {
|
||||
classBody = filterClassSource.getBytes(MixAll.DEFAULT_CHARSET);
|
||||
classCRC = UtilAll.crc32(classBody);
|
||||
} catch (Exception e1) {
|
||||
log.warn("uploadFilterClassToAllFilterServer Exception, ClassName: {} {}", //
|
||||
fullClassName, //
|
||||
log.warn("uploadFilterClassToAllFilterServer Exception, ClassName: {} {}",
|
||||
fullClassName,
|
||||
RemotingHelper.exceptionSimpleDesc(e1));
|
||||
}
|
||||
|
||||
TopicRouteData topicRouteData = this.topicRouteTable.get(topic);
|
||||
if (topicRouteData != null //
|
||||
if (topicRouteData != null
|
||||
&& topicRouteData.getFilterServerTable() != null && !topicRouteData.getFilterServerTable().isEmpty()) {
|
||||
Iterator<Entry<String, List<String>>> it = topicRouteData.getFilterServerTable().entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
@@ -1006,10 +1008,10 @@ public class MQClientInstance {
|
||||
return null;
|
||||
}
|
||||
|
||||
public FindBrokerResult findBrokerAddressInSubscribe(//
|
||||
final String brokerName, //
|
||||
final long brokerId, //
|
||||
final boolean onlyThisBroker//
|
||||
public FindBrokerResult findBrokerAddressInSubscribe(
|
||||
final String brokerName,
|
||||
final long brokerId,
|
||||
final boolean onlyThisBroker
|
||||
) {
|
||||
String brokerAddr = null;
|
||||
boolean slave = false;
|
||||
@@ -1102,7 +1104,6 @@ public class MQClientInstance {
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
//
|
||||
}
|
||||
|
||||
Iterator<MessageQueue> iterator = processQueueTable.keySet().iterator();
|
||||
@@ -1171,8 +1172,8 @@ public class MQClientInstance {
|
||||
return topicRouteTable;
|
||||
}
|
||||
|
||||
public ConsumeMessageDirectlyResult consumeMessageDirectly(final MessageExt msg, //
|
||||
final String consumerGroup, //
|
||||
public ConsumeMessageDirectlyResult consumeMessageDirectly(final MessageExt msg,
|
||||
final String consumerGroup,
|
||||
final String brokerName) {
|
||||
MQConsumerInner mqConsumerInner = this.consumerTable.get(consumerGroup);
|
||||
if (null != mqConsumerInner) {
|
||||
|
||||
+60
-53
@@ -116,11 +116,11 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
public void initTransactionEnv() {
|
||||
TransactionMQProducer producer = (TransactionMQProducer) this.defaultMQProducer;
|
||||
this.checkRequestQueue = new LinkedBlockingQueue<Runnable>(producer.getCheckRequestHoldMax());
|
||||
this.checkExecutor = new ThreadPoolExecutor(//
|
||||
producer.getCheckThreadPoolMinSize(), //
|
||||
producer.getCheckThreadPoolMaxSize(), //
|
||||
1000 * 60, //
|
||||
TimeUnit.MILLISECONDS, //
|
||||
this.checkExecutor = new ThreadPoolExecutor(
|
||||
producer.getCheckThreadPoolMinSize(),
|
||||
producer.getCheckThreadPoolMaxSize(),
|
||||
1000 * 60,
|
||||
TimeUnit.MILLISECONDS,
|
||||
this.checkRequestQueue);
|
||||
}
|
||||
|
||||
@@ -172,8 +172,8 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
case RUNNING:
|
||||
case START_FAILED:
|
||||
case SHUTDOWN_ALREADY:
|
||||
throw new MQClientException("The producer service state not OK, maybe started once, "//
|
||||
+ this.serviceState//
|
||||
throw new MQClientException("The producer service state not OK, maybe started once, "
|
||||
+ this.serviceState
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK),
|
||||
null);
|
||||
default:
|
||||
@@ -248,7 +248,8 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkTransactionState(final String addr, final MessageExt msg, final CheckTransactionStateRequestHeader header) {
|
||||
public void checkTransactionState(final String addr, final MessageExt msg,
|
||||
final CheckTransactionStateRequestHeader header) {
|
||||
Runnable request = new Runnable() {
|
||||
private final String brokerAddr = addr;
|
||||
private final MessageExt message = msg;
|
||||
@@ -268,18 +269,18 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
this.processTransactionState(//
|
||||
localTransactionState, //
|
||||
group, //
|
||||
this.processTransactionState(
|
||||
localTransactionState,
|
||||
group,
|
||||
exception);
|
||||
} else {
|
||||
log.warn("checkTransactionState, pick transactionCheckListener by group[{}] failed", group);
|
||||
}
|
||||
}
|
||||
|
||||
private void processTransactionState(//
|
||||
final LocalTransactionState localTransactionState, //
|
||||
final String producerGroup, //
|
||||
private void processTransactionState(
|
||||
final LocalTransactionState localTransactionState,
|
||||
final String producerGroup,
|
||||
final Throwable exception) {
|
||||
final EndTransactionRequestHeader thisHeader = new EndTransactionRequestHeader();
|
||||
thisHeader.setCommitLogOffset(checkRequestHeader.getCommitLogOffset());
|
||||
@@ -354,8 +355,8 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
|
||||
private void makeSureStateOK() throws MQClientException {
|
||||
if (this.serviceState != ServiceState.RUNNING) {
|
||||
throw new MQClientException("The producer service state not OK, "//
|
||||
+ this.serviceState//
|
||||
throw new MQClientException("The producer service state not OK, "
|
||||
+ this.serviceState
|
||||
+ FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK),
|
||||
null);
|
||||
}
|
||||
@@ -386,7 +387,8 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
return this.mQClientFactory.getMQAdminImpl().earliestMsgStoreTime(mq);
|
||||
}
|
||||
|
||||
public MessageExt viewMessage(String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
public MessageExt viewMessage(
|
||||
String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
this.makeSureStateOK();
|
||||
|
||||
return this.mQClientFactory.getMQAdminImpl().viewMessage(msgId);
|
||||
@@ -407,7 +409,8 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
/**
|
||||
* DEFAULT ASYNC -------------------------------------------------------
|
||||
*/
|
||||
public void send(Message msg, SendCallback sendCallback) throws MQClientException, RemotingException, InterruptedException {
|
||||
public void send(Message msg,
|
||||
SendCallback sendCallback) throws MQClientException, RemotingException, InterruptedException {
|
||||
send(msg, sendCallback, this.defaultMQProducer.getSendMsgTimeout());
|
||||
}
|
||||
|
||||
@@ -428,11 +431,11 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
this.mqFaultStrategy.updateFaultItem(brokerName, currentLatency, isolation);
|
||||
}
|
||||
|
||||
private SendResult sendDefaultImpl(//
|
||||
Message msg, //
|
||||
final CommunicationMode communicationMode, //
|
||||
final SendCallback sendCallback, //
|
||||
final long timeout//
|
||||
private SendResult sendDefaultImpl(
|
||||
Message msg,
|
||||
final CommunicationMode communicationMode,
|
||||
final SendCallback sendCallback,
|
||||
final long timeout
|
||||
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
this.makeSureStateOK();
|
||||
Validators.checkMessage(msg, this.defaultMQProducer);
|
||||
@@ -579,11 +582,11 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
}
|
||||
}
|
||||
|
||||
private SendResult sendKernelImpl(final Message msg, //
|
||||
final MessageQueue mq, //
|
||||
final CommunicationMode communicationMode, //
|
||||
final SendCallback sendCallback, //
|
||||
final TopicPublishInfo topicPublishInfo, //
|
||||
private SendResult sendKernelImpl(final Message msg,
|
||||
final MessageQueue mq,
|
||||
final CommunicationMode communicationMode,
|
||||
final SendCallback sendCallback,
|
||||
final TopicPublishInfo topicPublishInfo,
|
||||
final long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName());
|
||||
if (null == brokerAddr) {
|
||||
@@ -674,18 +677,18 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
SendResult sendResult = null;
|
||||
switch (communicationMode) {
|
||||
case ASYNC:
|
||||
sendResult = this.mQClientFactory.getMQClientAPIImpl().sendMessage(//
|
||||
brokerAddr, // 1
|
||||
mq.getBrokerName(), // 2
|
||||
msg, // 3
|
||||
requestHeader, // 4
|
||||
timeout, // 5
|
||||
communicationMode, // 6
|
||||
sendCallback, // 7
|
||||
topicPublishInfo, // 8
|
||||
this.mQClientFactory, // 9
|
||||
this.defaultMQProducer.getRetryTimesWhenSendAsyncFailed(), // 10
|
||||
context, //
|
||||
sendResult = this.mQClientFactory.getMQClientAPIImpl().sendMessage(
|
||||
brokerAddr,
|
||||
mq.getBrokerName(),
|
||||
msg,
|
||||
requestHeader,
|
||||
timeout,
|
||||
communicationMode,
|
||||
sendCallback,
|
||||
topicPublishInfo,
|
||||
this.mQClientFactory,
|
||||
this.defaultMQProducer.getRetryTimesWhenSendAsyncFailed(),
|
||||
context,
|
||||
this);
|
||||
break;
|
||||
case ONEWAY:
|
||||
@@ -863,7 +866,8 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
/**
|
||||
* KERNEL ONEWAY -------------------------------------------------------
|
||||
*/
|
||||
public void sendOneway(Message msg, MessageQueue mq) throws MQClientException, RemotingException, InterruptedException {
|
||||
public void sendOneway(Message msg,
|
||||
MessageQueue mq) throws MQClientException, RemotingException, InterruptedException {
|
||||
this.makeSureStateOK();
|
||||
Validators.checkMessage(msg, this.defaultMQProducer);
|
||||
|
||||
@@ -887,12 +891,12 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
return this.sendSelectImpl(msg, selector, arg, CommunicationMode.SYNC, null, timeout);
|
||||
}
|
||||
|
||||
private SendResult sendSelectImpl(//
|
||||
Message msg, //
|
||||
MessageQueueSelector selector, //
|
||||
Object arg, //
|
||||
final CommunicationMode communicationMode, //
|
||||
final SendCallback sendCallback, final long timeout//
|
||||
private SendResult sendSelectImpl(
|
||||
Message msg,
|
||||
MessageQueueSelector selector,
|
||||
Object arg,
|
||||
final CommunicationMode communicationMode,
|
||||
final SendCallback sendCallback, final long timeout
|
||||
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
this.makeSureStateOK();
|
||||
Validators.checkMessage(msg, this.defaultMQProducer);
|
||||
@@ -945,7 +949,8 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
}
|
||||
}
|
||||
|
||||
public TransactionSendResult sendMessageInTransaction(final Message msg, final LocalTransactionExecuter tranExecuter, final Object arg)
|
||||
public TransactionSendResult sendMessageInTransaction(final Message msg,
|
||||
final LocalTransactionExecuter tranExecuter, final Object arg)
|
||||
throws MQClientException {
|
||||
if (null == tranExecuter) {
|
||||
throw new MQClientException("tranExecutor is null", null);
|
||||
@@ -1013,13 +1018,14 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
/**
|
||||
* DEFAULT SYNC -------------------------------------------------------
|
||||
*/
|
||||
public SendResult send(Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
public SendResult send(
|
||||
Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
return send(msg, this.defaultMQProducer.getSendMsgTimeout());
|
||||
}
|
||||
|
||||
public void endTransaction(//
|
||||
final SendResult sendResult, //
|
||||
final LocalTransactionState localTransactionState, //
|
||||
public void endTransaction(
|
||||
final SendResult sendResult,
|
||||
final LocalTransactionState localTransactionState,
|
||||
final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException {
|
||||
final MessageId id;
|
||||
if (sendResult.getOffsetMsgId() != null) {
|
||||
@@ -1054,7 +1060,8 @@ public class DefaultMQProducerImpl implements MQProducerInner {
|
||||
this.defaultMQProducer.getSendMsgTimeout());
|
||||
}
|
||||
|
||||
public SendResult send(Message msg, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
public SendResult send(Message msg,
|
||||
long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ public interface MQProducerInner {
|
||||
|
||||
TransactionCheckListener checkListener();
|
||||
|
||||
void checkTransactionState(//
|
||||
final String addr, //
|
||||
final MessageExt msg, //
|
||||
void checkTransactionState(
|
||||
final String addr,
|
||||
final MessageExt msg,
|
||||
final CheckTransactionStateRequestHeader checkRequestHeader);
|
||||
|
||||
void updateTopicPublishInfo(final String topic, final TopicPublishInfo info);
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
*/
|
||||
package org.apache.rocketmq.client.log;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.rocketmq.common.constant.LoggerName;
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
|
||||
public class ClientLogger {
|
||||
public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot";
|
||||
public static final String CLIENT_LOG_MAXINDEX = "rocketmq.client.logFileMaxIndex";
|
||||
@@ -31,25 +31,21 @@ public class ClientLogger {
|
||||
|
||||
private static Logger log;
|
||||
|
||||
private static Class logClass = null;
|
||||
|
||||
private static Logger createLogger(final String loggerName) {
|
||||
String logConfigFilePath =
|
||||
System.getProperty("rocketmq.client.log.configFile",
|
||||
System.getenv("ROCKETMQ_CLIENT_LOG_CONFIGFILE"));
|
||||
String logConfigFilePath = System.getProperty("rocketmq.client.log.configFile", System.getenv("ROCKETMQ_CLIENT_LOG_CONFIGFILE"));
|
||||
Boolean isloadconfig =
|
||||
Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true"));
|
||||
Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true"));
|
||||
|
||||
final String log4JResourceFile =
|
||||
System.getProperty("rocketmq.client.log4j.resource.fileName", "log4j_rocketmq_client.xml");
|
||||
System.getProperty("rocketmq.client.log4j.resource.fileName", "log4j_rocketmq_client.xml");
|
||||
|
||||
final String logbackResourceFile =
|
||||
System.getProperty("rocketmq.client.logback.resource.fileName", "logback_rocketmq_client.xml");
|
||||
System.getProperty("rocketmq.client.logback.resource.fileName", "logback_rocketmq_client.xml");
|
||||
|
||||
final String log4J2ResourceFile =
|
||||
System.getProperty("rocketmq.client.log4j2.resource.fileName", "log4j2_rocketmq_client.xml");
|
||||
System.getProperty("rocketmq.client.log4j2.resource.fileName", "log4j2_rocketmq_client.xml");
|
||||
|
||||
String clientLogRoot = System.getProperty(CLIENT_LOG_ROOT, "${user.home}/logs/rocketmqlogs");
|
||||
String clientLogRoot = System.getProperty(CLIENT_LOG_ROOT, System.getProperty("user.home") + "/logs/rocketmqlogs");
|
||||
System.setProperty("client.logRoot", clientLogRoot);
|
||||
String clientLogLevel = System.getProperty(CLIENT_LOG_LEVEL, "INFO");
|
||||
System.setProperty("client.logLevel", clientLogLevel);
|
||||
@@ -85,11 +81,11 @@ public class ClientLogger {
|
||||
if (null == logConfigFilePath) {
|
||||
URL url = ClientLogger.class.getClassLoader().getResource(logbackResourceFile);
|
||||
Method doConfigure =
|
||||
joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class);
|
||||
joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class);
|
||||
doConfigure.invoke(joranConfiguratoroObj, url);
|
||||
} else {
|
||||
Method doConfigure =
|
||||
joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class);
|
||||
joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class);
|
||||
doConfigure.invoke(joranConfiguratoroObj, logConfigFilePath);
|
||||
}
|
||||
|
||||
@@ -102,7 +98,6 @@ public class ClientLogger {
|
||||
initialize.invoke(joranConfigurator, "log4j2", logConfigFilePath);
|
||||
}
|
||||
}
|
||||
logClass = classType;
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ import org.apache.rocketmq.remoting.exception.RemotingException;
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <strong>Thread Safety:</strong> After configuring and starting process, this class can be regarded as thread-safe
|
||||
* and used among multiple threads context.
|
||||
* <strong>Thread Safety:</strong> After configuring and starting process, this class can be regarded as thread-safe
|
||||
* and used among multiple threads context.
|
||||
* </p>
|
||||
*/
|
||||
public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
@@ -137,6 +137,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* Constructor specifying producer group.
|
||||
*
|
||||
* @param producerGroup Producer group, see the name-sake field.
|
||||
*/
|
||||
public DefaultMQProducer(final String producerGroup) {
|
||||
@@ -145,6 +146,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* Constructor specifying the RPC hook.
|
||||
*
|
||||
* @param rpcHook RPC hook to execute per each remoting command execution.
|
||||
*/
|
||||
public DefaultMQProducer(RPCHook rpcHook) {
|
||||
@@ -178,6 +180,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* Fetch message queues of topic <code>topic</code>, 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.
|
||||
@@ -204,12 +207,14 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
* @throws InterruptedException if the sending thread is interrupted.
|
||||
*/
|
||||
@Override
|
||||
public SendResult send(Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
public SendResult send(
|
||||
Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
return this.defaultMQProducerImpl.send(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same to {@link #send(Message)} with send timeout specified in addition.
|
||||
*
|
||||
* @param msg Message to send.
|
||||
* @param timeout send timeout.
|
||||
* @return {@link SendResult} instance to inform senders details of the deliverable, say Message ID of the message,
|
||||
@@ -220,7 +225,8 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
* @throws InterruptedException if the sending thread is interrupted.
|
||||
*/
|
||||
@Override
|
||||
public SendResult send(Message msg, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
public SendResult send(Message msg,
|
||||
long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
return this.defaultMQProducerImpl.send(msg, timeout);
|
||||
}
|
||||
|
||||
@@ -234,6 +240,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
* 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.
|
||||
@@ -241,12 +248,14 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
* @throws InterruptedException if the sending thread is interrupted.
|
||||
*/
|
||||
@Override
|
||||
public void send(Message msg, SendCallback sendCallback) throws MQClientException, RemotingException, InterruptedException {
|
||||
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.
|
||||
@@ -263,6 +272,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
/**
|
||||
* Similar to <a href="https://en.wikipedia.org/wiki/User_Datagram_Protocol">UDP</a>, 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.
|
||||
@@ -275,6 +285,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* 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,
|
||||
@@ -327,6 +338,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -343,6 +355,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -350,12 +363,13 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
* @throws InterruptedException if the sending thread is interrupted.
|
||||
*/
|
||||
@Override
|
||||
public void sendOneway(Message msg, MessageQueue mq) throws MQClientException, RemotingException, InterruptedException {
|
||||
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.
|
||||
* 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.
|
||||
@@ -430,6 +444,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -453,13 +468,15 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
* @throws MQClientException if there is any client error.
|
||||
*/
|
||||
@Override
|
||||
public TransactionSendResult sendMessageInTransaction(Message msg, LocalTransactionExecuter tranExecuter, final Object arg)
|
||||
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
|
||||
@@ -472,6 +489,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* Create a topic on broker.
|
||||
*
|
||||
* @param key accesskey
|
||||
* @param newTopic topic name
|
||||
* @param queueNum topic's queue number
|
||||
@@ -485,6 +503,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* Search consume queue offset of the given time stamp.
|
||||
*
|
||||
* @param mq Instance of MessageQueue
|
||||
* @param timestamp from when in milliseconds.
|
||||
* @return Consume queue offset.
|
||||
@@ -509,6 +528,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -520,6 +540,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* Query earliest message store time.
|
||||
*
|
||||
* @param mq Instance of MessageQueue
|
||||
* @return earliest message store time.
|
||||
* @throws MQClientException if there is any client error.
|
||||
@@ -531,6 +552,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
|
||||
/**
|
||||
* Query message of the given offset message ID.
|
||||
*
|
||||
* @param offsetMsgId message id
|
||||
* @return Message specified.
|
||||
* @throws MQBrokerException if there is any broker error.
|
||||
@@ -539,12 +561,14 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
* @throws InterruptedException if the sending thread is interrupted.
|
||||
*/
|
||||
@Override
|
||||
public MessageExt viewMessage(String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
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
|
||||
@@ -572,7 +596,8 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
* @throws InterruptedException if the sending thread is interrupted.
|
||||
*/
|
||||
@Override
|
||||
public MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
public MessageExt viewMessage(String topic,
|
||||
String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
|
||||
try {
|
||||
MessageId oldMsgId = MessageDecoder.decodeMessageId(msgId);
|
||||
return this.viewMessage(msgId);
|
||||
@@ -582,22 +607,26 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendResult send(Collection<Message> msgs) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
public SendResult send(
|
||||
Collection<Message> msgs) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
return this.defaultMQProducerImpl.send(batch(msgs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendResult send(Collection<Message> msgs, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
public SendResult send(Collection<Message> msgs,
|
||||
long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
return this.defaultMQProducerImpl.send(batch(msgs), timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendResult send(Collection<Message> msgs, MessageQueue messageQueue) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
public SendResult send(Collection<Message> msgs,
|
||||
MessageQueue messageQueue) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
return this.defaultMQProducerImpl.send(batch(msgs), messageQueue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendResult send(Collection<Message> msgs, MessageQueue messageQueue, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
public SendResult send(Collection<Message> msgs, MessageQueue messageQueue,
|
||||
long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
|
||||
return this.defaultMQProducerImpl.send(batch(msgs), messageQueue, timeout);
|
||||
}
|
||||
|
||||
@@ -615,6 +644,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
|
||||
}
|
||||
return msgBatch;
|
||||
}
|
||||
|
||||
public String getProducerGroup() {
|
||||
return producerGroup;
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,5 +19,5 @@ package org.apache.rocketmq.client.producer;
|
||||
import org.apache.rocketmq.common.message.Message;
|
||||
|
||||
public interface LocalTransactionExecuter {
|
||||
public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg);
|
||||
LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.apache.rocketmq.client.producer;
|
||||
|
||||
public interface SendCallback {
|
||||
public void onSuccess(final SendResult sendResult);
|
||||
void onSuccess(final SendResult sendResult);
|
||||
|
||||
public void onException(final Throwable e);
|
||||
void onException(final Throwable e);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ public class SendResult {
|
||||
public SendResult() {
|
||||
}
|
||||
|
||||
public SendResult(SendStatus sendStatus, String msgId, String offsetMsgId, MessageQueue messageQueue, long queueOffset) {
|
||||
public SendResult(SendStatus sendStatus, String msgId, String offsetMsgId, MessageQueue messageQueue,
|
||||
long queueOffset) {
|
||||
this.sendStatus = sendStatus;
|
||||
this.msgId = msgId;
|
||||
this.offsetMsgId = offsetMsgId;
|
||||
@@ -40,7 +41,8 @@ public class SendResult {
|
||||
this.queueOffset = queueOffset;
|
||||
}
|
||||
|
||||
public SendResult(final SendStatus sendStatus, final String msgId, final MessageQueue messageQueue, final long queueOffset, final String transactionId,
|
||||
public SendResult(final SendStatus sendStatus, final String msgId, final MessageQueue messageQueue,
|
||||
final long queueOffset, final String transactionId,
|
||||
final String offsetMsgId, final String regionId) {
|
||||
this.sendStatus = sendStatus;
|
||||
this.msgId = msgId;
|
||||
|
||||
+13
-7
@@ -86,7 +86,8 @@ public class DefaultMQPullConsumerTest {
|
||||
@Test
|
||||
public void testPullMessage_Success() throws Exception {
|
||||
doAnswer(new Answer() {
|
||||
@Override public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
PullMessageRequestHeader requestHeader = mock.getArgument(1);
|
||||
return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
|
||||
}
|
||||
@@ -103,9 +104,10 @@ public class DefaultMQPullConsumerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPullMessage_NotFound() throws Exception{
|
||||
public void testPullMessage_NotFound() throws Exception {
|
||||
doAnswer(new Answer() {
|
||||
@Override public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
PullMessageRequestHeader requestHeader = mock.getArgument(1);
|
||||
return createPullResult(requestHeader, PullStatus.NO_NEW_MSG, new ArrayList<MessageExt>());
|
||||
}
|
||||
@@ -119,7 +121,8 @@ public class DefaultMQPullConsumerTest {
|
||||
@Test
|
||||
public void testPullMessageAsync_Success() throws Exception {
|
||||
doAnswer(new Answer() {
|
||||
@Override public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
PullMessageRequestHeader requestHeader = mock.getArgument(1);
|
||||
PullResult pullResult = createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt()));
|
||||
|
||||
@@ -131,7 +134,8 @@ public class DefaultMQPullConsumerTest {
|
||||
|
||||
MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
|
||||
pullConsumer.pull(messageQueue, "*", 1024, 3, new PullCallback() {
|
||||
@Override public void onSuccess(PullResult pullResult) {
|
||||
@Override
|
||||
public void onSuccess(PullResult pullResult) {
|
||||
assertThat(pullResult).isNotNull();
|
||||
assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND);
|
||||
assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1);
|
||||
@@ -140,13 +144,15 @@ public class DefaultMQPullConsumerTest {
|
||||
assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList<Object>());
|
||||
}
|
||||
|
||||
@Override public void onException(Throwable e) {
|
||||
@Override
|
||||
public void onException(Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus, List<MessageExt> messageExtList) throws Exception {
|
||||
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus,
|
||||
List<MessageExt> messageExtList) throws Exception {
|
||||
return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, new byte[] {});
|
||||
}
|
||||
}
|
||||
+22
-19
@@ -90,7 +90,8 @@ public class DefaultMQPushConsumerTest {
|
||||
pushConsumer.setPullInterval(60 * 1000);
|
||||
|
||||
pushConsumer.registerMessageListener(new MessageListenerConcurrently() {
|
||||
@Override public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
|
||||
@Override
|
||||
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
|
||||
ConsumeConcurrentlyContext context) {
|
||||
return null;
|
||||
}
|
||||
@@ -109,7 +110,6 @@ public class DefaultMQPushConsumerTest {
|
||||
field.setAccessible(true);
|
||||
field.set(pushConsumerImpl, mQClientFactory);
|
||||
|
||||
|
||||
field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
|
||||
field.setAccessible(true);
|
||||
field.set(mQClientFactory, mQClientAPIImpl);
|
||||
@@ -125,21 +125,22 @@ public class DefaultMQPushConsumerTest {
|
||||
when(mQClientFactory.getMQClientAPIImpl().pullMessage(anyString(), any(PullMessageRequestHeader.class),
|
||||
anyLong(), any(CommunicationMode.class), nullable(PullCallback.class)))
|
||||
.thenAnswer(new Answer<Object>() {
|
||||
@Override public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
PullMessageRequestHeader requestHeader = mock.getArgument(1);
|
||||
MessageClientExt messageClientExt = new MessageClientExt();
|
||||
messageClientExt.setTopic(topic);
|
||||
messageClientExt.setQueueId(0);
|
||||
messageClientExt.setMsgId("123");
|
||||
messageClientExt.setBody(new byte[] {'a'});
|
||||
messageClientExt.setOffsetMsgId("234");
|
||||
messageClientExt.setBornHost(new InetSocketAddress(8080));
|
||||
messageClientExt.setStoreHost(new InetSocketAddress(8080));
|
||||
PullResult pullResult = createPullResult(requestHeader, PullStatus.FOUND, Collections.<MessageExt>singletonList(messageClientExt));
|
||||
((PullCallback)mock.getArgument(4)).onSuccess(pullResult);
|
||||
return pullResult;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
PullMessageRequestHeader requestHeader = mock.getArgument(1);
|
||||
MessageClientExt messageClientExt = new MessageClientExt();
|
||||
messageClientExt.setTopic(topic);
|
||||
messageClientExt.setQueueId(0);
|
||||
messageClientExt.setMsgId("123");
|
||||
messageClientExt.setBody(new byte[] {'a'});
|
||||
messageClientExt.setOffsetMsgId("234");
|
||||
messageClientExt.setBornHost(new InetSocketAddress(8080));
|
||||
messageClientExt.setStoreHost(new InetSocketAddress(8080));
|
||||
PullResult pullResult = createPullResult(requestHeader, PullStatus.FOUND, Collections.<MessageExt>singletonList(messageClientExt));
|
||||
((PullCallback) mock.getArgument(4)).onSuccess(pullResult);
|
||||
return pullResult;
|
||||
}
|
||||
});
|
||||
|
||||
doReturn(new FindBrokerResult("127.0.0.1:10911", false)).when(mQClientFactory).findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean());
|
||||
doReturn(Collections.singletonList(mQClientFactory.getClientId())).when(mQClientFactory).findConsumerIdList(anyString(), anyString());
|
||||
@@ -159,7 +160,8 @@ public class DefaultMQPushConsumerTest {
|
||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
final MessageExt[] messageExts = new MessageExt[1];
|
||||
pushConsumer.getDefaultMQPushConsumerImpl().setConsumeMessageService(new ConsumeMessageConcurrentlyService(pushConsumer.getDefaultMQPushConsumerImpl(), new MessageListenerConcurrently() {
|
||||
@Override public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
|
||||
@Override
|
||||
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
|
||||
ConsumeConcurrentlyContext context) {
|
||||
messageExts[0] = msgs.get(0);
|
||||
countDownLatch.countDown();
|
||||
@@ -217,7 +219,8 @@ public class DefaultMQPushConsumerTest {
|
||||
return pullRequest;
|
||||
}
|
||||
|
||||
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus, List<MessageExt> messageExtList) throws Exception {
|
||||
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus,
|
||||
List<MessageExt> messageExtList) throws Exception {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
for (MessageExt messageExt : messageExtList) {
|
||||
outputStream.write(MessageDecoder.encode(messageExt, false));
|
||||
|
||||
+22
-23
@@ -29,7 +29,6 @@ import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class AllocateMessageQueueConsitentHashTest {
|
||||
|
||||
private String topic;
|
||||
@@ -40,8 +39,6 @@ public class AllocateMessageQueueConsitentHashTest {
|
||||
topic = "topic_test";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void printMessageQueue(List<MessageQueue> messageQueueList, String name) {
|
||||
if (messageQueueList == null || messageQueueList.size() < 1)
|
||||
return;
|
||||
@@ -85,28 +82,27 @@ public class AllocateMessageQueueConsitentHashTest {
|
||||
|
||||
@Test
|
||||
public void testAllocate1() {
|
||||
testAllocate(20,10);
|
||||
testAllocate(20, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllocate2() {
|
||||
testAllocate(10,20);
|
||||
testAllocate(10, 20);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRun100RandomCase(){
|
||||
for(int i=0;i<100;i++){
|
||||
int consumerSize = new Random().nextInt(200)+1;//1-200
|
||||
int queueSize = new Random().nextInt(100)+1;//1-100
|
||||
testAllocate(queueSize,consumerSize);
|
||||
public void testRun100RandomCase() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int consumerSize = new Random().nextInt(20) + 1;//1-20
|
||||
int queueSize = new Random().nextInt(20) + 1;//1-20
|
||||
testAllocate(queueSize, consumerSize);
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testAllocate(int queueSize, int consumerSize) {
|
||||
AllocateMessageQueueStrategy allocateMessageQueueConsistentHash = new AllocateMessageQueueConsistentHash(3);
|
||||
|
||||
@@ -133,7 +129,7 @@ public class AllocateMessageQueueConsitentHashTest {
|
||||
}
|
||||
|
||||
Assert.assertTrue(
|
||||
verifyAllocateAll(cidBegin,mqAll, allocatedResAll));
|
||||
verifyAllocateAll(cidBegin, mqAll, allocatedResAll));
|
||||
}
|
||||
|
||||
Map<MessageQueue, String> allocateToAllAfterRemoveOne = new TreeMap<MessageQueue, String>();
|
||||
@@ -162,7 +158,7 @@ public class AllocateMessageQueueConsitentHashTest {
|
||||
//System.out.println("rs[" + cid + "]:" + "[" + rs.size() + "]" + rs.toString());
|
||||
}
|
||||
|
||||
Assert.assertTrue("queueSize"+queueSize+"consumerSize:"+consumerSize+"\nmqAll:"+mqAll+"\nallocatedResAllAfterRemove"+allocatedResAllAfterRemove,
|
||||
Assert.assertTrue("queueSize" + queueSize + "consumerSize:" + consumerSize + "\nmqAll:" + mqAll + "\nallocatedResAllAfterRemove" + allocatedResAllAfterRemove,
|
||||
verifyAllocateAll(cidAfterRemoveOne, mqAll, allocatedResAllAfterRemove));
|
||||
verifyAfterRemove(allocateToAllOrigin, allocateToAllAfterRemoveOne, removeCID);
|
||||
}
|
||||
@@ -170,7 +166,7 @@ public class AllocateMessageQueueConsitentHashTest {
|
||||
List<String> cidAfterAdd = new ArrayList<String>(cidAfterRemoveOne);
|
||||
//test allocate add one more cid
|
||||
{
|
||||
String newCid = CID_PREFIX+"NEW";
|
||||
String newCid = CID_PREFIX + "NEW";
|
||||
//System.out.println("add one more cid "+newCid);
|
||||
cidAfterAdd.add(newCid);
|
||||
List<MessageQueue> mqShouldOnlyChanged = new ArrayList<MessageQueue>();
|
||||
@@ -182,7 +178,7 @@ public class AllocateMessageQueueConsitentHashTest {
|
||||
allocatedResAllAfterAdd.addAll(rs);
|
||||
for (MessageQueue mq : rs) {
|
||||
allocateToAll3.put(mq, cid);
|
||||
if (cid.equals(newCid)){
|
||||
if (cid.equals(newCid)) {
|
||||
mqShouldOnlyChanged.add(mq);
|
||||
}
|
||||
}
|
||||
@@ -190,19 +186,21 @@ public class AllocateMessageQueueConsitentHashTest {
|
||||
}
|
||||
|
||||
Assert.assertTrue(
|
||||
verifyAllocateAll(cidAfterAdd,mqAll, allocatedResAllAfterAdd));
|
||||
verifyAllocateAll(cidAfterAdd, mqAll, allocatedResAllAfterAdd));
|
||||
verifyAfterAdd(allocateToAllAfterRemoveOne, allocateToAll3, newCid);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean verifyAllocateAll(List<String> cidAll,List<MessageQueue> mqAll, List<MessageQueue> allocatedResAll) {
|
||||
if (cidAll.isEmpty()){
|
||||
private boolean verifyAllocateAll(List<String> cidAll, List<MessageQueue> mqAll,
|
||||
List<MessageQueue> allocatedResAll) {
|
||||
if (cidAll.isEmpty()) {
|
||||
return allocatedResAll.isEmpty();
|
||||
}
|
||||
return mqAll.containsAll(allocatedResAll) && allocatedResAll.containsAll(mqAll);
|
||||
}
|
||||
|
||||
private void verifyAfterRemove(Map<MessageQueue, String> allocateToBefore, Map<MessageQueue, String> allocateAfter, String removeCID) {
|
||||
private void verifyAfterRemove(Map<MessageQueue, String> allocateToBefore, Map<MessageQueue, String> allocateAfter,
|
||||
String removeCID) {
|
||||
for (MessageQueue mq : allocateToBefore.keySet()) {
|
||||
String allocateToOrigin = allocateToBefore.get(mq);
|
||||
if (allocateToOrigin.equals(removeCID)) {
|
||||
@@ -213,14 +211,15 @@ public class AllocateMessageQueueConsitentHashTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyAfterAdd(Map<MessageQueue, String> allocateBefore, Map<MessageQueue, String> allocateAfter, String newCID) {
|
||||
private void verifyAfterAdd(Map<MessageQueue, String> allocateBefore, Map<MessageQueue, String> allocateAfter,
|
||||
String newCID) {
|
||||
for (MessageQueue mq : allocateAfter.keySet()) {
|
||||
String allocateToOrigin = allocateBefore.get(mq);
|
||||
String allocateToAfter = allocateAfter.get(mq);
|
||||
if (allocateToAfter.equals(newCID)) {
|
||||
|
||||
} else {//the rest queue should be the same
|
||||
Assert.assertTrue("it was allocated to "+allocateToOrigin+". Now, it is to "+allocateAfter.get(mq)+" mq:"+mq,allocateAfter.get(mq).equals(allocateToOrigin));//should be the same
|
||||
Assert.assertTrue("it was allocated to " + allocateToOrigin + ". Now, it is to " + allocateAfter.get(mq) + " mq:" + mq, allocateAfter.get(mq).equals(allocateToOrigin));//should be the same
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -99,7 +99,8 @@ public class RemoteBrokerOffsetStoreTest {
|
||||
final MessageQueue messageQueue = new MessageQueue(topic, brokerName, 3);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
@Override public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
UpdateConsumerOffsetRequestHeader updateRequestHeader = mock.getArgument(1);
|
||||
when(mqClientAPI.queryConsumerOffset(anyString(), any(QueryConsumerOffsetRequestHeader.class), anyLong())).thenReturn(updateRequestHeader.getCommitOffset());
|
||||
return null;
|
||||
@@ -123,8 +124,6 @@ public class RemoteBrokerOffsetStoreTest {
|
||||
assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1025);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testRemoveOffset() throws Exception {
|
||||
OffsetStore offsetStore = new RemoteBrokerOffsetStore(mQClientFactory, group);
|
||||
|
||||
@@ -107,7 +107,8 @@ public class MQClientAPIImplTest {
|
||||
@Test
|
||||
public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException {
|
||||
doAnswer(new Answer() {
|
||||
@Override public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
RemotingCommand request = mock.getArgument(1);
|
||||
return createSuccessResponse(request);
|
||||
}
|
||||
@@ -127,7 +128,8 @@ public class MQClientAPIImplTest {
|
||||
@Test
|
||||
public void testSendMessageSync_WithException() throws InterruptedException, RemotingException, MQBrokerException {
|
||||
doAnswer(new Answer() {
|
||||
@Override public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
RemotingCommand request = mock.getArgument(1);
|
||||
RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class);
|
||||
response.setCode(ResponseCode.SYSTEM_ERROR);
|
||||
@@ -156,7 +158,8 @@ public class MQClientAPIImplTest {
|
||||
assertThat(sendResult).isNull();
|
||||
|
||||
doAnswer(new Answer() {
|
||||
@Override public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock mock) throws Throwable {
|
||||
InvokeCallback callback = mock.getArgument(3);
|
||||
RemotingCommand request = mock.getArgument(1);
|
||||
ResponseFuture responseFuture = new ResponseFuture(request.getOpaque(), 3 * 1000, null, null);
|
||||
@@ -169,14 +172,16 @@ public class MQClientAPIImplTest {
|
||||
sendMessageContext.setProducer(new DefaultMQProducerImpl(new DefaultMQProducer()));
|
||||
mqClientAPI.sendMessage(brokerAddr, brokerName, msg, new SendMessageRequestHeader(), 3 * 1000, CommunicationMode.ASYNC,
|
||||
new SendCallback() {
|
||||
@Override public void onSuccess(SendResult sendResult) {
|
||||
@Override
|
||||
public void onSuccess(SendResult sendResult) {
|
||||
assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
|
||||
assertThat(sendResult.getOffsetMsgId()).isEqualTo("123");
|
||||
assertThat(sendResult.getQueueOffset()).isEqualTo(123L);
|
||||
assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Override public void onException(Throwable e) {
|
||||
@Override
|
||||
public void onException(Throwable e) {
|
||||
}
|
||||
},
|
||||
null, null, 0, sendMessageContext, defaultMQProducerImpl);
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MQClientInstanceTest {
|
||||
private MQClientInstance mqClientInstance = MQClientManager.getInstance().getAndCreateMQClientInstance(new ClientConfig());
|
||||
private MQClientInstance mqClientInstance = MQClientManager.getInstance().getAndCreateMQClientInstance(new ClientConfig());
|
||||
private String topic = "FooBar";
|
||||
private String group = "FooBarGroup";
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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.log;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Date;
|
||||
|
||||
public class ClientLogTest {
|
||||
|
||||
public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot";
|
||||
public static final String LOG_DIR;
|
||||
|
||||
static {
|
||||
LOG_DIR = System.getProperty(CLIENT_LOG_ROOT, "${user.home}/logs/rocketmqlogs");
|
||||
}
|
||||
|
||||
// FIXME: Workarond for concret implementation for slf4j, is there any better solution for all slf4j implementations in one class ? 2017/8/1
|
||||
@Test
|
||||
public void testLog4j2() throws IOException, NoSuchFieldException, IllegalAccessException {
|
||||
ClientLogger.getLog();
|
||||
long seek = 0;
|
||||
boolean result = false;
|
||||
File file = new File(LOG_DIR + File.separator + "rocketmq_client.log");
|
||||
if (file.exists()) {
|
||||
seek = file.length();
|
||||
}
|
||||
Field logClassField = ClientLogger.class.getDeclaredField("logClass");
|
||||
logClassField.setAccessible(true);
|
||||
Class logClass = (Class) logClassField.get(ClientLogger.class);
|
||||
Assert.assertEquals("org.apache.logging.slf4j.Log4jLoggerFactory", logClass.getName());
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ClientLogger.getLog().info("testcase testLog4j2 " + new Date());
|
||||
}
|
||||
|
||||
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
|
||||
randomAccessFile.seek(seek);
|
||||
String line = randomAccessFile.readLine();
|
||||
int idx = 1;
|
||||
while (line != null) {
|
||||
if (line.contains("testLog4j2")) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
line = randomAccessFile.readLine();
|
||||
idx++;
|
||||
if (idx > 20) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
randomAccessFile.close();
|
||||
Assert.assertTrue(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.log;
|
||||
|
||||
import org.apache.rocketmq.common.UtilAll;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ClientLoggerTest {
|
||||
|
||||
public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot";
|
||||
public static final String LOG_DIR;
|
||||
|
||||
static {
|
||||
LOG_DIR = System.getProperty(CLIENT_LOG_ROOT, System.getProperty("user.home") + "/logs/rocketmqlogs");
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void cleanFiles() {
|
||||
UtilAll.deleteFile(new File(LOG_DIR));
|
||||
}
|
||||
|
||||
// FIXME: Workaround for concrete implementation for slf4j, is there any better solution for all slf4j implementations in one class ? 2017/8/1
|
||||
@Test
|
||||
public void testLog4j2() throws Exception {
|
||||
Logger logger = ClientLogger.getLog();
|
||||
|
||||
System.out.println(logger);
|
||||
assertEquals("org.apache.logging.slf4j.Log4jLogger", logger.getClass().getName());
|
||||
}
|
||||
}
|
||||
+12
-6
@@ -149,13 +149,16 @@ public class DefaultMQProducerTest {
|
||||
final Throwable[] assertionErrors = new Throwable[1];
|
||||
final CountDownLatch countDownLatch = new CountDownLatch(2);
|
||||
producer.getDefaultMQProducerImpl().registerSendMessageHook(new SendMessageHook() {
|
||||
@Override public String hookName() {
|
||||
@Override
|
||||
public String hookName() {
|
||||
return "TestHook";
|
||||
}
|
||||
|
||||
@Override public void sendMessageBefore(final SendMessageContext context) {
|
||||
@Override
|
||||
public void sendMessageBefore(final SendMessageContext context) {
|
||||
assertionErrors[0] = assertInOtherThread(new Runnable() {
|
||||
@Override public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(context.getMessage()).isEqualTo(message);
|
||||
assertThat(context.getProducer()).isEqualTo(producer);
|
||||
assertThat(context.getCommunicationMode()).isEqualTo(CommunicationMode.SYNC);
|
||||
@@ -165,9 +168,11 @@ public class DefaultMQProducerTest {
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
|
||||
@Override public void sendMessageAfter(final SendMessageContext context) {
|
||||
@Override
|
||||
public void sendMessageAfter(final SendMessageContext context) {
|
||||
assertionErrors[0] = assertInOtherThread(new Runnable() {
|
||||
@Override public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(context.getMessage()).isEqualTo(message);
|
||||
assertThat(context.getProducer()).isEqualTo(producer.getDefaultMQProducerImpl());
|
||||
assertThat(context.getCommunicationMode()).isEqualTo(CommunicationMode.SYNC);
|
||||
@@ -229,7 +234,8 @@ public class DefaultMQProducerTest {
|
||||
private Throwable assertInOtherThread(final Runnable runnable) {
|
||||
final Throwable[] assertionErrors = new Throwable[1];
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (AssertionError e) {
|
||||
|
||||
@@ -54,7 +54,8 @@ public class BrokerConfig {
|
||||
private String messageStorePlugIn = "";
|
||||
|
||||
/**
|
||||
* thread numbers for send message thread pool, since spin lock will be used by default since 4.0.x, the default value is 1.
|
||||
* thread numbers for send message thread pool, since spin lock will be used by default since 4.0.x, the default
|
||||
* value is 1.
|
||||
*/
|
||||
private int sendMessageThreadPoolNums = 1; //16 + Runtime.getRuntime().availableProcessors() * 4;
|
||||
private int pullMessageThreadPoolNums = 16 + Runtime.getRuntime().availableProcessors() * 2;
|
||||
|
||||
@@ -65,7 +65,6 @@ public class Configuration {
|
||||
/**
|
||||
* register config object
|
||||
*
|
||||
* @param configObject
|
||||
* @return the current Configuration object
|
||||
*/
|
||||
public Configuration registerConfig(Object configObject) {
|
||||
@@ -91,7 +90,6 @@ public class Configuration {
|
||||
/**
|
||||
* register config properties
|
||||
*
|
||||
* @param extProperties
|
||||
* @return the current Configuration object
|
||||
*/
|
||||
public Configuration registerConfig(Properties extProperties) {
|
||||
@@ -117,8 +115,6 @@ public class Configuration {
|
||||
/**
|
||||
* The store path will be gotten from the field of object.
|
||||
*
|
||||
* @param object
|
||||
* @param fieldName
|
||||
* @throws java.lang.RuntimeException if the field of object is not exist.
|
||||
*/
|
||||
public void setStorePathFromConfig(Object object, String fieldName) {
|
||||
|
||||
@@ -29,7 +29,8 @@ public class CountDownLatch2 {
|
||||
/**
|
||||
* Constructs a {@code CountDownLatch2} initialized with the given count.
|
||||
*
|
||||
* @param count the number of times {@link #countDown} must be invoked before threads can pass through {@link #await}
|
||||
* @param count the number of times {@link #countDown} must be invoked before threads can pass through {@link
|
||||
* #await}
|
||||
* @throws IllegalArgumentException if {@code count} is negative
|
||||
*/
|
||||
public CountDownLatch2(int count) {
|
||||
@@ -104,7 +105,8 @@ public class CountDownLatch2 {
|
||||
*
|
||||
* @param timeout the maximum time to wait
|
||||
* @param unit the time unit of the {@code timeout} argument
|
||||
* @return {@code true} if the count reached zero and {@code false} if the waiting time elapsed before the count reached zero
|
||||
* @return {@code true} if the count reached zero and {@code false} if the waiting time elapsed before the count
|
||||
* reached zero
|
||||
* @throws InterruptedException if the current thread is interrupted while waiting
|
||||
*/
|
||||
public boolean await(long timeout, TimeUnit unit)
|
||||
@@ -176,7 +178,7 @@ public class CountDownLatch2 {
|
||||
|
||||
protected boolean tryReleaseShared(int releases) {
|
||||
// Decrement count; signal when transition to zero
|
||||
for (;;) {
|
||||
for (; ; ) {
|
||||
int c = getState();
|
||||
if (c == 0)
|
||||
return false;
|
||||
|
||||
@@ -74,7 +74,7 @@ public class DataVersion extends RemotingSerializable {
|
||||
int result = (int) (timestamp ^ (timestamp >>> 32));
|
||||
if (null != counter) {
|
||||
long l = counter.get();
|
||||
result = 31 * result + (int)(l ^ (l >>> 32));
|
||||
result = 31 * result + (int) (l ^ (l >>> 32));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -26,20 +26,17 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import org.apache.rocketmq.common.annotation.ImportantField;
|
||||
import org.apache.rocketmq.common.constant.LoggerName;
|
||||
@@ -58,8 +55,8 @@ public class MixAll {
|
||||
public static final String DEFAULT_NAMESRV_ADDR_LOOKUP = "jmenv.tbsite.net";
|
||||
public static final String WS_DOMAIN_NAME = System.getProperty("rocketmq.namesrv.domain", DEFAULT_NAMESRV_ADDR_LOOKUP);
|
||||
public static final String WS_DOMAIN_SUBGROUP = System.getProperty("rocketmq.namesrv.domain.subgroup", "nsaddr");
|
||||
// // http://jmenv.tbsite.net:8080/rocketmq/nsaddr
|
||||
// public static final String WS_ADDR = "http://" + WS_DOMAIN_NAME + ":8080/rocketmq/" + WS_DOMAIN_SUBGROUP;
|
||||
//http://jmenv.tbsite.net:8080/rocketmq/nsaddr
|
||||
//public static final String WS_ADDR = "http://" + WS_DOMAIN_NAME + ":8080/rocketmq/" + WS_DOMAIN_SUBGROUP;
|
||||
public static final String DEFAULT_TOPIC = "TBW102";
|
||||
public static final String BENCHMARK_TOPIC = "BenchmarkTest";
|
||||
public static final String DEFAULT_PRODUCER_GROUP = "DEFAULT_PRODUCER";
|
||||
@@ -141,16 +138,6 @@ public class MixAll {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static long createBrokerId(final String ip, final int port) {
|
||||
InetSocketAddress isa = new InetSocketAddress(ip, port);
|
||||
byte[] ipArray = isa.getAddress().getAddress();
|
||||
ByteBuffer bb = ByteBuffer.allocate(8);
|
||||
bb.put(ipArray);
|
||||
bb.putInt(port);
|
||||
long value = bb.getLong(0);
|
||||
return Math.abs(value);
|
||||
}
|
||||
|
||||
public static void string2File(final String str, final String fileName) throws IOException {
|
||||
|
||||
String tmpFile = fileName + ".tmp";
|
||||
@@ -169,7 +156,6 @@ public class MixAll {
|
||||
file.renameTo(new File(fileName));
|
||||
}
|
||||
|
||||
|
||||
public static void string2FileNotSafe(final String str, final String fileName) throws IOException {
|
||||
File file = new File(fileName);
|
||||
File fileParent = file.getParentFile();
|
||||
@@ -241,16 +227,12 @@ public class MixAll {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String findClassPath(Class<?> c) {
|
||||
URL url = c.getProtectionDomain().getCodeSource().getLocation();
|
||||
return url.getPath();
|
||||
}
|
||||
|
||||
public static void printObjectProperties(final Logger logger, final Object object) {
|
||||
printObjectProperties(logger, object, false);
|
||||
}
|
||||
|
||||
public static void printObjectProperties(final Logger logger, final Object object, final boolean onlyImportantField) {
|
||||
public static void printObjectProperties(final Logger logger, final Object object,
|
||||
final boolean onlyImportantField) {
|
||||
Field[] fields = object.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (!Modifier.isStatic(field.getModifiers())) {
|
||||
@@ -394,25 +376,54 @@ public class MixAll {
|
||||
return inetAddressList;
|
||||
}
|
||||
|
||||
public static boolean isLocalAddr(String address) {
|
||||
for (String addr : LOCAL_INET_ADDRESS) {
|
||||
if (address.contains(addr))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String localhost() {
|
||||
try {
|
||||
InetAddress addr = InetAddress.getLocalHost();
|
||||
return addr.getHostAddress();
|
||||
return InetAddress.getLocalHost().getHostAddress();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException"
|
||||
+ FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION),
|
||||
e);
|
||||
try {
|
||||
String candidatesHost = getLocalhostByNetworkInterface();
|
||||
if (candidatesHost != null)
|
||||
return candidatesHost;
|
||||
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException" + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), e);
|
||||
}
|
||||
}
|
||||
|
||||
//Reverse logic comparing to RemotingUtil method, consider refactor in RocketMQ 5.0
|
||||
public static String getLocalhostByNetworkInterface() throws SocketException {
|
||||
List<String> candidatesHost = new ArrayList<String>();
|
||||
Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
|
||||
|
||||
while (enumeration.hasMoreElements()) {
|
||||
NetworkInterface networkInterface = enumeration.nextElement();
|
||||
// Workaround for docker0 bridge
|
||||
if ("docker0".equals(networkInterface.getName()) || !networkInterface.isUp()) {
|
||||
continue;
|
||||
}
|
||||
Enumeration<InetAddress> addrs = networkInterface.getInetAddresses();
|
||||
while (addrs.hasMoreElements()) {
|
||||
InetAddress address = addrs.nextElement();
|
||||
if (address.isLoopbackAddress()) {
|
||||
continue;
|
||||
}
|
||||
//ip4 highter priority
|
||||
if (address instanceof Inet6Address) {
|
||||
candidatesHost.add(address.getHostAddress());
|
||||
continue;
|
||||
}
|
||||
return address.getHostAddress();
|
||||
}
|
||||
}
|
||||
|
||||
if (!candidatesHost.isEmpty()) {
|
||||
return candidatesHost.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean compareAndIncreaseOnly(final AtomicLong target, final long value) {
|
||||
long prev = target.get();
|
||||
while (value > prev) {
|
||||
@@ -426,16 +437,6 @@ public class MixAll {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String localhostName() {
|
||||
try {
|
||||
return InetAddress.getLocalHost().getHostName();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException"
|
||||
+ FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION),
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String humanReadableByteCount(long bytes, boolean si) {
|
||||
int unit = si ? 1000 : 1024;
|
||||
if (bytes < unit)
|
||||
@@ -445,19 +446,4 @@ public class MixAll {
|
||||
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
|
||||
}
|
||||
|
||||
public Set<String> list2Set(List<String> values) {
|
||||
Set<String> result = new HashSet<String>();
|
||||
for (String v : values) {
|
||||
result.add(v);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<String> set2List(Set<String> values) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
for (String v : values) {
|
||||
result.add(v);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class ServiceThread implements Runnable {
|
||||
}
|
||||
long eclipseTime = System.currentTimeMillis() - beginTime;
|
||||
log.info("join thread " + this.getServiceName() + " eclipse time(ms) " + eclipseTime + " "
|
||||
+ this.getJointime());
|
||||
+ this.getJointime());
|
||||
} catch (InterruptedException e) {
|
||||
log.error("Interrupted", e);
|
||||
}
|
||||
|
||||
@@ -46,24 +46,14 @@ public class TopicConfig {
|
||||
|
||||
public String encode() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 1
|
||||
sb.append(this.topicName);
|
||||
sb.append(SEPARATOR);
|
||||
|
||||
// 2
|
||||
sb.append(this.readQueueNums);
|
||||
sb.append(SEPARATOR);
|
||||
|
||||
// 3
|
||||
sb.append(this.writeQueueNums);
|
||||
sb.append(SEPARATOR);
|
||||
|
||||
// 4
|
||||
sb.append(this.perm);
|
||||
sb.append(SEPARATOR);
|
||||
|
||||
// 5
|
||||
sb.append(this.topicFilterType);
|
||||
|
||||
return sb.toString();
|
||||
|
||||
@@ -209,7 +209,6 @@ public class UtilAll {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public static int crc32(byte[] array) {
|
||||
if (array != null) {
|
||||
return crc32(array, 0, array.length);
|
||||
@@ -218,7 +217,6 @@ public class UtilAll {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public static int crc32(byte[] array, int offset, int length) {
|
||||
CRC32 crc32 = new CRC32();
|
||||
crc32.update(array, offset, length);
|
||||
@@ -505,4 +503,19 @@ public class UtilAll {
|
||||
throw new RuntimeException("Can not get local ip", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteFile(File file) {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
if (file.isFile()) {
|
||||
file.delete();
|
||||
} else if (file.isDirectory()) {
|
||||
File[] files = file.listFiles();
|
||||
for (File file1 : files) {
|
||||
deleteFile(file1);
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-11
@@ -25,20 +25,18 @@ import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* To hash Node objects to a hash ring with a certain amount of virtual node.
|
||||
* Method routeNode will return a Node instance which the object key should be allocated to according to consistent hash algorithm
|
||||
*
|
||||
* @param <T>
|
||||
* Method routeNode will return a Node instance which the object key should be allocated to according to consistent hash
|
||||
* algorithm
|
||||
*/
|
||||
public class ConsistentHashRouter<T extends Node> {
|
||||
private final SortedMap<Long, VirtualNode<T>> ring = new TreeMap<Long, VirtualNode<T>>();
|
||||
private final HashFunction hashFunction;
|
||||
|
||||
public ConsistentHashRouter(Collection<T> pNodes, int vNodeCount) {
|
||||
this(pNodes,vNodeCount, new MD5Hash());
|
||||
this(pNodes, vNodeCount, new MD5Hash());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pNodes collections of physical nodes
|
||||
* @param vNodeCount amounts of virtual nodes
|
||||
* @param hashFunction hash Function to hash Node instances
|
||||
@@ -57,11 +55,13 @@ public class ConsistentHashRouter<T extends Node> {
|
||||
|
||||
/**
|
||||
* add physic node to the hash ring with some virtual nodes
|
||||
*
|
||||
* @param pNode physical node needs added to hash ring
|
||||
* @param vNodeCount the number of virtual node of the physical node. Value should be greater than or equals to 0
|
||||
*/
|
||||
public void addNode(T pNode, int vNodeCount) {
|
||||
if (vNodeCount < 0) throw new IllegalArgumentException("illegal virtual node counts :" + vNodeCount);
|
||||
if (vNodeCount < 0)
|
||||
throw new IllegalArgumentException("illegal virtual node counts :" + vNodeCount);
|
||||
int existingReplicas = getExistingReplicas(pNode);
|
||||
for (int i = 0; i < vNodeCount; i++) {
|
||||
VirtualNode<T> vNode = new VirtualNode<T>(pNode, i + existingReplicas);
|
||||
@@ -71,7 +71,6 @@ public class ConsistentHashRouter<T extends Node> {
|
||||
|
||||
/**
|
||||
* remove the physical node from the hash ring
|
||||
* @param pNode
|
||||
*/
|
||||
public void removeNode(T pNode) {
|
||||
Iterator<Long> it = ring.keySet().iterator();
|
||||
@@ -86,20 +85,19 @@ public class ConsistentHashRouter<T extends Node> {
|
||||
|
||||
/**
|
||||
* with a specified key, route the nearest Node instance in the current hash ring
|
||||
*
|
||||
* @param objectKey the object key to find a nearest Node
|
||||
* @return
|
||||
*/
|
||||
public T routeNode(String objectKey) {
|
||||
if (ring.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Long hashVal = hashFunction.hash(objectKey);
|
||||
SortedMap<Long,VirtualNode<T>> tailMap = ring.tailMap(hashVal);
|
||||
SortedMap<Long, VirtualNode<T>> tailMap = ring.tailMap(hashVal);
|
||||
Long nodeHashVal = !tailMap.isEmpty() ? tailMap.firstKey() : ring.firstKey();
|
||||
return ring.get(nodeHashVal).getPhysicalNode();
|
||||
}
|
||||
|
||||
|
||||
public int getExistingReplicas(T pNode) {
|
||||
int replicas = 0;
|
||||
for (VirtualNode<T> vNode : ring.values()) {
|
||||
@@ -110,7 +108,6 @@ public class ConsistentHashRouter<T extends Node> {
|
||||
return replicas;
|
||||
}
|
||||
|
||||
|
||||
//default hash function
|
||||
private static class MD5Hash implements HashFunction {
|
||||
MessageDigest instance;
|
||||
|
||||
@@ -21,7 +21,6 @@ package org.apache.rocketmq.common.consistenthash;
|
||||
*/
|
||||
public interface Node {
|
||||
/**
|
||||
*
|
||||
* @return the key which will be used for hash mapping
|
||||
*/
|
||||
String getKey();
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.apache.rocketmq.common.consistenthash;
|
||||
|
||||
|
||||
public class VirtualNode<T extends Node> implements Node {
|
||||
final T physicalNode;
|
||||
final int replicaIndex;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class FilterAPI {
|
||||
}
|
||||
|
||||
public static SubscriptionData build(final String topic, final String subString,
|
||||
final String type) throws Exception {
|
||||
final String type) throws Exception {
|
||||
if (ExpressionType.TAG.equals(type) || type == null) {
|
||||
return buildSubscriptionData(null, topic, subString);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ public class PolishExpr {
|
||||
* Shunting-yard algorithm <br/>
|
||||
* http://en.wikipedia.org/wiki/Shunting_yard_algorithm
|
||||
*
|
||||
* @param tokens
|
||||
* @return the compute result of Shunting-yard algorithm
|
||||
*/
|
||||
public static List<Op> reversePolish(List<Op> tokens) {
|
||||
|
||||
@@ -18,44 +18,44 @@ package org.apache.rocketmq.common.help;
|
||||
|
||||
public class FAQUrl {
|
||||
|
||||
public static final String APPLY_TOPIC_URL = //
|
||||
public static final String APPLY_TOPIC_URL =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String NAME_SERVER_ADDR_NOT_EXIST_URL = //
|
||||
public static final String NAME_SERVER_ADDR_NOT_EXIST_URL =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String GROUP_NAME_DUPLICATE_URL = //
|
||||
public static final String GROUP_NAME_DUPLICATE_URL =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String CLIENT_PARAMETER_CHECK_URL = //
|
||||
public static final String CLIENT_PARAMETER_CHECK_URL =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String SUBSCRIPTION_GROUP_NOT_EXIST = //
|
||||
public static final String SUBSCRIPTION_GROUP_NOT_EXIST =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String CLIENT_SERVICE_NOT_OK = //
|
||||
public static final String CLIENT_SERVICE_NOT_OK =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
// FAQ: No route info of this topic, TopicABC
|
||||
public static final String NO_TOPIC_ROUTE_INFO = //
|
||||
public static final String NO_TOPIC_ROUTE_INFO =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String LOAD_JSON_EXCEPTION = //
|
||||
public static final String LOAD_JSON_EXCEPTION =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String SAME_GROUP_DIFFERENT_TOPIC = //
|
||||
public static final String SAME_GROUP_DIFFERENT_TOPIC =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String MQLIST_NOT_EXIST = //
|
||||
public static final String MQLIST_NOT_EXIST =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String UNEXPECTED_EXCEPTION_URL = //
|
||||
public static final String UNEXPECTED_EXCEPTION_URL =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String SEND_MSG_FAILED = //
|
||||
public static final String SEND_MSG_FAILED =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
public static final String UNKNOWN_HOST_EXCEPTION = //
|
||||
public static final String UNKNOWN_HOST_EXCEPTION =
|
||||
"http://rocketmq.apache.org/docs/faq/";
|
||||
|
||||
private static final String TIP_STRING_BEGIN = "\nSee ";
|
||||
|
||||
@@ -42,7 +42,7 @@ public class MessageClientIDSetter {
|
||||
tempBuffer.put(createFakeIP());
|
||||
}
|
||||
tempBuffer.position(6);
|
||||
tempBuffer.putInt(MessageClientIDSetter.class.getClassLoader().hashCode()); //4
|
||||
tempBuffer.putInt(MessageClientIDSetter.class.getClassLoader().hashCode());
|
||||
FIX_STRING = UtilAll.bytes2string(tempBuffer.array());
|
||||
setStartTime(System.currentTimeMillis());
|
||||
COUNTER = new AtomicInteger(0);
|
||||
|
||||
@@ -98,7 +98,6 @@ public class MessageDecoder {
|
||||
* Just decode properties from msg buffer.
|
||||
*
|
||||
* @param byteBuffer msg commit log buffer.
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> decodeProperties(java.nio.ByteBuffer byteBuffer) {
|
||||
int topicLengthPosition = BODY_SIZE_POSITION + 4 + byteBuffer.getInt(BODY_SIZE_POSITION);
|
||||
@@ -239,8 +238,6 @@ public class MessageDecoder {
|
||||
return byteBuffer.array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static MessageExt decode(
|
||||
java.nio.ByteBuffer byteBuffer, final boolean readBody, final boolean deCompressBody) {
|
||||
return decode(byteBuffer, readBody, deCompressBody, false);
|
||||
@@ -414,7 +411,6 @@ public class MessageDecoder {
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
public static byte[] encodeMessage(Message message) {
|
||||
//only need flag, body, properties
|
||||
byte[] body = message.getBody();
|
||||
@@ -488,9 +484,9 @@ public class MessageDecoder {
|
||||
|
||||
public static byte[] encodeMessages(List<Message> messages) {
|
||||
//TO DO refactor, accumulate in one buffer, avoid copies
|
||||
List<byte[]> encodedMessages = new ArrayList<byte[]>(messages.size());
|
||||
List<byte[]> encodedMessages = new ArrayList<byte[]>(messages.size());
|
||||
int allSize = 0;
|
||||
for (Message message: messages) {
|
||||
for (Message message : messages) {
|
||||
byte[] tmp = encodeMessage(message);
|
||||
encodedMessages.add(tmp);
|
||||
allSize += tmp.length;
|
||||
@@ -504,7 +500,6 @@ public class MessageDecoder {
|
||||
return allBytes;
|
||||
}
|
||||
|
||||
|
||||
public static List<Message> decodeMessages(ByteBuffer byteBuffer) throws Exception {
|
||||
//TO DO add a callback for processing, avoid creating lists
|
||||
List<Message> msgs = new ArrayList<Message>();
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
* (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
|
||||
* 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.
|
||||
* 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.message;
|
||||
@@ -23,13 +23,11 @@ public class MessageExtBatch extends MessageExt {
|
||||
|
||||
private static final long serialVersionUID = -2353110995348498537L;
|
||||
|
||||
|
||||
public ByteBuffer wrap() {
|
||||
assert getBody() != null;
|
||||
return ByteBuffer.wrap(getBody(), 0, getBody().length);
|
||||
return ByteBuffer.wrap(getBody(), 0, getBody().length);
|
||||
}
|
||||
|
||||
|
||||
private ByteBuffer encodedBuff;
|
||||
|
||||
public ByteBuffer getEncodedBuff() {
|
||||
|
||||
@@ -162,7 +162,6 @@ public class RequestCode {
|
||||
*/
|
||||
public static final int GET_NAMESRV_CONFIG = 319;
|
||||
|
||||
|
||||
public static final int SEND_BATCH_MESSAGE = 320;
|
||||
|
||||
public static final int QUERY_CONSUME_QUEUE = 321;
|
||||
|
||||
+47
-47
@@ -130,15 +130,15 @@ public class ConsumerRunningInfo extends RemotingSerializable {
|
||||
if (orderMsg) {
|
||||
|
||||
if (!pq.isLocked()) {
|
||||
sb.append(String.format("%s %s can't lock for a while, %dms%n", //
|
||||
clientId, //
|
||||
mq, //
|
||||
sb.append(String.format("%s %s can't lock for a while, %dms%n",
|
||||
clientId,
|
||||
mq,
|
||||
System.currentTimeMillis() - pq.getLastLockTimestamp()));
|
||||
} else {
|
||||
if (pq.isDroped() && (pq.getTryUnlockTimes() > 0)) {
|
||||
sb.append(String.format("%s %s unlock %d times, still failed%n", //
|
||||
clientId, //
|
||||
mq, //
|
||||
sb.append(String.format("%s %s unlock %d times, still failed%n",
|
||||
clientId,
|
||||
mq,
|
||||
pq.getTryUnlockTimes()));
|
||||
}
|
||||
}
|
||||
@@ -147,9 +147,9 @@ public class ConsumerRunningInfo extends RemotingSerializable {
|
||||
long diff = System.currentTimeMillis() - pq.getLastConsumeTimestamp();
|
||||
|
||||
if (diff > (1000 * 60) && pq.getCachedMsgCount() > 0) {
|
||||
sb.append(String.format("%s %s can't consume for a while, maybe blocked, %dms%n", //
|
||||
clientId, //
|
||||
mq, //
|
||||
sb.append(String.format("%s %s can't consume for a while, maybe blocked, %dms%n",
|
||||
clientId,
|
||||
mq,
|
||||
diff));
|
||||
}
|
||||
}
|
||||
@@ -211,10 +211,10 @@ public class ConsumerRunningInfo extends RemotingSerializable {
|
||||
int i = 0;
|
||||
while (it.hasNext()) {
|
||||
SubscriptionData next = it.next();
|
||||
String item = String.format("%03d Topic: %-40s ClassFilter: %-8s SubExpression: %s%n", //
|
||||
++i, //
|
||||
next.getTopic(), //
|
||||
next.isClassFilterMode(), //
|
||||
String item = String.format("%03d Topic: %-40s ClassFilter: %-8s SubExpression: %s%n",
|
||||
++i,
|
||||
next.getTopic(),
|
||||
next.isClassFilterMode(),
|
||||
next.getSubString());
|
||||
|
||||
sb.append(item);
|
||||
@@ -223,20 +223,20 @@ public class ConsumerRunningInfo extends RemotingSerializable {
|
||||
|
||||
{
|
||||
sb.append("\n\n#Consumer Offset#\n");
|
||||
sb.append(String.format("%-32s %-32s %-4s %-20s%n", //
|
||||
"#Topic", //
|
||||
"#Broker Name", //
|
||||
"#QID", //
|
||||
"#Consumer Offset"//
|
||||
sb.append(String.format("%-32s %-32s %-4s %-20s%n",
|
||||
"#Topic",
|
||||
"#Broker Name",
|
||||
"#QID",
|
||||
"#Consumer Offset"
|
||||
));
|
||||
|
||||
Iterator<Entry<MessageQueue, ProcessQueueInfo>> it = this.mqTable.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<MessageQueue, ProcessQueueInfo> next = it.next();
|
||||
String item = String.format("%-32s %-32s %-4d %-20d%n", //
|
||||
next.getKey().getTopic(), //
|
||||
next.getKey().getBrokerName(), //
|
||||
next.getKey().getQueueId(), //
|
||||
String item = String.format("%-32s %-32s %-4d %-20d%n",
|
||||
next.getKey().getTopic(),
|
||||
next.getKey().getBrokerName(),
|
||||
next.getKey().getQueueId(),
|
||||
next.getValue().getCommitOffset());
|
||||
|
||||
sb.append(item);
|
||||
@@ -245,20 +245,20 @@ public class ConsumerRunningInfo extends RemotingSerializable {
|
||||
|
||||
{
|
||||
sb.append("\n\n#Consumer MQ Detail#\n");
|
||||
sb.append(String.format("%-32s %-32s %-4s %-20s%n", //
|
||||
"#Topic", //
|
||||
"#Broker Name", //
|
||||
"#QID", //
|
||||
"#ProcessQueueInfo"//
|
||||
sb.append(String.format("%-32s %-32s %-4s %-20s%n",
|
||||
"#Topic",
|
||||
"#Broker Name",
|
||||
"#QID",
|
||||
"#ProcessQueueInfo"
|
||||
));
|
||||
|
||||
Iterator<Entry<MessageQueue, ProcessQueueInfo>> it = this.mqTable.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<MessageQueue, ProcessQueueInfo> next = it.next();
|
||||
String item = String.format("%-32s %-32s %-4d %s%n", //
|
||||
next.getKey().getTopic(), //
|
||||
next.getKey().getBrokerName(), //
|
||||
next.getKey().getQueueId(), //
|
||||
String item = String.format("%-32s %-32s %-4d %s%n",
|
||||
next.getKey().getTopic(),
|
||||
next.getKey().getBrokerName(),
|
||||
next.getKey().getQueueId(),
|
||||
next.getValue().toString());
|
||||
|
||||
sb.append(item);
|
||||
@@ -267,27 +267,27 @@ public class ConsumerRunningInfo extends RemotingSerializable {
|
||||
|
||||
{
|
||||
sb.append("\n\n#Consumer RT&TPS#\n");
|
||||
sb.append(String.format("%-32s %14s %14s %14s %14s %18s %25s%n", //
|
||||
"#Topic", //
|
||||
"#Pull RT", //
|
||||
"#Pull TPS", //
|
||||
"#Consume RT", //
|
||||
"#ConsumeOK TPS", //
|
||||
"#ConsumeFailed TPS", //
|
||||
"#ConsumeFailedMsgsInHour"//
|
||||
sb.append(String.format("%-32s %14s %14s %14s %14s %18s %25s%n",
|
||||
"#Topic",
|
||||
"#Pull RT",
|
||||
"#Pull TPS",
|
||||
"#Consume RT",
|
||||
"#ConsumeOK TPS",
|
||||
"#ConsumeFailed TPS",
|
||||
"#ConsumeFailedMsgsInHour"
|
||||
));
|
||||
|
||||
Iterator<Entry<String, ConsumeStatus>> it = this.statusTable.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, ConsumeStatus> next = it.next();
|
||||
String item = String.format("%-32s %14.2f %14.2f %14.2f %14.2f %18.2f %25d%n", //
|
||||
next.getKey(), //
|
||||
next.getValue().getPullRT(), //
|
||||
next.getValue().getPullTPS(), //
|
||||
next.getValue().getConsumeRT(), //
|
||||
next.getValue().getConsumeOKTPS(), //
|
||||
next.getValue().getConsumeFailedTPS(), //
|
||||
next.getValue().getConsumeFailedMsgs()//
|
||||
String item = String.format("%-32s %14.2f %14.2f %14.2f %14.2f %18.2f %25d%n",
|
||||
next.getKey(),
|
||||
next.getValue().getPullRT(),
|
||||
next.getValue().getPullTPS(),
|
||||
next.getValue().getConsumeRT(),
|
||||
next.getValue().getConsumeOKTPS(),
|
||||
next.getValue().getConsumeFailedTPS(),
|
||||
next.getValue().getConsumeFailedMsgs()
|
||||
);
|
||||
|
||||
sb.append(item);
|
||||
|
||||
-2
@@ -27,8 +27,6 @@ public class GetConsumeStatsRequestHeader implements CommandCustomHeader {
|
||||
|
||||
@Override
|
||||
public void checkFields() throws RemotingCommandException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public String getConsumerGroup() {
|
||||
|
||||
-1
@@ -32,7 +32,6 @@ public class GetConsumerStatusRequestHeader implements CommandCustomHeader {
|
||||
|
||||
@Override
|
||||
public void checkFields() throws RemotingCommandException {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
public String getTopic() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user