Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
360341e
[ROCKETMQ-3] Remove try...catch, using assertNull etc
Dec 26, 2016
f1552f6
[ROCKETMQ-13] Wrong log level for AcceptSocketService termination.
shroman Dec 26, 2016
e8deb23
[ROCKETMQ-9] Errors in rocketmq-store module.
shroman Dec 26, 2016
b856459
[ROCKETMQ-9] Clean up the code
WillemJiang Dec 27, 2016
1aca01f
Remove redundant groupId statement if it is stardard maven plugin
vongosling Dec 23, 2016
2a43743
ROCKETMQ-3 Clean up the unit test code of rocketmq-store
WillemJiang Dec 23, 2016
915be84
ROCKETMQ-3 Clean up the unit test code of rocketmq-client
WillemJiang Dec 23, 2016
e91312e
ROCKETMQ-2 [ROCKETMQ-2] Closing the channel closes apache/incubator-r…
shroman Dec 23, 2016
3a409f7
merge from apache/incubator-rocketmq
lollipopjin Dec 27, 2016
f74f2eb
ROCKETMQ-14 closes apache/incubator-rocketmq#19 *Won't fix: We could …
lollipopjin Dec 29, 2016
5919c91
由于 clientconfig 在获取本地 ip 时,ipv4获取最后一个 ip,致使在双网卡的环境中,如果最后一个 ip 对应的是外网 …
tain198127 Jan 12, 2017
06b0b15
fix the last pull request error
tain198127 Jan 12, 2017
64594ed
Merge remote-tracking branch 'upstream/master'
tain198127 Jan 13, 2017
4311d26
增加了编译和合并的脚本。
tain198127 Jan 13, 2017
8965764
Merge branch 'master' of https://github.com/lollipopjin/incubator-roc…
tain198127 Jan 17, 2017
9178b8e
Merge remote-tracking branch 'upstream/master'
tain198127 Jan 17, 2017
d178a6f
Revert "IntegrateASF sonar"
tain198127 Jan 17, 2017
accaf72
Revert "Remove script command in travis config file"
tain198127 Jan 17, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ jdk:
- oraclejdk7
- openjdk7

#script:
# - travis_retry mvn --batch-mode clean apache-rat:check
# - travis_wait 60 mvn --batch-mode clean package findbugs:check
script:
- travis_retry mvn --batch-mode clean apache-rat:check
- travis_wait 60 mvn --batch-mode clean package findbugs:check

after_success:
- mvn clean apache-rat:check cobertura:cobertura coveralls:report
- mvn clean cobertura:cobertura coveralls:report
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* 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.
Expand All @@ -8,28 +8,39 @@
*
* 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.broker;
package com.alibaba.rocketmq.broker;

import org.apache.rocketmq.common.BrokerConfig;
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
import org.apache.rocketmq.remoting.netty.NettyServerConfig;
import org.apache.rocketmq.store.config.MessageStoreConfig;
import com.alibaba.rocketmq.common.BrokerConfig;
import com.alibaba.rocketmq.remoting.netty.NettyClientConfig;
import com.alibaba.rocketmq.remoting.netty.NettyServerConfig;
import com.alibaba.rocketmq.store.config.MessageStoreConfig;
<<<<<<< HEAD
import org.junit.Test;
=======
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
>>>>>>> b85645996a573b19159ad184007484a99742cc5f

