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/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-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java b/rocketmq-broker/src/main/java/com/alibaba/rocketmq/broker/BrokerStartup.java index 7e81117fa27..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 @@ -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 make sure that the file: " + file + " is readable%n"); } + nettyServerConfig.setListenPort(brokerConfig.getPort()); MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), brokerConfig); 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 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( 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; 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..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,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 make sure that the file: " + file + " is readable%n"); } + nettyServerConfig.setListenPort(namesrvConfig.getPort()); if (commandLine.hasOption('p')) {