Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
11d3df66
R
Rocketmq
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
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看板
提交
11d3df66
编写于
11月 08, 2018
作者:
L
laohu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add acl use example. AclClient.java
上级
94403714
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
173 addition
and
177 deletion
+173
-177
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/DefaultAclRemotingServiceImpl.java
...ache/rocketmq/acl/plug/DefaultAclRemotingServiceImpl.java
+12
-13
example/src/main/java/org/apache/rocketmq/example/simple/AclClient.java
...in/java/org/apache/rocketmq/example/simple/AclClient.java
+161
-164
未找到文件。
acl-plug/src/main/java/org/apache/rocketmq/acl/plug/DefaultAclRemotingServiceImpl.java
浏览文件 @
11d3df66
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
*/
*/
package
org.apache.rocketmq.acl.plug
;
package
org.apache.rocketmq.acl.plug
;
import
java.util.HashMap
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.acl.AccessResource
;
import
org.apache.rocketmq.acl.AccessResource
;
import
org.apache.rocketmq.acl.AccessValidator
;
import
org.apache.rocketmq.acl.AccessValidator
;
...
@@ -27,8 +28,6 @@ import org.apache.rocketmq.acl.plug.entity.ControllerParameters;
...
@@ -27,8 +28,6 @@ import org.apache.rocketmq.acl.plug.entity.ControllerParameters;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
org.apache.rocketmq.acl.plug.exception.AclPlugRuntimeException
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
java.util.HashMap
;
public
class
DefaultAclRemotingServiceImpl
implements
AclRemotingService
,
AccessValidator
{
public
class
DefaultAclRemotingServiceImpl
implements
AclRemotingService
,
AccessValidator
{
private
AclPlugEngine
aclPlugEngine
;
private
AclPlugEngine
aclPlugEngine
;
...
@@ -80,8 +79,8 @@ public class DefaultAclRemotingServiceImpl implements AclRemotingService, Access
...
@@ -80,8 +79,8 @@ public class DefaultAclRemotingServiceImpl implements AclRemotingService, Access
if
(
authenticationResult
.
getAccessControl
()
==
null
||
!
authenticationResult
.
isSucceed
())
{
if
(
authenticationResult
.
getAccessControl
()
==
null
||
!
authenticationResult
.
isSucceed
())
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"%s accessControl data is %s"
,
authenticationResult
.
getResultString
(),
accessResource
.
toString
()));
throw
new
AclPlugRuntimeException
(
String
.
format
(
"%s accessControl data is %s"
,
authenticationResult
.
getResultString
(),
accessResource
.
toString
()));
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
AclPlugRuntimeException
(
String
.
format
(
"validate exception AccessResource data %s"
,
accessResource
.
toString
())
,
e
);
throw
new
AclPlugRuntimeException
(
String
.
format
(
"validate exception AccessResource data %s"
,
accessResource
.
toString
())
,
e
);
}
}
}
}
...
...
example/src/main/java/org/apache/rocketmq/example/simple/AclClient.java
浏览文件 @
11d3df66
...
@@ -20,7 +20,6 @@ import java.util.HashMap;
...
@@ -20,7 +20,6 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
org.apache.rocketmq.client.consumer.DefaultMQPullConsumer
;
import
org.apache.rocketmq.client.consumer.DefaultMQPullConsumer
;
import
org.apache.rocketmq.client.consumer.DefaultMQPushConsumer
;
import
org.apache.rocketmq.client.consumer.DefaultMQPushConsumer
;
import
org.apache.rocketmq.client.consumer.PullResult
;
import
org.apache.rocketmq.client.consumer.PullResult
;
...
@@ -40,21 +39,22 @@ import org.apache.rocketmq.remoting.common.RemotingHelper;
...
@@ -40,21 +39,22 @@ import org.apache.rocketmq.remoting.common.RemotingHelper;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
/**
/**
* 1. 把broker模块src/test/resources/META-INF/service/org.apache.rocketmq.acl.AccessValidator 复制到src/java/resources/META-INF/service
*
* 2. 查看distribution模块下 /conf/transport.yml文件,注意里面的账户密码,ip
* English explain
* 3. 把ALC_RCP_HOOK_ACCOUT与ACL_RCP_HOOK_PASSWORD 修改成transport.yml里面对应的账户密码
* 1. broker module src/test/resources/META-INF/service/org.apache.rocketmq.acl.AccessValidator copy to src/java/resources/META-INF/service.
* @author laohu
*
* 2. view the /conf/transport.yml file under the distribution module, pay attention to the account password, IP.
*
* 3. Modify ALC_RCP_HOOK_ACCOUT and ACL_RCP_HOOK_PASSWORD to the corresponding account password in transport.yml
*
*
*/
*/
public
class
AclClient
{
public
class
AclClient
{
private
static
final
Map
<
MessageQueue
,
Long
>
OFFSE_TABLE
=
new
HashMap
<
MessageQueue
,
Long
>();
private
static
final
Map
<
MessageQueue
,
Long
>
OFFSE_TABLE
=
new
HashMap
<
MessageQueue
,
Long
>();
private
static
String
ALC_RCP_HOOK_ACCOUT
=
"RocketMQ"
;
private
static
final
String
ACL_RCPHOOK_ACCOUT
=
"RocketMQ"
;
private
static
String
ACL_RCP_HOOK_PASSWORD
=
"1234567"
;
private
static
final
String
ACL_RCPHOOK_PASSWORD
=
"1234567"
;
public
static
void
main
(
String
[]
args
)
throws
MQClientException
,
InterruptedException
{
public
static
void
main
(
String
[]
args
)
throws
MQClientException
,
InterruptedException
{
producer
();
producer
();
...
@@ -63,7 +63,7 @@ public class AclClient {
...
@@ -63,7 +63,7 @@ public class AclClient {
}
}
public
static
void
producer
()
throws
MQClientException
{
public
static
void
producer
()
throws
MQClientException
{
DefaultMQProducer
producer
=
new
DefaultMQProducer
(
"ProducerGroupName"
,
getAalRPCHook
());
DefaultMQProducer
producer
=
new
DefaultMQProducer
(
"ProducerGroupName"
,
getAalRPCHook
());
producer
.
setNamesrvAddr
(
"127.0.0.1:9876"
);
producer
.
setNamesrvAddr
(
"127.0.0.1:9876"
);
producer
.
start
();
producer
.
start
();
...
@@ -87,8 +87,7 @@ public class AclClient {
...
@@ -87,8 +87,7 @@ public class AclClient {
public
static
void
pushConsumer
()
throws
MQClientException
{
public
static
void
pushConsumer
()
throws
MQClientException
{
DefaultMQPushConsumer
consumer
=
new
DefaultMQPushConsumer
(
"please_rename_unique_group_name_5"
,
getAalRPCHook
(),
new
AllocateMessageQueueAveragely
());
DefaultMQPushConsumer
consumer
=
new
DefaultMQPushConsumer
(
"please_rename_unique_group_name_5"
,
getAalRPCHook
(),
new
AllocateMessageQueueAveragely
());
consumer
.
setNamesrvAddr
(
"127.0.0.1:9876"
);
consumer
.
setNamesrvAddr
(
"127.0.0.1:9876"
);
consumer
.
subscribe
(
"TopicTest"
,
"*"
);
consumer
.
subscribe
(
"TopicTest"
,
"*"
);
consumer
.
setConsumeFromWhere
(
ConsumeFromWhere
.
CONSUME_FROM_FIRST_OFFSET
);
consumer
.
setConsumeFromWhere
(
ConsumeFromWhere
.
CONSUME_FROM_FIRST_OFFSET
);
...
@@ -108,7 +107,7 @@ public class AclClient {
...
@@ -108,7 +107,7 @@ public class AclClient {
}
}
public
static
void
pullConsumer
()
throws
MQClientException
{
public
static
void
pullConsumer
()
throws
MQClientException
{
DefaultMQPullConsumer
consumer
=
new
DefaultMQPullConsumer
(
"please_rename_unique_group_name_6"
,
getAalRPCHook
());
DefaultMQPullConsumer
consumer
=
new
DefaultMQPullConsumer
(
"please_rename_unique_group_name_6"
,
getAalRPCHook
());
consumer
.
setNamesrvAddr
(
"127.0.0.1:9876"
);
consumer
.
setNamesrvAddr
(
"127.0.0.1:9876"
);
consumer
.
start
();
consumer
.
start
();
...
@@ -149,12 +148,11 @@ public class AclClient {
...
@@ -149,12 +148,11 @@ public class AclClient {
}
}
private
static
void
printBody
(
List
<
MessageExt
>
msg
)
{
private
static
void
printBody
(
List
<
MessageExt
>
msg
)
{
if
(
msg
==
null
||
msg
.
size
()
==
0
)
if
(
msg
==
null
||
msg
.
size
()
==
0
)
return
;
return
;
for
(
MessageExt
m
:
msg
)
{
for
(
MessageExt
m
:
msg
)
{
if
(
m
!=
null
)
{
if
(
m
!=
null
)
{
System
.
out
.
printf
(
"msgId : %s body : %s"
,
m
.
getMsgId
()
,
new
String
(
m
.
getBody
()));
System
.
out
.
printf
(
"msgId : %s body : %s \n\r"
,
m
.
getMsgId
(),
new
String
(
m
.
getBody
()));
System
.
out
.
println
();
}
}
}
}
}
}
...
@@ -172,17 +170,16 @@ public class AclClient {
...
@@ -172,17 +170,16 @@ public class AclClient {
}
}
static
RPCHook
getAalRPCHook
()
{
static
RPCHook
getAalRPCHook
()
{
return
new
AalRPCHook
(
ALC_RCP_HOOK_ACCOUT
,
ACL_RCP_
HOOK_PASSWORD
);
return
new
AalRPCHook
(
ACL_RCPHOOK_ACCOUT
,
ACL_RCP
HOOK_PASSWORD
);
}
}
static
class
AalRPCHook
implements
RPCHook
{
static
class
AalRPCHook
implements
RPCHook
{
private
String
account
;
private
String
account
;
private
String
password
;
private
String
password
;
public
AalRPCHook
(
String
account
,
String
password
)
{
public
AalRPCHook
(
String
account
,
String
password
)
{
this
.
account
=
account
;
this
.
account
=
account
;
this
.
password
=
password
;
this
.
password
=
password
;
}
}
...
@@ -191,7 +188,7 @@ public class AclClient {
...
@@ -191,7 +188,7 @@ public class AclClient {
public
void
doBeforeRequest
(
String
remoteAddr
,
RemotingCommand
request
)
{
public
void
doBeforeRequest
(
String
remoteAddr
,
RemotingCommand
request
)
{
HashMap
<
String
,
String
>
ext
=
request
.
getExtFields
();
HashMap
<
String
,
String
>
ext
=
request
.
getExtFields
();
if
(
ext
==
null
)
{
if
(
ext
==
null
)
{
ext
=
new
HashMap
<>();
ext
=
new
HashMap
<>();
request
.
setExtFields
(
ext
);
request
.
setExtFields
(
ext
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录