/**
* @author shtykh_roman
*/
public class BrokerControllerTest {
private static final int RESTART_NUM = 3;
<<<<<<< HEAD
=======
protected Logger logger = LoggerFactory.getLogger(BrokerControllerTest.class);

>>>>>>> b85645996a573b19159ad184007484a99742cc5f
private static final int RESTART_NUM = 3;

/**
* Tests if the controller can be properly stopped and started.
*
Expand All @@ -45,13 +56,20 @@ public void testRestart() throws Exception {
new NettyClientConfig(), //
new MessageStoreConfig());
boolean initResult = brokerController.initialize();
<<<<<<< HEAD
System.out.println("initialize " + initResult);
brokerController.start();

brokerController.shutdown();
=======
Assert.assertTrue(initResult);
logger.info("Broker is initialized " + initResult);
brokerController.start();
logger.info("Broker is started");

brokerController.shutdown();
logger.info("Broker is stopped");
>>>>>>> b85645996a573b19159ad184007484a99742cc5f
}
}
}
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -X
40 changes: 40 additions & 0 deletions client/src/main/java/org/apache/rocketmq/client/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
import org.apache.rocketmq.common.UtilAll;
import org.apache.rocketmq.remoting.common.RemotingUtil;

import java.util.ArrayList;
import java.util.List;

/**
* Client Common configuration
*/
public class ClientConfig {
public static final String SEND_MESSAGE_WITH_VIP_CHANNEL_PROPERTY = "com.rocketmq.sendMessageWithVIPChannel";
private String namesrvAddr = System.getProperty(MixAll.NAMESRV_ADDR_PROPERTY, System.getenv(MixAll.NAMESRV_ADDR_ENV));
private String clientIP = RemotingUtil.getLocalAddress();
private List<String> clientIPArray = RemotingUtil.getLocalAddressArray();
private boolean isClientIPReplaced = false;
private String instanceName = System.getProperty("rocketmq.client.name", "DEFAULT");
private int clientCallbackExecutorThreads = Runtime.getRuntime().availableProcessors();
/**
Expand Down Expand Up @@ -63,7 +68,42 @@ public String getClientIP() {
return clientIP;
}

/**
* to match the right ip,
* side effort:if the candidate is only one,the clientIP will be replace by the first candidate
* @param ipPattern:ip parttern,if ipPattern is null or empty,will return all the candidate, e.g:10.1.2
*
*
* @return ip candidate list
*/
public List<String> computeClientIP(String ipPattern) {
List<String> rstIPArray = new ArrayList<String>(this.clientIPArray.size());
if (ipPattern != null && !ipPattern.isEmpty())
{
for (String ip : this.clientIPArray)
{
if (ip.contains(ipPattern))
rstIPArray.add(ip);
}
if (!isClientIPReplaced && rstIPArray.size() <= 0)
throw new RuntimeException("you do not have ip address pls use ifconfig to check you ip");

if (!isClientIPReplaced && rstIPArray.size() == 1)
this.setClientIP(rstIPArray.get(0));
} else {
rstIPArray.addAll(this.clientIPArray);
}
if (rstIPArray.size() > 1 && !isClientIPReplaced)
try {
throw new RuntimeException("you have more than one ip address, pls use <computeClientIP> to avoid it ,or use <setClientIP>");
}
catch (Exception e) {
e.printStackTrace();
}
return rstIPArray;
}
public void setClientIP(String clientIP) {
isClientIPReplaced = true;
this.clientIP = clientIP;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public DefaultMQProducer(RPCHook rpcHook) {
*/
@Override
public void start() throws MQClientException {
this.computeClientIP(null);
this.defaultMQProducerImpl.start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;
import org.junit.Test;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;


public class SimpleConsumerProducerTest {
private static final String TOPIC_TEST = "TopicTest-fundmng";

@Test
public void producerConsumerTest() throws MQClientException, InterruptedException, IOException {
System.setProperty("rocketmq.namesrv.domain", "jmenv.tbsite.alipay.net");

DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("S_fundmng_demo_producer");
DefaultMQProducer producer = new DefaultMQProducer("P_fundmng_demo_producer");
//producer.computeClientIP("10.1.33");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
consumer.subscribe(TOPIC_TEST, null);

final AtomicLong lastReceivedMills = new AtomicLong(System.currentTimeMillis());

final AtomicLong consumeTimes = new AtomicLong(0);

consumer.registerMessageListener(new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(final List<MessageExt> msgs,
final ConsumeConcurrentlyContext context) {
System.out.println("Received" + consumeTimes.incrementAndGet() + "messages !");

lastReceivedMills.set(System.currentTimeMillis());

return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});

consumer.start();
producer.start();

for (int i = 0; i < 100; i++) {
try {
Message msg = new Message(TOPIC_TEST, ("Hello RocketMQ " + i).getBytes());
SendResult sendResult = producer.send(msg);
System.out.println(sendResult);
} catch (Exception e) {
System.err.println(e.toString());
TimeUnit.SECONDS.sleep(1);
}
}

// // wait no messages
while ((System.currentTimeMillis() - lastReceivedMills.get()) < 5000) {
TimeUnit.MILLISECONDS.sleep(200);
}

consumer.shutdown();
producer.shutdown();
}
}
3 changes: 3 additions & 0 deletions merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
git fetch upstream
git checkout master
git merge upstream/master
15 changes: 2 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<artifactId>rocketmq-all</artifactId>
<version>4.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Apache RocketMQ git s${project.version}</name>
<name>rocketmq-all ${project.version}</name>
<url>http://rocketmq.incubator.apache.org/</url>

<prerequisites>
Expand All @@ -42,8 +42,7 @@
<scm>
<url>https://git-wip-us.apache.org/repos/asf/incubator-rocketmq.git</url>
<connection>scm:git:https://git-wip-us.apache.org/repos/asf/incubator-rocketmq.git</connection>
<developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/incubator-rocketmq.git
</developerConnection>
<developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/incubator-rocketmq.git</developerConnection>
</scm>

<mailingLists>
Expand Down Expand Up @@ -158,11 +157,6 @@
<!-- compiler settings properties -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>

<!-- URL of the ASF SonarQube server -->
<sonar.host.url>https://builds.apache.org/analysis</sonar.host.url>
<!-- Exclude all generated code -->
<sonar.exclusions>file:**/generated-sources/**</sonar.exclusions>
</properties>

<modules>
Expand Down Expand Up @@ -343,11 +337,6 @@
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.4</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.0.2</version>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.SelectorProvider;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -91,8 +94,9 @@ public static Selector openSelector() throws IOException {
public static boolean isLinuxPlatform() {
return isLinuxPlatform;
}

public static String getLocalAddress() {
public static List<String> getLocalAddressArray()
{
ArrayList<String> rstIP = new ArrayList<String>();
try {
// Traversal Network interface to get the first non-loopback and non-private address
Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
Expand All @@ -119,17 +123,17 @@ public static String getLocalAddress() {
if (ip.startsWith("127.0") || ip.startsWith("192.168")) {
continue;
}
rstIP.add(ip);

return ip;
}

return ipv4Result.get(ipv4Result.size() - 1);
//to adapt old rocketmq,make the last ent address be the first
Collections.reverse(rstIP);
} else if (!ipv6Result.isEmpty()) {
return ipv6Result.get(0);
rstIP.addAll(ipv6Result);
} else {
rstIP.add(normalizeHostAddress(InetAddress.getLocalHost()));
}
//If failed to find,fall back to localhost
final InetAddress localHost = InetAddress.getLocalHost();
return normalizeHostAddress(localHost);
return rstIP;
} catch (SocketException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
Expand All @@ -138,6 +142,14 @@ public static String getLocalAddress() {

return null;
}
public static String getLocalAddress() {
final List<String> address = getLocalAddressArray();
if (address != null && !address.isEmpty()) {
return address.get(0);
}

return null;
}

public static String normalizeHostAddress(final InetAddress localHost) {
if (localHost instanceof Inet6Address) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.apache.rocketmq.remoting;


import org.apache.rocketmq.remoting.common.RemotingUtil;
import org.junit.Test;

import java.util.List;

/**
* Created by tain on 2017/1/11.
*/
public class LocalAddressTest {
@Test
public void getLoacalAddress()
{
List address = RemotingUtil.getLocalAddressArray();
System.out.println(address);
}
}
Loading