From 32e6333a73e72a8282aa0d26bac38136a0c6d747 Mon Sep 17 00:00:00 2001 From: Nottyjay <891084418@qq.com> Date: Thu, 22 Dec 2016 18:11:46 +0800 Subject: [PATCH 1/5] Null check is not needed -- can't be null when reaches this point. --- .../client/impl/consumer/DefaultMQPullConsumerImpl.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/rocketmq-client/src/main/java/com/alibaba/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java b/rocketmq-client/src/main/java/com/alibaba/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java index 1785ec92075..61f1fb69a4f 100644 --- a/rocketmq-client/src/main/java/com/alibaba/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java +++ b/rocketmq-client/src/main/java/com/alibaba/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java @@ -598,14 +598,6 @@ private void checkConfig() throws MQClientException { // check consumerGroup Validators.checkGroup(this.defaultMQPullConsumer.getConsumerGroup()); - // consumerGroup - if (null == this.defaultMQPullConsumer.getConsumerGroup()) { - throw new MQClientException( - "consumerGroup is null" // - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // - null); - } - // consumerGroup if (this.defaultMQPullConsumer.getConsumerGroup().equals(MixAll.DEFAULT_CONSUMER_GROUP)) { throw new MQClientException( From d7b162a7ba609dc976e3e67b0610f30efa28b562 Mon Sep 17 00:00:00 2001 From: Nottyjay Date: Sun, 25 Dec 2016 22:28:55 +0800 Subject: [PATCH 2/5] Add namesrv config file --- conf/namesrv.conf | 19 ++++++++++ .../common/namesrv/NamesrvConfig.java | 10 ++++++ .../rocketmq/namesrv/NamesrvStartup.java | 36 +++++++++++-------- 3 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 conf/namesrv.conf diff --git a/conf/namesrv.conf b/conf/namesrv.conf new file mode 100644 index 00000000000..64a44d53ff6 --- /dev/null +++ b/conf/namesrv.conf @@ -0,0 +1,19 @@ +# 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. + +# rocketMQ nameserver port config +# you can change it at here, and it will take effect at next start-up. +# default port is 9876 +port=9876 \ No newline at end of file diff --git a/rocketmq-common/src/main/java/com/alibaba/rocketmq/common/namesrv/NamesrvConfig.java b/rocketmq-common/src/main/java/com/alibaba/rocketmq/common/namesrv/NamesrvConfig.java index 08db35794cc..5b8de16deba 100644 --- a/rocketmq-common/src/main/java/com/alibaba/rocketmq/common/namesrv/NamesrvConfig.java +++ b/rocketmq-common/src/main/java/com/alibaba/rocketmq/common/namesrv/NamesrvConfig.java @@ -43,6 +43,8 @@ public class NamesrvConfig { private boolean clusterTest = false; private boolean orderMessageEnable = false; + private int port = 9876; + public boolean isOrderMessageEnable() { return orderMessageEnable; } @@ -97,4 +99,12 @@ public String getConfigStorePath() { public void setConfigStorePath(final String configStorePath) { this.configStorePath = configStorePath; } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } } diff --git a/rocketmq-namesrv/src/main/java/com/alibaba/rocketmq/namesrv/NamesrvStartup.java b/rocketmq-namesrv/src/main/java/com/alibaba/rocketmq/namesrv/NamesrvStartup.java index 286de3a6e33..bf369c93ccb 100644 --- a/rocketmq-namesrv/src/main/java/com/alibaba/rocketmq/namesrv/NamesrvStartup.java +++ b/rocketmq-namesrv/src/main/java/com/alibaba/rocketmq/namesrv/NamesrvStartup.java @@ -79,22 +79,28 @@ public static NamesrvController main0(String[] args) { final NamesrvConfig namesrvConfig = new NamesrvConfig(); final NettyServerConfig nettyServerConfig = new NettyServerConfig(); - nettyServerConfig.setListenPort(9876); - if (commandLine.hasOption('c')) { - String file = commandLine.getOptionValue('c'); - if (file != null) { - InputStream in = new BufferedInputStream(new FileInputStream(file)); - properties = new Properties(); - properties.load(in); - MixAll.properties2Object(properties, namesrvConfig); - MixAll.properties2Object(properties, nettyServerConfig); - - namesrvConfig.setConfigStorePath(file); - - System.out.printf("load config properties file OK, " + file + "%n"); - in.close(); - } + String file = null; + + if (commandLine.hasOption('c')) + file = commandLine.getOptionValue('c'); + else + file = namesrvConfig.getRocketmqHome() + "/conf/namesrv.conf"; + + if (file != null) { + InputStream in = new BufferedInputStream(new FileInputStream(file)); + properties = new Properties(); + properties.load(in); + MixAll.properties2Object(properties, namesrvConfig); + MixAll.properties2Object(properties, nettyServerConfig); + + namesrvConfig.setConfigStorePath(file); + + System.out.printf("load config properties file OK, " + file + "%n"); + in.close(); + }else{ + System.out.print("load config properties file failed, please ensure " + file + " can read%n"); } + nettyServerConfig.setListenPort(namesrvConfig.getPort()); if (commandLine.hasOption('p')) { From 12f978c6abdd1853afb49164b0efe1049a13dabe Mon Sep 17 00:00:00 2001 From: Nottyjay Date: Mon, 26 Dec 2016 00:28:37 +0800 Subject: [PATCH 3/5] NameServerConnector Test unit --- .../broker/NameServerConnectorTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 rocketmq-broker/src/test/java/com/alibaba/rocketmq/broker/NameServerConnectorTest.java diff --git a/rocketmq-broker/src/test/java/com/alibaba/rocketmq/broker/NameServerConnectorTest.java b/rocketmq-broker/src/test/java/com/alibaba/rocketmq/broker/NameServerConnectorTest.java new file mode 100644 index 00000000000..56ecf56f384 --- /dev/null +++ b/rocketmq-broker/src/test/java/com/alibaba/rocketmq/broker/NameServerConnectorTest.java @@ -0,0 +1,28 @@ +package com.alibaba.rocketmq.broker; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author nottyjay + * @date 2016/12/25 + */ +public class NameServerConnectorTest { + + private static final Logger LOG = LoggerFactory.getLogger(BrokerControllerTest.class); + + @Test + public void testConnectorWithDefaultPort() throws Exception { + BrokerStartup.start(BrokerStartup.createBrokerController(new String[]{"-n", "localhost:9876"})); + Thread.sleep(6000); + BrokerStartup.createBrokerController(new String[]{"-c"}); + } + + @Test + public void testConnectorWithOtherPort() throws Exception { + BrokerStartup.start(BrokerStartup.createBrokerController(new String[]{"-n", "localhost:12345"})); + Thread.sleep(6000); + BrokerStartup.createBrokerController(new String[]{"-c"}); + } +} \ No newline at end of file From 54aab0b122377d0175fbc4ad972b946fead02a3e Mon Sep 17 00:00:00 2001 From: Nottyjay <891084418@qq.com> Date: Mon, 26 Dec 2016 14:31:54 +0800 Subject: [PATCH 4/5] Add broker config --- conf/broker.conf | 5 +++ .../rocketmq/broker/BrokerStartup.java | 41 +++++++++++-------- .../alibaba/rocketmq/common/BrokerConfig.java | 8 ++++ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/conf/broker.conf b/conf/broker.conf index 6ca12f1db85..1e65a102387 100644 --- a/conf/broker.conf +++ b/conf/broker.conf @@ -20,3 +20,8 @@ deleteWhen=04 fileReservedTime=48 brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH + +# rocketMQ broker port config +# you can change it at here, and it will take effect at next start-up. +# default port is 10911 +port=10911 diff --git a/rocketmq-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java b/rocketmq-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java index 7e81117fa27..c1032fedd28 100644 --- a/rocketmq-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java +++ b/rocketmq-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java @@ -100,7 +100,6 @@ public static BrokerController createBrokerController(String[] args) { final BrokerConfig brokerConfig = new BrokerConfig(); final NettyServerConfig nettyServerConfig = new NettyServerConfig(); final NettyClientConfig nettyClientConfig = new NettyClientConfig(); - nettyServerConfig.setListenPort(10911); final MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); if (BrokerRole.SLAVE == messageStoreConfig.getBrokerRole()) { @@ -122,24 +121,30 @@ public static BrokerController createBrokerController(String[] args) { System.exit(0); } - if (commandLine.hasOption('c')) { - String file = commandLine.getOptionValue('c'); - if (file != null) { - configFile = file; - InputStream in = new BufferedInputStream(new FileInputStream(file)); - properties = new Properties(); - properties.load(in); - - parsePropertie2SystemEnv(properties); - MixAll.properties2Object(properties, brokerConfig); - MixAll.properties2Object(properties, nettyServerConfig); - MixAll.properties2Object(properties, nettyClientConfig); - MixAll.properties2Object(properties, messageStoreConfig); - - BrokerPathConfigHelper.setBrokerConfigPath(file); - in.close(); - } + String file = null; + if (commandLine.hasOption('c')) + file = commandLine.getOptionValue('c'); + else + file = brokerConfig.getRocketmqHome() + "/conf/namesrv.conf"; + + if (file != null) { + configFile = file; + InputStream in = new BufferedInputStream(new FileInputStream(file)); + properties = new Properties(); + properties.load(in); + + parsePropertie2SystemEnv(properties); + MixAll.properties2Object(properties, brokerConfig); + MixAll.properties2Object(properties, nettyServerConfig); + MixAll.properties2Object(properties, nettyClientConfig); + MixAll.properties2Object(properties, messageStoreConfig); + + BrokerPathConfigHelper.setBrokerConfigPath(file); + in.close(); + }else{ + System.out.print("load config properties file failed, please ensure " + file + " can read%n"); } + nettyServerConfig.setListenPort(brokerConfig.getPort()); MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), brokerConfig); diff --git a/rocketmq-common/src/main/java/com/alibaba/rocketmq/common/BrokerConfig.java b/rocketmq-common/src/main/java/com/alibaba/rocketmq/common/BrokerConfig.java index 6eae0a74295..a8ce511d81e 100644 --- a/rocketmq-common/src/main/java/com/alibaba/rocketmq/common/BrokerConfig.java +++ b/rocketmq-common/src/main/java/com/alibaba/rocketmq/common/BrokerConfig.java @@ -41,6 +41,7 @@ public class BrokerConfig { @ImportantField private long brokerId = MixAll.MASTER_ID; private int brokerPermission = PermName.PERM_READ | PermName.PERM_WRITE; + private int port = 10911; private int defaultTopicQueueNums = 8; @ImportantField private boolean autoCreateTopicEnable = true; @@ -263,6 +264,13 @@ public void setBrokerClusterName(String brokerClusterName) { this.brokerClusterName = brokerClusterName; } + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } public String getBrokerIP1() { return brokerIP1; From bb1f2c70d8f80743b481105a75bba7bbe96cc4e5 Mon Sep 17 00:00:00 2001 From: Nottyjay <891084418@qq.com> Date: Mon, 26 Dec 2016 14:32:52 +0800 Subject: [PATCH 5/5] change print message --- .../main/java/com/alibaba/rocketmq/broker/BrokerStartup.java | 2 +- .../java/com/alibaba/rocketmq/namesrv/NamesrvStartup.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rocketmq-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java b/rocketmq-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java index c1032fedd28..f4fda05c098 100644 --- a/rocketmq-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java +++ b/rocketmq-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java @@ -142,7 +142,7 @@ public static BrokerController createBrokerController(String[] args) { BrokerPathConfigHelper.setBrokerConfigPath(file); in.close(); }else{ - System.out.print("load config properties file failed, please ensure " + file + " can read%n"); + System.out.print("load config properties file failed, please make sure that the file: " + file + " is readable%n"); } nettyServerConfig.setListenPort(brokerConfig.getPort()); diff --git a/rocketmq-namesrv/src/main/java/com/alibaba/rocketmq/namesrv/NamesrvStartup.java b/rocketmq-namesrv/src/main/java/com/alibaba/rocketmq/namesrv/NamesrvStartup.java index bf369c93ccb..698d01e5a34 100644 --- a/rocketmq-namesrv/src/main/java/com/alibaba/rocketmq/namesrv/NamesrvStartup.java +++ b/rocketmq-namesrv/src/main/java/com/alibaba/rocketmq/namesrv/NamesrvStartup.java @@ -79,8 +79,8 @@ public static NamesrvController main0(String[] args) { final NamesrvConfig namesrvConfig = new NamesrvConfig(); final NettyServerConfig nettyServerConfig = new NettyServerConfig(); - String file = null; + String file = null; if (commandLine.hasOption('c')) file = commandLine.getOptionValue('c'); else @@ -98,7 +98,7 @@ public static NamesrvController main0(String[] args) { System.out.printf("load config properties file OK, " + file + "%n"); in.close(); }else{ - System.out.print("load config properties file failed, please ensure " + file + " can read%n"); + System.out.print("load config properties file failed, please make sure that the file: " + file + " is readable%n"); } nettyServerConfig.setListenPort(namesrvConfig.getPort());