Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
8a0219df
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看板
提交
8a0219df
编写于
1月 25, 2019
作者:
H
huzongtang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ISSUE#724]Integrated ACL Interceptor into SnodeController.
上级
c7fdb765
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
157 addition
and
7 deletion
+157
-7
acl/pom.xml
acl/pom.xml
+0
-4
distribution/conf/plain_acl.yml
distribution/conf/plain_acl.yml
+40
-0
example/src/main/java/org/apache/rocketmq/example/filter/SqlConsumer.java
.../java/org/apache/rocketmq/example/filter/SqlConsumer.java
+1
-1
pom.xml
pom.xml
+5
-0
remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java
...ava/org/apache/rocketmq/remoting/common/RemotingUtil.java
+7
-0
remoting/src/main/java/org/apache/rocketmq/remoting/util/ServiceProvider.java
...va/org/apache/rocketmq/remoting/util/ServiceProvider.java
+2
-0
snode/pom.xml
snode/pom.xml
+4
-0
snode/src/main/java/org/apache/rocketmq/snode/SnodeController.java
.../main/java/org/apache/rocketmq/snode/SnodeController.java
+45
-0
snode/src/main/java/org/apache/rocketmq/snode/config/SnodeConfig.java
...in/java/org/apache/rocketmq/snode/config/SnodeConfig.java
+14
-0
snode/src/main/java/org/apache/rocketmq/snode/flowcontrol/QPSFlowControlServiceImpl.java
...rocketmq/snode/flowcontrol/QPSFlowControlServiceImpl.java
+2
-2
snode/src/main/resources/META-INF/service/org.apache.rocketmq.acl.AccessValidator
.../META-INF/service/org.apache.rocketmq.acl.AccessValidator
+1
-0
snode/src/test/java/org/apache/rocketmq/snode/SnodeControllerTest.java
...t/java/org/apache/rocketmq/snode/SnodeControllerTest.java
+14
-0
snode/src/test/resources/META-INF/service/flowControl.yml
snode/src/test/resources/META-INF/service/flowControl.yml
+19
-0
snode/src/test/resources/META-INF/service/org.apache.rocketmq.acl.AccessValidator
.../META-INF/service/org.apache.rocketmq.acl.AccessValidator
+1
-0
snode/src/test/resources/META-INF/service/org.apache.rocketmq.snode.interceptor.ConsumeMessageInterceptor
...ache.rocketmq.snode.interceptor.ConsumeMessageInterceptor
+0
-0
snode/src/test/resources/META-INF/service/org.apache.rocketmq.snode.interceptor.RemotingServerInterceptor
...ache.rocketmq.snode.interceptor.RemotingServerInterceptor
+2
-0
snode/src/test/resources/META-INF/service/org.apache.rocketmq.snode.interceptor.SendMessageInterceptor
....apache.rocketmq.snode.interceptor.SendMessageInterceptor
+0
-0
未找到文件。
acl/pom.xml
浏览文件 @
8a0219df
...
...
@@ -69,10 +69,6 @@
<artifactId>
logback-core
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
rocketmq-remoting
</artifactId>
</dependency>
</dependencies>
</project>
distribution/conf/plain_acl.yml
0 → 100644
浏览文件 @
8a0219df
# 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.
globalWhiteRemoteAddresses
:
accounts
:
-
accessKey
:
RocketMQ
secretKey
:
12345678
whiteRemoteAddress
:
admin
:
false
defaultTopicPerm
:
DENY
defaultGroupPerm
:
SUB
topicPerms
:
-
topicA=DENY
-
topicB=PUB|SUB
-
topicC=SUB
groupPerms
:
# the group should convert to retry topic
-
groupA=DENY
-
groupB=PUB|SUB
-
groupC=SUB
-
accessKey
:
rocketmq2
secretKey
:
12345678
whiteRemoteAddress
:
192.168.1.*
# if it is admin, it could access all resources
admin
:
true
example/src/main/java/org/apache/rocketmq/example/filter/SqlConsumer.java
浏览文件 @
8a0219df
...
...
@@ -27,7 +27,7 @@ import org.apache.rocketmq.common.message.MessageExt;
public
class
SqlConsumer
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
DefaultMQPushConsumer
consumer
=
new
DefaultMQPushConsumer
(
"please_rename_unique_group_name"
);
// Don't forget to set enablePropertyFilter=true in broker
...
...
pom.xml
浏览文件 @
8a0219df
...
...
@@ -525,6 +525,11 @@
<artifactId>
rocketmq-example
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
rocketmq-acl
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
...
...
remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingUtil.java
浏览文件 @
8a0219df
...
...
@@ -162,6 +162,13 @@ public class RemotingUtil {
return
sb
.
toString
();
}
public
static
String
socketAddress2IpString
(
final
SocketAddress
addr
)
{
StringBuilder
sb
=
new
StringBuilder
();
InetSocketAddress
inetSocketAddress
=
(
InetSocketAddress
)
addr
;
sb
.
append
(
inetSocketAddress
.
getAddress
().
getHostAddress
());
return
sb
.
toString
();
}
public
static
SocketChannel
connect
(
SocketAddress
remote
)
{
return
connect
(
remote
,
1000
*
5
);
}
...
...
remoting/src/main/java/org/apache/rocketmq/remoting/util/ServiceProvider.java
浏览文件 @
8a0219df
...
...
@@ -40,6 +40,8 @@ public class ServiceProvider {
public
static
final
String
TRANSACTION_LISTENER_ID
=
"META-INF/service/org.apache.rocketmq.broker.transaction.AbstractTransactionalMessageCheckListener"
;
public
static
final
String
ACL_VALIDATOR_ID
=
"META-INF/service/org.apache.rocketmq.acl.AccessValidator"
;
static
{
thisClassLoader
=
getClassLoader
(
ServiceProvider
.
class
);
}
...
...
snode/pom.xml
浏览文件 @
8a0219df
...
...
@@ -52,6 +52,10 @@
<groupId>
${project.groupId}
</groupId>
<artifactId>
rocketmq-filter
</artifactId>
</dependency>
<dependency>
<groupId>
${project.groupId}
</groupId>
<artifactId>
rocketmq-acl
</artifactId>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
...
...
snode/src/main/java/org/apache/rocketmq/snode/SnodeController.java
浏览文件 @
8a0219df
...
...
@@ -22,6 +22,7 @@ import java.util.concurrent.ExecutorService;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.rocketmq.acl.AccessValidator
;
import
org.apache.rocketmq.common.ThreadFactoryImpl
;
import
org.apache.rocketmq.common.constant.LoggerName
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
...
...
@@ -34,9 +35,15 @@ import org.apache.rocketmq.remoting.RemotingClientFactory;
import
org.apache.rocketmq.remoting.RemotingServer
;
import
org.apache.rocketmq.remoting.RemotingServerFactory
;
import
org.apache.rocketmq.remoting.ServerConfig
;
import
org.apache.rocketmq.remoting.common.RemotingUtil
;
import
org.apache.rocketmq.remoting.interceptor.ExceptionContext
;
import
org.apache.rocketmq.remoting.interceptor.Interceptor
;
import
org.apache.rocketmq.remoting.interceptor.InterceptorFactory
;
import
org.apache.rocketmq.remoting.interceptor.InterceptorGroup
;
import
org.apache.rocketmq.remoting.interceptor.RequestContext
;
import
org.apache.rocketmq.remoting.interceptor.ResponseContext
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.util.ServiceProvider
;
import
org.apache.rocketmq.snode.client.ClientHousekeepingService
;
import
org.apache.rocketmq.snode.client.ClientManager
;
import
org.apache.rocketmq.snode.client.SlowConsumerService
;
...
...
@@ -201,10 +208,48 @@ public class SnodeController {
this
.
registerProcessor
();
initSnodeInterceptorGroup
();
initRemotingServerInterceptorGroup
();
initAclInterceptorGroup
();
this
.
snodeServer
.
registerInterceptorGroup
(
this
.
remotingServerInterceptorGroup
);
return
true
;
}
private
void
initAclInterceptorGroup
()
{
if
(!
this
.
snodeConfig
.
isAclEnable
())
{
log
.
info
(
"The snode dose not enable acl"
);
return
;
}
List
<
AccessValidator
>
accessValidators
=
ServiceProvider
.
loadServiceList
(
ServiceProvider
.
ACL_VALIDATOR_ID
,
AccessValidator
.
class
);
if
(
accessValidators
==
null
||
accessValidators
.
isEmpty
())
{
log
.
info
(
"The snode dose not load the AccessValidator"
);
return
;
}
for
(
AccessValidator
accessValidator:
accessValidators
)
{
final
AccessValidator
validator
=
accessValidator
;
this
.
remotingServerInterceptorGroup
.
registerInterceptor
(
new
Interceptor
()
{
@Override
public
String
interceptorName
()
{
return
"snodeRequestAclControlInterceptor"
;
}
@Override
public
void
beforeRequest
(
RequestContext
requestContext
)
{
//Do not catch the exception
RemotingCommand
request
=
requestContext
.
getRequest
();
String
remoteAddr
=
RemotingUtil
.
socketAddress2IpString
(
requestContext
.
getRemotingChannel
().
remoteAddress
());
validator
.
validate
(
validator
.
parse
(
request
,
remoteAddr
));
}
@Override
public
void
afterRequest
(
ResponseContext
responseContext
)
{
}
@Override
public
void
onException
(
ExceptionContext
exceptionContext
)
{
}
});
}
}
private
void
initSnodeInterceptorGroup
()
{
List
<
Interceptor
>
consumeMessageInterceptors
=
InterceptorFactory
.
getInstance
().
loadInterceptors
(
this
.
snodeConfig
.
getConsumeMessageInterceptorPath
());
if
(
consumeMessageInterceptors
!=
null
&&
consumeMessageInterceptors
.
size
()
>
0
)
{
...
...
snode/src/main/java/org/apache/rocketmq/snode/config/SnodeConfig.java
浏览文件 @
8a0219df
...
...
@@ -79,6 +79,12 @@ public class SnodeConfig {
private
boolean
vipChannelEnabled
=
Boolean
.
parseBoolean
(
System
.
getProperty
(
SEND_MESSAGE_WITH_VIP_CHANNEL_PROPERTY
,
"true"
));
/**
* Acl feature switch
*/
@ImportantField
private
boolean
aclEnable
=
false
;
public
void
setSnodeHeartBeatInterval
(
long
snodeHeartBeatInterval
)
{
this
.
snodeHeartBeatInterval
=
snodeHeartBeatInterval
;
}
...
...
@@ -291,4 +297,12 @@ public class SnodeConfig {
public
void
setSlowConsumerThreshold
(
int
slowConsumerThreshold
)
{
this
.
slowConsumerThreshold
=
slowConsumerThreshold
;
}
public
boolean
isAclEnable
()
{
return
aclEnable
;
}
public
void
setAclEnable
(
boolean
aclEnable
)
{
this
.
aclEnable
=
aclEnable
;
}
}
snode/src/main/java/org/apache/rocketmq/snode/flowcontrol/QPSFlowControlServiceImpl.java
浏览文件 @
8a0219df
...
...
@@ -17,17 +17,17 @@
package
org.apache.rocketmq.snode.flowcontrol
;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.apache.rocketmq.common.constant.LoggerName
;
import
org.apache.rocketmq.common.flowcontrol.AbstractFlowControlService
;
import
org.apache.rocketmq.common.protocol.RequestCode
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLoggerFactory
;
import
org.apache.rocketmq.remoting.common.RemotingHelper
;
import
org.apache.rocketmq.remoting.exception.RemotingRuntimeException
;
import
org.apache.rocketmq.remoting.interceptor.RequestContext
;
import
org.apache.rocketmq.remoting.protocol.RemotingSysResponseCode
;
public
class
QPSFlowControlServiceImpl
extends
AbstractFlowControlService
{
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
SNODE_LOGGER_NAME
);
private
final
AtomicLong
logCount
=
new
AtomicLong
(
0
);
...
...
snode/src/main/resources/META-INF/service/org.apache.rocketmq.acl.AccessValidator
0 → 100644
浏览文件 @
8a0219df
org.apache.rocketmq.acl.plain.PlainAccessValidator
\ No newline at end of file
snode/src/test/java/org/apache/rocketmq/snode/SnodeControllerTest.java
浏览文件 @
8a0219df
...
...
@@ -36,4 +36,18 @@ public class SnodeControllerTest {
snodeController
.
shutdown
();
}
@Test
public
void
testSnodeRestartWithAclEnable
()
{
SnodeConfig
snodeConfig
=
new
SnodeConfig
();
snodeConfig
.
setAclEnable
(
true
);
SnodeController
snodeController
=
new
SnodeController
(
new
ServerConfig
(),
new
ClientConfig
(),
snodeConfig
);
assertThat
(
snodeController
.
initialize
());
snodeController
.
start
();
snodeController
.
shutdown
();
}
}
snode/src/test/resources/META-INF/service/flowControl.yml
0 → 100644
浏览文件 @
8a0219df
snode
:
countLimit
:
# flow control type, only requestCount & requestSize support
-
flowControlResourceName
:
310
flowControlGrade
:
1
flowControlBehavior
:
1
flowControlResourceCount
:
500.00
#QPS
-
flowControlResourceName
:
overall
flowControlGrade
:
1
flowControlBehavior
:
1
flowControlResourceCount
:
10000.00
#QPS
sizeLimit
:
-
flowControlResourceName
:
310
flowControlGrade
:
1
flowControlBehavior
:
1
flowControlResourceCount
:
5.00
#KB/S
topicLimit
:
\ No newline at end of file
snode/src/test/resources/META-INF/service/org.apache.rocketmq.acl.AccessValidator
0 → 100644
浏览文件 @
8a0219df
org.apache.rocketmq.acl.plain.PlainAccessValidator
\ No newline at end of file
snode/src/test/resources/META-INF/service/org.apache.rocketmq.snode.interceptor.ConsumeMessageInterceptor
0 → 100644
浏览文件 @
8a0219df
snode/src/test/resources/META-INF/service/org.apache.rocketmq.snode.interceptor.RemotingServerInterceptor
0 → 100644
浏览文件 @
8a0219df
org.apache.rocketmq.snode.flowcontrol.QPSFlowControlServiceImpl
org.apache.rocketmq.snode.flowcontrol.RequestSizeFlowControlServiceImpl
\ No newline at end of file
snode/src/test/resources/META-INF/service/org.apache.rocketmq.snode.interceptor.SendMessageInterceptor
0 → 100644
浏览文件 @
8a0219df
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录