Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
9fc0ce45
R
Rocketmq
项目概览
小五666\n哈哈
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9fc0ce45
编写于
1月 31, 2019
作者:
D
duhenglucky
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish snode register process
上级
8f517779
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
143 addition
and
24 deletion
+143
-24
snode/src/main/java/org/apache/rocketmq/snode/client/impl/SlowConsumerServiceImpl.java
...e/rocketmq/snode/client/impl/SlowConsumerServiceImpl.java
+0
-1
snode/src/main/java/org/apache/rocketmq/snode/processor/mqtthandler/MqttSubscribeMessageHandler.java
...de/processor/mqtthandler/MqttSubscribeMessageHandler.java
+5
-4
snode/src/main/java/org/apache/rocketmq/snode/service/NnodeService.java
.../java/org/apache/rocketmq/snode/service/NnodeService.java
+19
-4
snode/src/main/java/org/apache/rocketmq/snode/service/impl/EnodeServiceImpl.java
.../apache/rocketmq/snode/service/impl/EnodeServiceImpl.java
+2
-2
snode/src/main/java/org/apache/rocketmq/snode/service/impl/NnodeServiceImpl.java
.../apache/rocketmq/snode/service/impl/NnodeServiceImpl.java
+4
-1
snode/src/main/java/org/apache/rocketmq/snode/service/impl/ScheduledServiceImpl.java
...che/rocketmq/snode/service/impl/ScheduledServiceImpl.java
+6
-1
snode/src/test/java/org/apache/rocketmq/snode/processor/SendMessageProcessorTest.java
...he/rocketmq/snode/processor/SendMessageProcessorTest.java
+4
-5
snode/src/test/java/org/apache/rocketmq/snode/service/EnodeServiceImplTest.java
...g/apache/rocketmq/snode/service/EnodeServiceImplTest.java
+16
-6
snode/src/test/java/org/apache/rocketmq/snode/service/NnodeServiceImplTest.java
...g/apache/rocketmq/snode/service/NnodeServiceImplTest.java
+87
-0
未找到文件。
snode/src/main/java/org/apache/rocketmq/snode/client/impl/SlowConsumerServiceImpl.java
浏览文件 @
9fc0ce45
...
...
@@ -41,7 +41,6 @@ public class SlowConsumerServiceImpl implements SlowConsumerService {
log
.
warn
(
"[SlowConsumer] group: {}, lastAckedOffset:{} nowOffset:{} "
,
consumerGroup
,
ackedOffset
,
currentOffset
);
return
true
;
}
return
false
;
}
...
...
snode/src/main/java/org/apache/rocketmq/snode/processor/mqtthandler/MqttSubscribeMessageHandler.java
浏览文件 @
9fc0ce45
...
...
@@ -24,16 +24,17 @@ import org.apache.rocketmq.snode.SnodeController;
public
class
MqttSubscribeMessageHandler
implements
MessageHandler
{
/* private SubscriptionStore subscriptionStore;
/* private SubscriptionStore subscriptionStore;
public MqttSubscribeMessageHandler(SubscriptionStore subscriptionStore) {
this.subscriptionStore = subscriptionStore;
}*/
public MqttSubscribeMessageHandler(SubscriptionStore subscriptionStore) {
this.subscriptionStore = subscriptionStore;
}*/
private
final
SnodeController
snodeController
;
public
MqttSubscribeMessageHandler
(
SnodeController
snodeController
)
{
this
.
snodeController
=
snodeController
;
}
/**
* handle the SUBSCRIBE message from the client
* <ol>
...
...
snode/src/main/java/org/apache/rocketmq/snode/service/NnodeService.java
浏览文件 @
9fc0ce45
...
...
@@ -26,10 +26,25 @@ import org.apache.rocketmq.remoting.exception.RemotingTimeoutException;
import
org.apache.rocketmq.snode.config.SnodeConfig
;
public
interface
NnodeService
{
void
registerSnode
(
SnodeConfig
snodeConfig
);
void
updateNnodeAddressList
(
final
String
addrs
);
/**
* Register Snode to Nnode(Name server) includes information: snodeAddress, snodeName, snodeClusterName.
*
* @param snodeConfig {@link SnodeConfig}
*/
void
registerSnode
(
SnodeConfig
snodeConfig
)
throws
Exception
;
/**
* Update Nnode server address list.
*
* @param addresses Node name service list
*/
void
updateNnodeAddressList
(
final
String
addresses
);
/**
* Fetch Node server address
*
* @return Node address
*/
String
fetchNnodeAdress
();
void
updateTopicRouteDataByTopic
();
...
...
snode/src/main/java/org/apache/rocketmq/snode/service/impl/EnodeServiceImpl.java
浏览文件 @
9fc0ce45
...
...
@@ -244,12 +244,12 @@ public class EnodeServiceImpl implements EnodeService {
TopicConfig
topicConfig
)
throws
InterruptedException
,
RemotingTimeoutException
,
RemotingSendRequestException
,
RemotingConnectException
{
CreateTopicRequestHeader
requestHeader
=
new
CreateTopicRequestHeader
();
requestHeader
.
setTopic
(
topicConfig
.
getTopicName
());
requestHeader
.
setPerm
(
topicConfig
.
getPerm
());
requestHeader
.
setReadQueueNums
(
topicConfig
.
getReadQueueNums
());
requestHeader
.
setWriteQueueNums
(
topicConfig
.
getWriteQueueNums
());
requestHeader
.
set
Perm
(
topicConfig
.
getPerm
());
requestHeader
.
set
Order
(
topicConfig
.
isOrder
());
requestHeader
.
setTopicFilterType
(
topicConfig
.
getTopicFilterType
().
name
());
requestHeader
.
setTopicSysFlag
(
topicConfig
.
getTopicSysFlag
());
requestHeader
.
setOrder
(
topicConfig
.
isOrder
());
RemotingCommand
request
=
RemotingCommand
.
createRequestCommand
(
RequestCode
.
UPDATE_AND_CREATE_TOPIC
,
requestHeader
);
String
address
=
this
.
snodeController
.
getNnodeService
().
getAddressByEnodeName
(
enodeName
,
false
);
return
this
.
snodeController
.
getRemotingClient
().
invokeSync
(
address
,
...
...
snode/src/main/java/org/apache/rocketmq/snode/service/impl/NnodeServiceImpl.java
浏览文件 @
9fc0ce45
...
...
@@ -58,7 +58,7 @@ public class NnodeServiceImpl implements NnodeService {
}
@Override
public
void
registerSnode
(
SnodeConfig
snodeConfig
)
{
public
void
registerSnode
(
SnodeConfig
snodeConfig
)
throws
Exception
{
List
<
String
>
nnodeAddressList
=
this
.
snodeController
.
getRemotingClient
().
getNameServerAddressList
();
RemotingCommand
remotingCommand
=
new
RemotingCommand
();
RegisterSnodeRequestHeader
requestHeader
=
new
RegisterSnodeRequestHeader
();
...
...
@@ -75,6 +75,9 @@ public class NnodeServiceImpl implements NnodeService {
log
.
warn
(
"Register Snode to Nnode addr: {} error, ex:{} "
,
nodeAddress
,
ex
);
}
}
}
else
{
log
.
warn
(
"Nnode server list is null"
);
throw
new
RemotingSendRequestException
(
"Nnode server list is null"
);
}
}
...
...
snode/src/main/java/org/apache/rocketmq/snode/service/impl/ScheduledServiceImpl.java
浏览文件 @
9fc0ce45
...
...
@@ -15,6 +15,7 @@
* limitations under the License.
*/
package
org.apache.rocketmq.snode.service.impl
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ThreadFactory
;
...
...
@@ -88,7 +89,11 @@ public class ScheduledServiceImpl implements ScheduledService {
this
.
scheduledExecutorService
.
scheduleAtFixedRate
(
new
Runnable
()
{
@Override
public
void
run
()
{
snodeController
.
getNnodeService
().
registerSnode
(
snodeConfig
);
try
{
snodeController
.
getNnodeService
().
registerSnode
(
snodeConfig
);
}
catch
(
Exception
ex
)
{
log
.
warn
(
"Register snode error"
,
ex
);
}
}
},
0
,
Math
.
max
(
10000
,
Math
.
min
(
snodeConfig
.
getRegisterNameServerPeriod
(),
60000
)),
TimeUnit
.
MILLISECONDS
);
...
...
snode/src/test/java/org/apache/rocketmq/snode/processor/SendMessageProcessorTest.java
浏览文件 @
9fc0ce45
...
...
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.when;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
SendMessageProcessorTest
{
private
SendMessageProcessor
sendMessageProcessor
;
@Spy
...
...
@@ -52,12 +53,10 @@ public class SendMessageProcessorTest {
@Mock
private
RemotingChannel
remotingChannel
;
private
String
topic
=
"SnodeTopic"
;
private
String
group
=
"SnodeGroup"
;
private
String
enodeName
=
"enodeName"
;
private
String
topic
=
"snodeTopic"
;
private
String
group
=
"snodeGroup"
;
@Mock
private
EnodeService
enodeService
;
...
...
snode/src/test/java/org/apache/rocketmq/snode/service/EnodeServiceImplTest.java
浏览文件 @
9fc0ce45
...
...
@@ -18,7 +18,7 @@ package org.apache.rocketmq.snode.service;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.rocketmq.common.
message.Message
;
import
org.apache.rocketmq.common.
TopicConfig
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.apache.rocketmq.common.protocol.ResponseCode
;
import
org.apache.rocketmq.common.protocol.header.PullMessageRequestHeader
;
...
...
@@ -53,6 +53,7 @@ import static org.mockito.Mockito.when;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
EnodeServiceImplTest
extends
SnodeTestBase
{
private
EnodeService
enodeService
;
@Spy
...
...
@@ -66,20 +67,20 @@ public class EnodeServiceImplTest extends SnodeTestBase {
private
String
enodeName
=
"enodeName"
;
private
String
topic
=
"
S
nodeTopic"
;
private
String
topic
=
"
s
nodeTopic"
;
private
String
group
=
"
S
nodeGroup"
;
private
String
group
=
"
s
nodeGroup"
;
@Before
public
void
init
()
{
snodeController
.
setNnodeService
(
nnodeService
);
snodeController
.
setRemotingClient
(
remotingClient
);
enodeService
=
new
EnodeServiceImpl
(
snodeController
);
}
@Test
public
void
sendMessageTest
()
throws
Exception
{
snodeController
.
setNnodeService
(
nnodeService
);
snodeController
.
setRemotingClient
(
remotingClient
);
when
(
snodeController
.
getNnodeService
().
getAddressByEnodeName
(
anyString
(),
anyBoolean
())).
thenReturn
(
"1024"
);
when
(
snodeController
.
getNnodeService
().
getAddressByEnodeName
(
anyString
(),
anyBoolean
())).
thenReturn
(
"127.0.0.1:10911"
);
CompletableFuture
<
RemotingCommand
>
responseCF
=
new
CompletableFuture
<>();
doAnswer
(
new
Answer
()
{
@Override
...
...
@@ -123,6 +124,15 @@ public class EnodeServiceImplTest extends SnodeTestBase {
assertThat
(
response
.
getCode
()).
isEqualTo
(
ResponseCode
.
SUCCESS
);
}
@Test
public
void
creatTopicTest
()
throws
Exception
{
when
(
snodeController
.
getNnodeService
().
getAddressByEnodeName
(
anyString
(),
anyBoolean
())).
thenReturn
(
"127.0.0.1:10911"
);
when
(
snodeController
.
getRemotingClient
().
invokeSync
(
anyString
(),
any
(
RemotingCommand
.
class
),
anyLong
())).
thenReturn
(
createSuccessResponse
());
TopicConfig
topicConfig
=
new
TopicConfig
(
topic
,
1
,
1
,
2
);
RemotingCommand
response
=
enodeService
.
creatTopic
(
enodeName
,
topicConfig
);
assertThat
(
response
.
getCode
()).
isEqualTo
(
ResponseCode
.
SUCCESS
);
}
private
GetMessageResult
createGetMessageResult
()
{
GetMessageResult
getMessageResult
=
new
GetMessageResult
();
getMessageResult
.
setStatus
(
GetMessageStatus
.
FOUND
);
...
...
snode/src/test/java/org/apache/rocketmq/snode/service/NnodeServiceImplTest.java
0 → 100644
浏览文件 @
9fc0ce45
/*
* 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.snode.service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.rocketmq.remoting.ClientConfig
;
import
org.apache.rocketmq.remoting.ServerConfig
;
import
org.apache.rocketmq.remoting.exception.RemotingConnectException
;
import
org.apache.rocketmq.remoting.exception.RemotingSendRequestException
;
import
org.apache.rocketmq.remoting.exception.RemotingTimeoutException
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.transport.rocketmq.NettyRemotingClient
;
import
org.apache.rocketmq.snode.SnodeController
;
import
org.apache.rocketmq.snode.SnodeTestBase
;
import
org.apache.rocketmq.snode.config.SnodeConfig
;
import
org.apache.rocketmq.snode.service.impl.NnodeServiceImpl
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.Spy
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
NnodeServiceImplTest
extends
SnodeTestBase
{
@Spy
private
SnodeController
snodeController
=
new
SnodeController
(
new
ServerConfig
(),
new
ClientConfig
(),
new
SnodeConfig
());
@Mock
private
NettyRemotingClient
remotingClient
;
private
NnodeService
nnodeService
;
@Before
public
void
init
()
{
snodeController
.
setRemotingClient
(
remotingClient
);
nnodeService
=
new
NnodeServiceImpl
(
snodeController
);
}
@Test
public
void
registerSnodeSuccessTest
()
throws
InterruptedException
,
RemotingConnectException
,
RemotingSendRequestException
,
RemotingTimeoutException
{
when
(
snodeController
.
getRemotingClient
().
getNameServerAddressList
()).
thenReturn
(
createNnodeList
());
when
(
snodeController
.
getRemotingClient
().
invokeSync
(
anyString
(),
any
(
RemotingCommand
.
class
),
anyLong
())).
thenReturn
(
createSuccessResponse
());
try
{
nnodeService
.
registerSnode
(
createSnodeConfig
());
}
catch
(
Exception
ex
)
{
assertThat
(
ex
).
isNull
();
}
}
private
List
createNnodeList
()
{
List
<
String
>
addresses
=
new
ArrayList
<>();
addresses
.
add
(
"127.0.0.1:9876"
);
return
addresses
;
}
private
SnodeConfig
createSnodeConfig
()
{
SnodeConfig
snodeConfig
=
new
SnodeConfig
();
snodeConfig
.
setClusterName
(
"defaultCluster"
);
snodeConfig
.
setSnodeIP1
(
"127.0.0.1:10911"
);
snodeConfig
.
setSnodeName
(
"snode-a"
);
return
snodeConfig
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录