Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
b8cb82f4
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看板
提交
b8cb82f4
编写于
12月 28, 2018
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename tracktrace to trace, and polish the package hierarchy
上级
5f664247
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
194 addition
and
211 deletion
+194
-211
client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java
...pache/rocketmq/client/consumer/DefaultMQPushConsumer.java
+17
-17
client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java
...rg/apache/rocketmq/client/producer/DefaultMQProducer.java
+20
-18
client/src/main/java/org/apache/rocketmq/client/trace/AsyncTraceDispatcher.java
...rg/apache/rocketmq/client/trace/AsyncTraceDispatcher.java
+29
-37
client/src/main/java/org/apache/rocketmq/client/trace/TraceBean.java
...main/java/org/apache/rocketmq/client/trace/TraceBean.java
+2
-2
client/src/main/java/org/apache/rocketmq/client/trace/TraceConstants.java
...java/org/apache/rocketmq/client/trace/TraceConstants.java
+2
-2
client/src/main/java/org/apache/rocketmq/client/trace/TraceContext.java
...n/java/org/apache/rocketmq/client/trace/TraceContext.java
+11
-11
client/src/main/java/org/apache/rocketmq/client/trace/TraceDataEncoder.java
...va/org/apache/rocketmq/client/trace/TraceDataEncoder.java
+56
-58
client/src/main/java/org/apache/rocketmq/client/trace/TraceDispatcher.java
...ava/org/apache/rocketmq/client/trace/TraceDispatcher.java
+2
-2
client/src/main/java/org/apache/rocketmq/client/trace/TraceDispatcherType.java
...org/apache/rocketmq/client/trace/TraceDispatcherType.java
+2
-2
client/src/main/java/org/apache/rocketmq/client/trace/TraceProducerFactory.java
...rg/apache/rocketmq/client/trace/TraceProducerFactory.java
+8
-8
client/src/main/java/org/apache/rocketmq/client/trace/TraceTransferBean.java
...a/org/apache/rocketmq/client/trace/TraceTransferBean.java
+2
-2
client/src/main/java/org/apache/rocketmq/client/trace/TraceType.java
...main/java/org/apache/rocketmq/client/trace/TraceType.java
+2
-2
client/src/main/java/org/apache/rocketmq/client/trace/hook/ConsumeMessageTraceHookImpl.java
...cketmq/client/trace/hook/ConsumeMessageTraceHookImpl.java
+14
-14
client/src/main/java/org/apache/rocketmq/client/trace/hook/SendMessageTraceHookImpl.java
.../rocketmq/client/trace/hook/SendMessageTraceHookImpl.java
+17
-17
client/src/test/java/org/apache/rocketmq/client/trace/DefaultMQConsumerWithTraceTest.java
...rocketmq/client/trace/DefaultMQConsumerWithTraceTest.java
+3
-4
client/src/test/java/org/apache/rocketmq/client/trace/DefaultMQProducerWithTraceTest.java
...rocketmq/client/trace/DefaultMQProducerWithTraceTest.java
+6
-7
example/src/main/java/org/apache/rocketmq/example/simple/AclClient.java
...in/java/org/apache/rocketmq/example/simple/AclClient.java
+1
-8
未找到文件。
client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java
浏览文件 @
b8cb82f4
...
...
@@ -31,11 +31,11 @@ import org.apache.rocketmq.client.exception.MQBrokerException;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl
;
import
org.apache.rocketmq.client.log.ClientLogger
;
import
org.apache.rocketmq.client.trace.
core.common.TrackTraceConstants
;
import
org.apache.rocketmq.client.trace.
core.common.TrackTraceDispatcherType
;
import
org.apache.rocketmq.client.trace.
core.dispatch.Async
Dispatcher
;
import
org.apache.rocketmq.client.trace.
core.dispatch.impl.AsyncArrayDispatcher
;
import
org.apache.rocketmq.client.trace.
core.
hook.ConsumeMessageTraceHookImpl
;
import
org.apache.rocketmq.client.trace.
AsyncTraceDispatcher
;
import
org.apache.rocketmq.client.trace.
TraceConstants
;
import
org.apache.rocketmq.client.trace.
Trace
Dispatcher
;
import
org.apache.rocketmq.client.trace.
TraceDispatcherType
;
import
org.apache.rocketmq.client.trace.hook.ConsumeMessageTraceHookImpl
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.UtilAll
;
import
org.apache.rocketmq.common.consumer.ConsumeFromWhere
;
...
...
@@ -259,7 +259,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
/**
* Interface of asynchronous transfer data
*/
private
Async
Dispatcher
traceDispatcher
=
null
;
private
Trace
Dispatcher
traceDispatcher
=
null
;
/**
* Default constructor.
...
...
@@ -299,17 +299,17 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
if
(
msgTraceSwitch
)
{
try
{
Properties
tempProperties
=
new
Properties
();
tempProperties
.
put
(
Trac
kTrac
eConstants
.
MAX_MSG_SIZE
,
"128000"
);
tempProperties
.
put
(
Trac
kTrac
eConstants
.
ASYNC_BUFFER_SIZE
,
"2048"
);
tempProperties
.
put
(
Trac
kTrac
eConstants
.
MAX_BATCH_NUM
,
"100"
);
tempProperties
.
put
(
Trac
kTrac
eConstants
.
INSTANCE_NAME
,
"PID_CLIENT_INNER_TRACE_PRODUCER"
);
tempProperties
.
put
(
Trac
kTraceConstants
.
TRACE_DISPATCHER_TYPE
,
Track
TraceDispatcherType
.
CONSUMER
.
name
());
tempProperties
.
put
(
TraceConstants
.
MAX_MSG_SIZE
,
"128000"
);
tempProperties
.
put
(
TraceConstants
.
ASYNC_BUFFER_SIZE
,
"2048"
);
tempProperties
.
put
(
TraceConstants
.
MAX_BATCH_NUM
,
"100"
);
tempProperties
.
put
(
TraceConstants
.
INSTANCE_NAME
,
"PID_CLIENT_INNER_TRACE_PRODUCER"
);
tempProperties
.
put
(
Trac
eConstants
.
TRACE_DISPATCHER_TYPE
,
TraceDispatcherType
.
CONSUMER
.
name
());
if
(!
UtilAll
.
isBlank
(
traceTopicName
))
{
tempProperties
.
put
(
Trac
kTrac
eConstants
.
TRACE_TOPIC
,
traceTopicName
);
tempProperties
.
put
(
TraceConstants
.
TRACE_TOPIC
,
traceTopicName
);
}
else
{
tempProperties
.
put
(
Trac
kTrac
eConstants
.
TRACE_TOPIC
,
MixAll
.
RMQ_SYS_TRACK_TRACE_TOPIC
);
tempProperties
.
put
(
TraceConstants
.
TRACE_TOPIC
,
MixAll
.
RMQ_SYS_TRACK_TRACE_TOPIC
);
}
Async
ArrayDispatcher
dispatcher
=
new
AsyncArray
Dispatcher
(
tempProperties
,
rpcHook
);
Async
TraceDispatcher
dispatcher
=
new
AsyncTrace
Dispatcher
(
tempProperties
,
rpcHook
);
dispatcher
.
setHostConsumer
(
this
.
getDefaultMQPushConsumerImpl
());
traceDispatcher
=
dispatcher
;
...
...
@@ -586,7 +586,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
if
(
null
!=
traceDispatcher
)
{
try
{
Properties
tempProperties
=
new
Properties
();
tempProperties
.
put
(
Trac
kTrac
eConstants
.
NAMESRV_ADDR
,
this
.
getNamesrvAddr
());
tempProperties
.
put
(
TraceConstants
.
NAMESRV_ADDR
,
this
.
getNamesrvAddr
());
traceDispatcher
.
start
(
tempProperties
);
}
catch
(
MQClientException
e
)
{
log
.
warn
(
"trace dispatcher start failed "
,
e
);
...
...
@@ -772,11 +772,11 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume
this
.
consumeTimeout
=
consumeTimeout
;
}
public
Async
Dispatcher
getTraceDispatcher
()
{
public
Trace
Dispatcher
getTraceDispatcher
()
{
return
traceDispatcher
;
}
public
void
setTraceDispatcher
(
Async
Dispatcher
traceDispatcher
)
{
public
void
setTraceDispatcher
(
Trace
Dispatcher
traceDispatcher
)
{
this
.
traceDispatcher
=
traceDispatcher
;
}
}
client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java
浏览文件 @
b8cb82f4
...
...
@@ -27,11 +27,11 @@ import org.apache.rocketmq.client.exception.MQBrokerException;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl
;
import
org.apache.rocketmq.client.log.ClientLogger
;
import
org.apache.rocketmq.client.trace.
core.common.TrackTraceConstants
;
import
org.apache.rocketmq.client.trace.
core.common.TrackTraceDispatcherType
;
import
org.apache.rocketmq.client.trace.
core.dispatch.AsyncDispatcher
;
import
org.apache.rocketmq.client.trace.
core.dispatch.impl.AsyncArray
Dispatcher
;
import
org.apache.rocketmq.client.trace.
core.hook.SendMessageTrack
HookImpl
;
import
org.apache.rocketmq.client.trace.
AsyncTraceDispatcher
;
import
org.apache.rocketmq.client.trace.
TraceConstants
;
import
org.apache.rocketmq.client.trace.
TraceDispatcherType
;
import
org.apache.rocketmq.client.trace.
Trace
Dispatcher
;
import
org.apache.rocketmq.client.trace.
hook.SendMessageTrace
HookImpl
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.UtilAll
;
import
org.apache.rocketmq.common.message.Message
;
...
...
@@ -133,7 +133,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
/**
* Interface of asynchronous transfer data
*/
private
Async
Dispatcher
traceDispatcher
=
null
;
private
Trace
Dispatcher
traceDispatcher
=
null
;
/**
* Default constructor.
...
...
@@ -165,25 +165,26 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
this
.
producerGroup
=
producerGroup
;
defaultMQProducerImpl
=
new
DefaultMQProducerImpl
(
this
,
rpcHook
);
//if client open the message track trace feature
//TODO wrap this code to TraceDispatcherFactory
if
(
msgTraceSwitch
)
{
try
{
Properties
tempProperties
=
new
Properties
();
tempProperties
.
put
(
Trac
kTrac
eConstants
.
MAX_MSG_SIZE
,
"128000"
);
tempProperties
.
put
(
Trac
kTrac
eConstants
.
ASYNC_BUFFER_SIZE
,
"2048"
);
tempProperties
.
put
(
Trac
kTrac
eConstants
.
MAX_BATCH_NUM
,
"100"
);
tempProperties
.
put
(
Trac
kTrac
eConstants
.
INSTANCE_NAME
,
"PID_CLIENT_INNER_TRACE_PRODUCER"
);
tempProperties
.
put
(
Trac
kTraceConstants
.
TRACE_DISPATCHER_TYPE
,
Track
TraceDispatcherType
.
PRODUCER
.
name
());
tempProperties
.
put
(
TraceConstants
.
MAX_MSG_SIZE
,
"128000"
);
tempProperties
.
put
(
TraceConstants
.
ASYNC_BUFFER_SIZE
,
"2048"
);
tempProperties
.
put
(
TraceConstants
.
MAX_BATCH_NUM
,
"100"
);
tempProperties
.
put
(
TraceConstants
.
INSTANCE_NAME
,
"PID_CLIENT_INNER_TRACE_PRODUCER"
);
tempProperties
.
put
(
Trac
eConstants
.
TRACE_DISPATCHER_TYPE
,
TraceDispatcherType
.
PRODUCER
.
name
());
if
(!
UtilAll
.
isBlank
(
traceTopicName
))
{
tempProperties
.
put
(
Trac
kTrac
eConstants
.
TRACE_TOPIC
,
traceTopicName
);
tempProperties
.
put
(
TraceConstants
.
TRACE_TOPIC
,
traceTopicName
);
}
else
{
tempProperties
.
put
(
Trac
kTrac
eConstants
.
TRACE_TOPIC
,
MixAll
.
RMQ_SYS_TRACK_TRACE_TOPIC
);
tempProperties
.
put
(
TraceConstants
.
TRACE_TOPIC
,
MixAll
.
RMQ_SYS_TRACK_TRACE_TOPIC
);
}
Async
ArrayDispatcher
dispatcher
=
new
AsyncArray
Dispatcher
(
tempProperties
,
rpcHook
);
Async
TraceDispatcher
dispatcher
=
new
AsyncTrace
Dispatcher
(
tempProperties
,
rpcHook
);
dispatcher
.
setHostProducer
(
this
.
getDefaultMQProducerImpl
());
traceDispatcher
=
dispatcher
;
this
.
getDefaultMQProducerImpl
().
registerSendMessageHook
(
new
SendMessageTrac
k
HookImpl
(
traceDispatcher
));
new
SendMessageTrac
e
HookImpl
(
traceDispatcher
));
}
catch
(
Throwable
e
)
{
log
.
error
(
"system mqtrace hook init failed ,maybe can't send msg trace data"
);
}
...
...
@@ -234,10 +235,11 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
@Override
public
void
start
()
throws
MQClientException
{
this
.
defaultMQProducerImpl
.
start
();
//TODO wrap this code to TraceDispatcherFactory
if
(
null
!=
traceDispatcher
)
{
try
{
Properties
tempProperties
=
new
Properties
();
tempProperties
.
put
(
Trac
kTrac
eConstants
.
NAMESRV_ADDR
,
this
.
getNamesrvAddr
());
tempProperties
.
put
(
TraceConstants
.
NAMESRV_ADDR
,
this
.
getNamesrvAddr
());
traceDispatcher
.
start
(
tempProperties
);
}
catch
(
MQClientException
e
)
{
log
.
warn
(
"trace dispatcher start failed "
,
e
);
...
...
@@ -864,11 +866,11 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer {
this
.
retryTimesWhenSendAsyncFailed
=
retryTimesWhenSendAsyncFailed
;
}
public
Async
Dispatcher
getTraceDispatcher
()
{
public
Trace
Dispatcher
getTraceDispatcher
()
{
return
traceDispatcher
;
}
public
void
setTraceDispatcher
(
Async
Dispatcher
traceDispatcher
)
{
public
void
setTraceDispatcher
(
Trace
Dispatcher
traceDispatcher
)
{
this
.
traceDispatcher
=
traceDispatcher
;
}
}
client/src/main/java/org/apache/rocketmq/client/trace/
core/dispatch/impl/AsyncArray
Dispatcher.java
→
client/src/main/java/org/apache/rocketmq/client/trace/
AsyncTrace
Dispatcher.java
浏览文件 @
b8cb82f4
...
...
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.dispatch.impl
;
package
org.apache.rocketmq.client.trace
;
import
org.apache.rocketmq.client.common.ThreadLocalIndex
;
import
org.apache.rocketmq.client.exception.MQClientException
;
...
...
@@ -26,11 +26,6 @@ import org.apache.rocketmq.client.producer.DefaultMQProducer;
import
org.apache.rocketmq.client.producer.MessageQueueSelector
;
import
org.apache.rocketmq.client.producer.SendCallback
;
import
org.apache.rocketmq.client.producer.SendResult
;
import
org.apache.rocketmq.client.trace.core.common.TrackTraceConstants
;
import
org.apache.rocketmq.client.trace.core.common.TrackTraceContext
;
import
org.apache.rocketmq.client.trace.core.common.TrackTraceDataEncoder
;
import
org.apache.rocketmq.client.trace.core.common.TrackTraceTransferBean
;
import
org.apache.rocketmq.client.trace.core.dispatch.AsyncDispatcher
;
import
org.apache.rocketmq.common.ThreadFactoryImpl
;
import
org.apache.rocketmq.common.message.Message
;
import
org.apache.rocketmq.common.message.MessageQueue
;
...
...
@@ -51,10 +46,7 @@ import java.util.concurrent.TimeUnit;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.apache.rocketmq.remoting.RPCHook
;
/**
* Created by zongtanghu on 2018/11/6.
*/
public
class
AsyncArrayDispatcher
implements
AsyncDispatcher
{
public
class
AsyncTraceDispatcher
implements
TraceDispatcher
{
private
final
static
InternalLogger
log
=
ClientLogger
.
getLog
();
private
final
int
queueSize
;
...
...
@@ -64,7 +56,7 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
// the last discard number of log
private
AtomicLong
discardCount
;
private
Thread
worker
;
private
ArrayBlockingQueue
<
Trac
kTrac
eContext
>
traceContextQueue
;
private
ArrayBlockingQueue
<
TraceContext
>
traceContextQueue
;
private
ArrayBlockingQueue
<
Runnable
>
appenderQueue
;
private
volatile
Thread
shutDownHook
;
private
volatile
boolean
stopped
=
false
;
...
...
@@ -75,17 +67,17 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
private
String
dispatcherId
=
UUID
.
randomUUID
().
toString
();
private
String
traceTopicName
;
public
Async
Array
Dispatcher
(
Properties
properties
,
RPCHook
rpcHook
)
throws
MQClientException
{
dispatcherType
=
properties
.
getProperty
(
Trac
kTrac
eConstants
.
TRACE_DISPATCHER_TYPE
);
int
queueSize
=
Integer
.
parseInt
(
properties
.
getProperty
(
Trac
kTrac
eConstants
.
ASYNC_BUFFER_SIZE
,
"2048"
));
public
Async
Trace
Dispatcher
(
Properties
properties
,
RPCHook
rpcHook
)
throws
MQClientException
{
dispatcherType
=
properties
.
getProperty
(
TraceConstants
.
TRACE_DISPATCHER_TYPE
);
int
queueSize
=
Integer
.
parseInt
(
properties
.
getProperty
(
TraceConstants
.
ASYNC_BUFFER_SIZE
,
"2048"
));
// queueSize is greater than or equal to the n power of 2 of value
queueSize
=
1
<<
(
32
-
Integer
.
numberOfLeadingZeros
(
queueSize
-
1
));
this
.
queueSize
=
queueSize
;
batchSize
=
Integer
.
parseInt
(
properties
.
getProperty
(
Trac
kTrac
eConstants
.
MAX_BATCH_NUM
,
"1"
));
batchSize
=
Integer
.
parseInt
(
properties
.
getProperty
(
TraceConstants
.
MAX_BATCH_NUM
,
"1"
));
this
.
discardCount
=
new
AtomicLong
(
0L
);
traceContextQueue
=
new
ArrayBlockingQueue
<
Trac
kTrac
eContext
>(
1024
);
traceContextQueue
=
new
ArrayBlockingQueue
<
TraceContext
>(
1024
);
appenderQueue
=
new
ArrayBlockingQueue
<
Runnable
>(
queueSize
);
traceTopicName
=
properties
.
getProperty
(
Trac
kTrac
eConstants
.
TRACE_TOPIC
);
traceTopicName
=
properties
.
getProperty
(
TraceConstants
.
TRACE_TOPIC
);
this
.
traceExecuter
=
new
ThreadPoolExecutor
(
//
10
,
//
20
,
//
...
...
@@ -93,7 +85,7 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
TimeUnit
.
MILLISECONDS
,
//
this
.
appenderQueue
,
//
new
ThreadFactoryImpl
(
"MQTraceSendThread_"
));
traceProducer
=
Trac
kTrac
eProducerFactory
.
getTraceDispatcherProducer
(
properties
,
rpcHook
);
traceProducer
=
TraceProducerFactory
.
getTraceDispatcherProducer
(
properties
,
rpcHook
);
}
public
String
getTraceTopicName
()
{
...
...
@@ -125,8 +117,8 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
}
public
void
start
(
Properties
properties
)
throws
MQClientException
{
Trac
kTraceProducerFactory
.
registerTraceDispatcher
(
dispatcherId
,
properties
.
getProperty
(
Track
TraceConstants
.
NAMESRV_ADDR
));
this
.
worker
=
new
Thread
(
new
AsyncRunnable
(),
"MQ-Async
Array
Dispatcher-Thread-"
+
dispatcherId
);
Trac
eProducerFactory
.
registerTraceDispatcher
(
dispatcherId
,
properties
.
getProperty
(
TraceConstants
.
NAMESRV_ADDR
));
this
.
worker
=
new
Thread
(
new
AsyncRunnable
(),
"MQ-Async
Trace
Dispatcher-Thread-"
+
dispatcherId
);
this
.
worker
.
setDaemon
(
true
);
this
.
worker
.
start
();
this
.
registerShutDownHook
();
...
...
@@ -134,7 +126,7 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
@Override
public
boolean
append
(
final
Object
ctx
)
{
boolean
result
=
traceContextQueue
.
offer
((
Trac
kTrac
eContext
)
ctx
);
boolean
result
=
traceContextQueue
.
offer
((
TraceContext
)
ctx
);
if
(!
result
)
{
log
.
info
(
"buffer full"
+
discardCount
.
incrementAndGet
()
+
" ,context is "
+
ctx
);
}
...
...
@@ -159,7 +151,7 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
public
void
shutdown
()
{
this
.
stopped
=
true
;
this
.
traceExecuter
.
shutdown
();
Trac
kTrac
eProducerFactory
.
unregisterTraceDispatcher
(
dispatcherId
);
TraceProducerFactory
.
unregisterTraceDispatcher
(
dispatcherId
);
this
.
removeShutdownHook
();
}
...
...
@@ -197,9 +189,9 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
@Override
public
void
run
()
{
while
(!
stopped
)
{
List
<
Trac
kTraceContext
>
contexts
=
new
ArrayList
<
Track
TraceContext
>(
batchSize
);
List
<
Trac
eContext
>
contexts
=
new
ArrayList
<
TraceContext
>(
batchSize
);
for
(
int
i
=
0
;
i
<
batchSize
;
i
++)
{
Trac
kTrac
eContext
context
=
null
;
TraceContext
context
=
null
;
try
{
//get track trace data element from blocking Queue — traceContextQueue
context
=
traceContextQueue
.
poll
(
5
,
TimeUnit
.
MILLISECONDS
);
...
...
@@ -214,7 +206,7 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
if
(
contexts
.
size
()
>
0
)
{
AsyncAppenderRequest
request
=
new
AsyncAppenderRequest
(
contexts
);
traceExecuter
.
submit
(
request
);
}
else
if
(
Async
Array
Dispatcher
.
this
.
stopped
)
{
}
else
if
(
Async
Trace
Dispatcher
.
this
.
stopped
)
{
this
.
stopped
=
true
;
}
}
...
...
@@ -223,13 +215,13 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
}
class
AsyncAppenderRequest
implements
Runnable
{
List
<
Trac
kTrac
eContext
>
contextList
;
List
<
TraceContext
>
contextList
;
public
AsyncAppenderRequest
(
final
List
<
Trac
kTrac
eContext
>
contextList
)
{
public
AsyncAppenderRequest
(
final
List
<
TraceContext
>
contextList
)
{
if
(
contextList
!=
null
)
{
this
.
contextList
=
contextList
;
}
else
{
this
.
contextList
=
new
ArrayList
<
Trac
kTrac
eContext
>(
1
);
this
.
contextList
=
new
ArrayList
<
TraceContext
>(
1
);
}
}
...
...
@@ -238,9 +230,9 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
sendTraceData
(
contextList
);
}
public
void
sendTraceData
(
List
<
Trac
kTrac
eContext
>
contextList
)
{
Map
<
String
,
List
<
Trac
kTraceTransferBean
>>
transBeanMap
=
new
HashMap
<
String
,
List
<
Track
TraceTransferBean
>>();
for
(
Trac
kTrac
eContext
context
:
contextList
)
{
public
void
sendTraceData
(
List
<
TraceContext
>
contextList
)
{
Map
<
String
,
List
<
Trac
eTransferBean
>>
transBeanMap
=
new
HashMap
<
String
,
List
<
TraceTransferBean
>>();
for
(
TraceContext
context
:
contextList
)
{
if
(
context
.
getTraceBeans
().
isEmpty
())
{
continue
;
}
...
...
@@ -248,15 +240,15 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
String
topic
=
context
.
getTraceBeans
().
get
(
0
).
getTopic
();
//2.use original message entity's topic as key
String
key
=
topic
;
List
<
Trac
kTrac
eTransferBean
>
transBeanList
=
transBeanMap
.
get
(
key
);
List
<
TraceTransferBean
>
transBeanList
=
transBeanMap
.
get
(
key
);
if
(
transBeanList
==
null
)
{
transBeanList
=
new
ArrayList
<
Trac
kTrac
eTransferBean
>();
transBeanList
=
new
ArrayList
<
TraceTransferBean
>();
transBeanMap
.
put
(
key
,
transBeanList
);
}
Trac
kTraceTransferBean
traceData
=
Track
TraceDataEncoder
.
encoderFromContextBean
(
context
);
Trac
eTransferBean
traceData
=
TraceDataEncoder
.
encoderFromContextBean
(
context
);
transBeanList
.
add
(
traceData
);
}
for
(
Map
.
Entry
<
String
,
List
<
Trac
kTrac
eTransferBean
>>
entry
:
transBeanMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
List
<
TraceTransferBean
>>
entry
:
transBeanMap
.
entrySet
())
{
flushData
(
entry
.
getValue
());
}
}
...
...
@@ -264,7 +256,7 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
/**
* batch sending data actually
*/
private
void
flushData
(
List
<
Trac
kTrac
eTransferBean
>
transBeanList
)
{
private
void
flushData
(
List
<
TraceTransferBean
>
transBeanList
)
{
if
(
transBeanList
.
size
()
==
0
)
{
return
;
}
...
...
@@ -273,7 +265,7 @@ public class AsyncArrayDispatcher implements AsyncDispatcher {
int
count
=
0
;
Set
<
String
>
keySet
=
new
HashSet
<
String
>();
for
(
Trac
kTrac
eTransferBean
bean
:
transBeanList
)
{
for
(
TraceTransferBean
bean
:
transBeanList
)
{
// keyset of message track trace includes msgId of or original message
keySet
.
addAll
(
bean
.
getTransKey
());
buffer
.
append
(
bean
.
getTransData
());
...
...
client/src/main/java/org/apache/rocketmq/client/trace/
core/common/Track
TraceBean.java
→
client/src/main/java/org/apache/rocketmq/client/trace/TraceBean.java
浏览文件 @
b8cb82f4
...
...
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.common
;
package
org.apache.rocketmq.client.trace
;
import
org.apache.rocketmq.common.UtilAll
;
import
org.apache.rocketmq.common.message.MessageType
;
public
class
Trac
kTrac
eBean
{
public
class
TraceBean
{
private
static
final
String
LOCAL_ADDRESS
=
UtilAll
.
ipToIPv4Str
(
UtilAll
.
getIP
());
private
String
topic
=
""
;
private
String
msgId
=
""
;
...
...
client/src/main/java/org/apache/rocketmq/client/trace/
core/common/Track
TraceConstants.java
→
client/src/main/java/org/apache/rocketmq/client/trace/TraceConstants.java
浏览文件 @
b8cb82f4
...
...
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.common
;
package
org.apache.rocketmq.client.trace
;
public
class
Trac
kTrac
eConstants
{
public
class
TraceConstants
{
public
static
final
String
NAMESRV_ADDR
=
"NAMESRV_ADDR"
;
public
static
final
String
ADDRSRV_URL
=
"ADDRSRV_URL"
;
public
static
final
String
INSTANCE_NAME
=
"InstanceName"
;
...
...
client/src/main/java/org/apache/rocketmq/client/trace/
core/common/Track
TraceContext.java
→
client/src/main/java/org/apache/rocketmq/client/trace/TraceContext.java
浏览文件 @
b8cb82f4
...
...
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.common
;
package
org.apache.rocketmq.client.trace
;
import
org.apache.rocketmq.common.message.MessageClientIDSetter
;
...
...
@@ -23,9 +23,9 @@ import java.util.List;
/**
* The context of Track Trace
*/
public
class
Trac
kTraceContext
implements
Comparable
<
Track
TraceContext
>
{
public
class
Trac
eContext
implements
Comparable
<
TraceContext
>
{
private
Trac
kTrac
eType
traceType
;
private
TraceType
traceType
;
private
long
timeStamp
=
System
.
currentTimeMillis
();
private
String
regionId
=
""
;
private
String
regionName
=
""
;
...
...
@@ -34,7 +34,7 @@ public class TrackTraceContext implements Comparable<TrackTraceContext> {
private
boolean
isSuccess
=
true
;
private
String
requestId
=
MessageClientIDSetter
.
createUniqID
();
private
int
contextCode
=
0
;
private
List
<
Trac
kTrac
eBean
>
traceBeans
;
private
List
<
TraceBean
>
traceBeans
;
public
int
getContextCode
()
{
return
contextCode
;
...
...
@@ -44,11 +44,11 @@ public class TrackTraceContext implements Comparable<TrackTraceContext> {
this
.
contextCode
=
contextCode
;
}
public
List
<
Trac
kTrac
eBean
>
getTraceBeans
()
{
public
List
<
TraceBean
>
getTraceBeans
()
{
return
traceBeans
;
}
public
void
setTraceBeans
(
List
<
Trac
kTrac
eBean
>
traceBeans
)
{
public
void
setTraceBeans
(
List
<
TraceBean
>
traceBeans
)
{
this
.
traceBeans
=
traceBeans
;
}
...
...
@@ -60,11 +60,11 @@ public class TrackTraceContext implements Comparable<TrackTraceContext> {
this
.
regionId
=
regionId
;
}
public
Trac
kTrac
eType
getTraceType
()
{
public
TraceType
getTraceType
()
{
return
traceType
;
}
public
void
setTraceType
(
Trac
kTrac
eType
traceType
)
{
public
void
setTraceType
(
TraceType
traceType
)
{
this
.
traceType
=
traceType
;
}
...
...
@@ -117,7 +117,7 @@ public class TrackTraceContext implements Comparable<TrackTraceContext> {
}
@Override
public
int
compareTo
(
Trac
kTrac
eContext
o
)
{
public
int
compareTo
(
TraceContext
o
)
{
return
(
int
)
(
this
.
timeStamp
-
o
.
getTimeStamp
());
}
...
...
@@ -127,10 +127,10 @@ public class TrackTraceContext implements Comparable<TrackTraceContext> {
sb
.
append
(
traceType
).
append
(
"_"
).
append
(
groupName
)
.
append
(
"_"
).
append
(
regionId
).
append
(
"_"
).
append
(
isSuccess
).
append
(
"_"
);
if
(
traceBeans
!=
null
&&
traceBeans
.
size
()
>
0
)
{
for
(
Trac
kTrac
eBean
bean
:
traceBeans
)
{
for
(
TraceBean
bean
:
traceBeans
)
{
sb
.
append
(
bean
.
getMsgId
()
+
"_"
+
bean
.
getTopic
()
+
"_"
);
}
}
return
"Trac
kTrac
eContext{"
+
sb
.
toString
()
+
'}'
;
return
"TraceContext{"
+
sb
.
toString
()
+
'}'
;
}
}
client/src/main/java/org/apache/rocketmq/client/trace/
core/common/Track
TraceDataEncoder.java
→
client/src/main/java/org/apache/rocketmq/client/trace/TraceDataEncoder.java
浏览文件 @
b8cb82f4
...
...
@@ -14,19 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.common
;
package
org.apache.rocketmq.client.trace
;
import
org.apache.rocketmq.common.message.MessageType
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
apache
.
rocketmq
.
client
.
trace
.
core
.
common
.
TrackTraceType
.
Pub
;
/**
* encode/decode for Track Trace Data
*/
public
class
Trac
kTrac
eDataEncoder
{
public
class
TraceDataEncoder
{
/**
* resolving traceContext list From track trace data String
...
...
@@ -34,21 +32,21 @@ public class TrackTraceDataEncoder {
* @param traceData
* @return
*/
public
static
List
<
Trac
kTrac
eContext
>
decoderFromTraceDataString
(
String
traceData
)
{
List
<
Trac
kTraceContext
>
resList
=
new
ArrayList
<
Track
TraceContext
>();
public
static
List
<
TraceContext
>
decoderFromTraceDataString
(
String
traceData
)
{
List
<
Trac
eContext
>
resList
=
new
ArrayList
<
TraceContext
>();
if
(
traceData
==
null
||
traceData
.
length
()
<=
0
)
{
return
resList
;
}
String
[]
contextList
=
traceData
.
split
(
String
.
valueOf
(
Trac
kTrac
eConstants
.
FIELD_SPLITOR
));
String
[]
contextList
=
traceData
.
split
(
String
.
valueOf
(
TraceConstants
.
FIELD_SPLITOR
));
for
(
String
context
:
contextList
)
{
String
[]
line
=
context
.
split
(
String
.
valueOf
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
));
if
(
line
[
0
].
equals
(
Pub
.
name
()))
{
Trac
kTraceContext
pubContext
=
new
Track
TraceContext
();
pubContext
.
setTraceType
(
Pub
);
String
[]
line
=
context
.
split
(
String
.
valueOf
(
TraceConstants
.
CONTENT_SPLITOR
));
if
(
line
[
0
].
equals
(
TraceType
.
Pub
.
name
()))
{
Trac
eContext
pubContext
=
new
TraceContext
();
pubContext
.
setTraceType
(
TraceType
.
Pub
);
pubContext
.
setTimeStamp
(
Long
.
parseLong
(
line
[
1
]));
pubContext
.
setRegionId
(
line
[
2
]);
pubContext
.
setGroupName
(
line
[
3
]);
Trac
kTraceBean
bean
=
new
Track
TraceBean
();
Trac
eBean
bean
=
new
TraceBean
();
bean
.
setTopic
(
line
[
4
]);
bean
.
setMsgId
(
line
[
5
]);
bean
.
setTags
(
line
[
6
]);
...
...
@@ -64,31 +62,31 @@ public class TrackTraceDataEncoder {
bean
.
setOffsetMsgId
(
line
[
12
]);
pubContext
.
setSuccess
(
Boolean
.
parseBoolean
(
line
[
13
]));
}
pubContext
.
setTraceBeans
(
new
ArrayList
<
Trac
kTrac
eBean
>(
1
));
pubContext
.
setTraceBeans
(
new
ArrayList
<
TraceBean
>(
1
));
pubContext
.
getTraceBeans
().
add
(
bean
);
resList
.
add
(
pubContext
);
}
else
if
(
line
[
0
].
equals
(
Trac
kTrac
eType
.
SubBefore
.
name
()))
{
Trac
kTraceContext
subBeforeContext
=
new
Track
TraceContext
();
subBeforeContext
.
setTraceType
(
Trac
kTrac
eType
.
SubBefore
);
}
else
if
(
line
[
0
].
equals
(
TraceType
.
SubBefore
.
name
()))
{
Trac
eContext
subBeforeContext
=
new
TraceContext
();
subBeforeContext
.
setTraceType
(
TraceType
.
SubBefore
);
subBeforeContext
.
setTimeStamp
(
Long
.
parseLong
(
line
[
1
]));
subBeforeContext
.
setRegionId
(
line
[
2
]);
subBeforeContext
.
setGroupName
(
line
[
3
]);
subBeforeContext
.
setRequestId
(
line
[
4
]);
Trac
kTraceBean
bean
=
new
Track
TraceBean
();
Trac
eBean
bean
=
new
TraceBean
();
bean
.
setMsgId
(
line
[
5
]);
bean
.
setRetryTimes
(
Integer
.
parseInt
(
line
[
6
]));
bean
.
setKeys
(
line
[
7
]);
subBeforeContext
.
setTraceBeans
(
new
ArrayList
<
Trac
kTrac
eBean
>(
1
));
subBeforeContext
.
setTraceBeans
(
new
ArrayList
<
TraceBean
>(
1
));
subBeforeContext
.
getTraceBeans
().
add
(
bean
);
resList
.
add
(
subBeforeContext
);
}
else
if
(
line
[
0
].
equals
(
Trac
kTrac
eType
.
SubAfter
.
name
()))
{
Trac
kTraceContext
subAfterContext
=
new
Track
TraceContext
();
subAfterContext
.
setTraceType
(
Trac
kTrac
eType
.
SubAfter
);
}
else
if
(
line
[
0
].
equals
(
TraceType
.
SubAfter
.
name
()))
{
Trac
eContext
subAfterContext
=
new
TraceContext
();
subAfterContext
.
setTraceType
(
TraceType
.
SubAfter
);
subAfterContext
.
setRequestId
(
line
[
1
]);
Trac
kTraceBean
bean
=
new
Track
TraceBean
();
Trac
eBean
bean
=
new
TraceBean
();
bean
.
setMsgId
(
line
[
2
]);
bean
.
setKeys
(
line
[
5
]);
subAfterContext
.
setTraceBeans
(
new
ArrayList
<
Trac
kTrac
eBean
>(
1
));
subAfterContext
.
setTraceBeans
(
new
ArrayList
<
TraceBean
>(
1
));
subAfterContext
.
getTraceBeans
().
add
(
bean
);
subAfterContext
.
setCostTime
(
Integer
.
parseInt
(
line
[
3
]));
subAfterContext
.
setSuccess
(
Boolean
.
parseBoolean
(
line
[
4
]));
...
...
@@ -108,62 +106,62 @@ public class TrackTraceDataEncoder {
* @param ctx
* @return
*/
public
static
Trac
kTraceTransferBean
encoderFromContextBean
(
Track
TraceContext
ctx
)
{
public
static
Trac
eTransferBean
encoderFromContextBean
(
TraceContext
ctx
)
{
if
(
ctx
==
null
)
{
return
null
;
}
//build message track trace of the transfering entity content bean
Trac
kTraceTransferBean
transferBean
=
new
Track
TraceTransferBean
();
Trac
eTransferBean
transferBean
=
new
TraceTransferBean
();
StringBuilder
sb
=
new
StringBuilder
(
256
);
switch
(
ctx
.
getTraceType
())
{
case
Pub:
{
Trac
kTrac
eBean
bean
=
ctx
.
getTraceBeans
().
get
(
0
);
TraceBean
bean
=
ctx
.
getTraceBeans
().
get
(
0
);
//append the content of context and traceBean to transferBean's TransData
sb
.
append
(
ctx
.
getTraceType
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getTimeStamp
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getRegionId
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getGroupName
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getTopic
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getMsgId
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getTags
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getKeys
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getStoreHost
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getBodyLength
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getCostTime
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getMsgType
().
ordinal
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getOffsetMsgId
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
isSuccess
()).
append
(
Trac
kTrac
eConstants
.
FIELD_SPLITOR
);
sb
.
append
(
ctx
.
getTraceType
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getTimeStamp
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getRegionId
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getGroupName
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getTopic
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getMsgId
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getTags
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getKeys
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getStoreHost
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getBodyLength
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getCostTime
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getMsgType
().
ordinal
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getOffsetMsgId
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
isSuccess
()).
append
(
TraceConstants
.
FIELD_SPLITOR
);
}
break
;
case
SubBefore:
{
for
(
Trac
kTrac
eBean
bean
:
ctx
.
getTraceBeans
())
{
sb
.
append
(
ctx
.
getTraceType
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getTimeStamp
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getRegionId
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getGroupName
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getRequestId
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getMsgId
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getRetryTimes
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getKeys
()).
append
(
Trac
kTrac
eConstants
.
FIELD_SPLITOR
);
//
for
(
TraceBean
bean
:
ctx
.
getTraceBeans
())
{
sb
.
append
(
ctx
.
getTraceType
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getTimeStamp
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getRegionId
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getGroupName
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getRequestId
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getMsgId
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getRetryTimes
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getKeys
()).
append
(
TraceConstants
.
FIELD_SPLITOR
);
//
}
}
break
;
case
SubAfter:
{
for
(
Trac
kTrac
eBean
bean
:
ctx
.
getTraceBeans
())
{
sb
.
append
(
ctx
.
getTraceType
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getRequestId
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getMsgId
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getCostTime
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
isSuccess
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getKeys
()).
append
(
Trac
kTrac
eConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getContextCode
()).
append
(
Trac
kTrac
eConstants
.
FIELD_SPLITOR
);
for
(
TraceBean
bean
:
ctx
.
getTraceBeans
())
{
sb
.
append
(
ctx
.
getTraceType
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getRequestId
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getMsgId
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getCostTime
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
isSuccess
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
bean
.
getKeys
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
.
append
(
ctx
.
getContextCode
()).
append
(
TraceConstants
.
FIELD_SPLITOR
);
}
}
break
;
default
:
}
transferBean
.
setTransData
(
sb
.
toString
());
for
(
Trac
kTrac
eBean
bean
:
ctx
.
getTraceBeans
())
{
for
(
TraceBean
bean
:
ctx
.
getTraceBeans
())
{
transferBean
.
getTransKey
().
add
(
bean
.
getMsgId
());
if
(
bean
.
getKeys
()
!=
null
&&
bean
.
getKeys
().
length
()
>
0
)
{
...
...
client/src/main/java/org/apache/rocketmq/client/trace/
core/dispatch/Async
Dispatcher.java
→
client/src/main/java/org/apache/rocketmq/client/trace/
Trace
Dispatcher.java
浏览文件 @
b8cb82f4
...
...
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.dispatch
;
package
org.apache.rocketmq.client.trace
;
import
java.util.Properties
;
import
org.apache.rocketmq.client.exception.MQClientException
;
...
...
@@ -23,7 +23,7 @@ import java.io.IOException;
/**
* Interface of asynchronous transfer data
*/
public
interface
Async
Dispatcher
{
public
interface
Trace
Dispatcher
{
/**
* Initialize asynchronous transfer data module
...
...
client/src/main/java/org/apache/rocketmq/client/trace/
core/common/Track
TraceDispatcherType.java
→
client/src/main/java/org/apache/rocketmq/client/trace/TraceDispatcherType.java
浏览文件 @
b8cb82f4
...
...
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.common
;
package
org.apache.rocketmq.client.trace
;
public
enum
Trac
kTrac
eDispatcherType
{
public
enum
TraceDispatcherType
{
PRODUCER
,
CONSUMER
}
client/src/main/java/org/apache/rocketmq/client/trace/
core/dispatch/impl/Track
TraceProducerFactory.java
→
client/src/main/java/org/apache/rocketmq/client/trace/TraceProducerFactory.java
浏览文件 @
b8cb82f4
...
...
@@ -14,11 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.dispatch.impl
;
package
org.apache.rocketmq.client.trace
;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.client.producer.DefaultMQProducer
;
import
org.apache.rocketmq.client.trace.core.common.TrackTraceConstants
;
import
org.apache.rocketmq.common.namesrv.TopAddressing
;
import
java.util.Map
;
...
...
@@ -27,7 +26,8 @@ import java.util.concurrent.ConcurrentHashMap;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
org.apache.rocketmq.remoting.RPCHook
;
public
class
TrackTraceProducerFactory
{
@Deprecated
public
class
TraceProducerFactory
{
private
static
Map
<
String
,
Object
>
dispatcherTable
=
new
ConcurrentHashMap
<
String
,
Object
>();
private
static
AtomicBoolean
isStarted
=
new
AtomicBoolean
(
false
);
...
...
@@ -38,18 +38,18 @@ public class TrackTraceProducerFactory {
if
(
traceProducer
==
null
)
{
traceProducer
=
new
DefaultMQProducer
(
rpcHook
);
traceProducer
.
setProducerGroup
(
Trac
kTrac
eConstants
.
GROUP_NAME
);
traceProducer
.
setProducerGroup
(
TraceConstants
.
GROUP_NAME
);
traceProducer
.
setSendMsgTimeout
(
5000
);
traceProducer
.
setInstanceName
(
properties
.
getProperty
(
Trac
kTrac
eConstants
.
INSTANCE_NAME
,
String
.
valueOf
(
System
.
currentTimeMillis
())));
String
nameSrv
=
properties
.
getProperty
(
Trac
kTrac
eConstants
.
NAMESRV_ADDR
);
traceProducer
.
setInstanceName
(
properties
.
getProperty
(
TraceConstants
.
INSTANCE_NAME
,
String
.
valueOf
(
System
.
currentTimeMillis
())));
String
nameSrv
=
properties
.
getProperty
(
TraceConstants
.
NAMESRV_ADDR
);
if
(
nameSrv
==
null
)
{
TopAddressing
topAddressing
=
new
TopAddressing
(
properties
.
getProperty
(
Trac
kTrac
eConstants
.
ADDRSRV_URL
));
TopAddressing
topAddressing
=
new
TopAddressing
(
properties
.
getProperty
(
TraceConstants
.
ADDRSRV_URL
));
nameSrv
=
topAddressing
.
fetchNSAddr
();
}
traceProducer
.
setNamesrvAddr
(
nameSrv
);
traceProducer
.
setVipChannelEnabled
(
false
);
//the max size of message is 128K
int
maxSize
=
Integer
.
parseInt
(
properties
.
getProperty
(
Trac
kTrac
eConstants
.
MAX_MSG_SIZE
,
"128000"
));
int
maxSize
=
Integer
.
parseInt
(
properties
.
getProperty
(
TraceConstants
.
MAX_MSG_SIZE
,
"128000"
));
traceProducer
.
setMaxMessageSize
(
maxSize
-
10
*
1000
);
}
return
traceProducer
;
...
...
client/src/main/java/org/apache/rocketmq/client/trace/
core/common/Track
TraceTransferBean.java
→
client/src/main/java/org/apache/rocketmq/client/trace/TraceTransferBean.java
浏览文件 @
b8cb82f4
...
...
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.common
;
package
org.apache.rocketmq.client.trace
;
import
java.util.HashSet
;
import
java.util.Set
;
...
...
@@ -22,7 +22,7 @@ import java.util.Set;
/**
* track trace transfering bean
*/
public
class
Trac
kTrac
eTransferBean
{
public
class
TraceTransferBean
{
private
String
transData
;
private
Set
<
String
>
transKey
=
new
HashSet
<
String
>();
...
...
client/src/main/java/org/apache/rocketmq/client/trace/
core/common/Track
TraceType.java
→
client/src/main/java/org/apache/rocketmq/client/trace/TraceType.java
浏览文件 @
b8cb82f4
...
...
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace
.core.common
;
package
org.apache.rocketmq.client.trace
;
public
enum
Trac
kTrac
eType
{
public
enum
TraceType
{
Pub
,
SubBefore
,
SubAfter
,
...
...
client/src/main/java/org/apache/rocketmq/client/trace/
core/
hook/ConsumeMessageTraceHookImpl.java
→
client/src/main/java/org/apache/rocketmq/client/trace/hook/ConsumeMessageTraceHookImpl.java
浏览文件 @
b8cb82f4
...
...
@@ -14,15 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace.
core.
hook
;
package
org.apache.rocketmq.client.trace.hook
;
import
org.apache.rocketmq.client.consumer.listener.ConsumeReturnType
;
import
org.apache.rocketmq.client.hook.ConsumeMessageContext
;
import
org.apache.rocketmq.client.hook.ConsumeMessageHook
;
import
org.apache.rocketmq.client.trace.
core.common.TrackTraceBean
;
import
org.apache.rocketmq.client.trace.
core.common.TrackTraceContext
;
import
org.apache.rocketmq.client.trace.
core.common.TrackTraceType
;
import
org.apache.rocketmq.client.trace.
core.dispatch.AsyncDispatcher
;
import
org.apache.rocketmq.client.trace.
TraceContext
;
import
org.apache.rocketmq.client.trace.
TraceDispatcher
;
import
org.apache.rocketmq.client.trace.
TraceBean
;
import
org.apache.rocketmq.client.trace.
TraceType
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.message.MessageConst
;
import
org.apache.rocketmq.common.message.MessageExt
;
...
...
@@ -32,9 +32,9 @@ import java.util.List;
public
class
ConsumeMessageTraceHookImpl
implements
ConsumeMessageHook
{
private
Async
Dispatcher
localDispatcher
;
private
Trace
Dispatcher
localDispatcher
;
public
ConsumeMessageTraceHookImpl
(
Async
Dispatcher
localDispatcher
)
{
public
ConsumeMessageTraceHookImpl
(
Trace
Dispatcher
localDispatcher
)
{
this
.
localDispatcher
=
localDispatcher
;
}
...
...
@@ -48,11 +48,11 @@ public class ConsumeMessageTraceHookImpl implements ConsumeMessageHook {
if
(
context
==
null
||
context
.
getMsgList
()
==
null
||
context
.
getMsgList
().
isEmpty
())
{
return
;
}
Trac
kTraceContext
traceContext
=
new
Track
TraceContext
();
Trac
eContext
traceContext
=
new
TraceContext
();
context
.
setMqTraceContext
(
traceContext
);
traceContext
.
setTraceType
(
Trac
kTrac
eType
.
SubBefore
);
//
traceContext
.
setTraceType
(
TraceType
.
SubBefore
);
//
traceContext
.
setGroupName
(
context
.
getConsumerGroup
());
//
List
<
Trac
kTraceBean
>
beans
=
new
ArrayList
<
Track
TraceBean
>();
List
<
Trac
eBean
>
beans
=
new
ArrayList
<
TraceBean
>();
for
(
MessageExt
msg
:
context
.
getMsgList
())
{
if
(
msg
==
null
)
{
continue
;
...
...
@@ -64,7 +64,7 @@ public class ConsumeMessageTraceHookImpl implements ConsumeMessageHook {
// if trace switch is false ,skip it
continue
;
}
Trac
kTraceBean
traceBean
=
new
Track
TraceBean
();
Trac
eBean
traceBean
=
new
TraceBean
();
traceBean
.
setTopic
(
msg
.
getTopic
());
//
traceBean
.
setMsgId
(
msg
.
getMsgId
());
//
traceBean
.
setTags
(
msg
.
getTags
());
//
...
...
@@ -87,14 +87,14 @@ public class ConsumeMessageTraceHookImpl implements ConsumeMessageHook {
if
(
context
==
null
||
context
.
getMsgList
()
==
null
||
context
.
getMsgList
().
isEmpty
())
{
return
;
}
Trac
kTraceContext
subBeforeContext
=
(
Track
TraceContext
)
context
.
getMqTraceContext
();
Trac
eContext
subBeforeContext
=
(
TraceContext
)
context
.
getMqTraceContext
();
if
(
subBeforeContext
.
getTraceBeans
()
==
null
||
subBeforeContext
.
getTraceBeans
().
size
()
<
1
)
{
// if subbefore bean is null ,skip it
return
;
}
Trac
kTraceContext
subAfterContext
=
new
Track
TraceContext
();
subAfterContext
.
setTraceType
(
Trac
kTrac
eType
.
SubAfter
);
//
Trac
eContext
subAfterContext
=
new
TraceContext
();
subAfterContext
.
setTraceType
(
TraceType
.
SubAfter
);
//
subAfterContext
.
setRegionId
(
subBeforeContext
.
getRegionId
());
//
subAfterContext
.
setGroupName
(
subBeforeContext
.
getGroupName
());
//
subAfterContext
.
setRequestId
(
subBeforeContext
.
getRequestId
());
//
...
...
client/src/main/java/org/apache/rocketmq/client/trace/
core/hook/SendMessageTrack
HookImpl.java
→
client/src/main/java/org/apache/rocketmq/client/trace/
hook/SendMessageTrace
HookImpl.java
浏览文件 @
b8cb82f4
...
...
@@ -14,23 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.rocketmq.client.trace.
core.
hook
;
package
org.apache.rocketmq.client.trace.hook
;
import
org.apache.rocketmq.client.hook.SendMessageContext
;
import
org.apache.rocketmq.client.hook.SendMessageHook
;
import
org.apache.rocketmq.client.producer.SendStatus
;
import
org.apache.rocketmq.client.trace.
core.common.TrackTraceBean
;
import
org.apache.rocketmq.client.trace.
core.common.Track
TraceContext
;
import
org.apache.rocketmq.client.trace.
core.common.TrackTraceType
;
import
org.apache.rocketmq.client.trace.
core.dispatch.AsyncDispatcher
;
import
org.apache.rocketmq.client.trace.
core.dispatch.impl.AsyncArrayDispatcher
;
import
org.apache.rocketmq.client.trace.
AsyncTraceDispatcher
;
import
org.apache.rocketmq.client.trace.TraceContext
;
import
org.apache.rocketmq.client.trace.
TraceDispatcher
;
import
org.apache.rocketmq.client.trace.
TraceBean
;
import
org.apache.rocketmq.client.trace.
TraceType
;
import
java.util.ArrayList
;
public
class
SendMessageTrac
k
HookImpl
implements
SendMessageHook
{
public
class
SendMessageTrac
e
HookImpl
implements
SendMessageHook
{
private
Async
Dispatcher
localDispatcher
;
private
Trace
Dispatcher
localDispatcher
;
public
SendMessageTrac
kHookImpl
(
Async
Dispatcher
localDispatcher
)
{
public
SendMessageTrac
eHookImpl
(
Trace
Dispatcher
localDispatcher
)
{
this
.
localDispatcher
=
localDispatcher
;
}
...
...
@@ -42,18 +42,18 @@ public class SendMessageTrackHookImpl implements SendMessageHook {
@Override
public
void
sendMessageBefore
(
SendMessageContext
context
)
{
//if it is message track trace data,then it doesn't recorded
if
(
context
==
null
||
context
.
getMessage
().
getTopic
().
startsWith
(((
Async
Array
Dispatcher
)
localDispatcher
).
getTraceTopicName
()))
{
if
(
context
==
null
||
context
.
getMessage
().
getTopic
().
startsWith
(((
Async
Trace
Dispatcher
)
localDispatcher
).
getTraceTopicName
()))
{
return
;
}
//build the context content of TuxeTraceContext
Trac
kTraceContext
tuxeContext
=
new
Track
TraceContext
();
tuxeContext
.
setTraceBeans
(
new
ArrayList
<
Trac
kTrac
eBean
>(
1
));
Trac
eContext
tuxeContext
=
new
TraceContext
();
tuxeContext
.
setTraceBeans
(
new
ArrayList
<
TraceBean
>(
1
));
context
.
setMqTraceContext
(
tuxeContext
);
tuxeContext
.
setTraceType
(
Trac
kTrac
eType
.
Pub
);
tuxeContext
.
setTraceType
(
TraceType
.
Pub
);
tuxeContext
.
setGroupName
(
context
.
getProducerGroup
());
//build the data bean object of message track trace
Trac
kTraceBean
traceBean
=
new
Track
TraceBean
();
Trac
eBean
traceBean
=
new
TraceBean
();
traceBean
.
setTopic
(
context
.
getMessage
().
getTopic
());
traceBean
.
setTags
(
context
.
getMessage
().
getTags
());
traceBean
.
setKeys
(
context
.
getMessage
().
getKeys
());
...
...
@@ -66,7 +66,7 @@ public class SendMessageTrackHookImpl implements SendMessageHook {
@Override
public
void
sendMessageAfter
(
SendMessageContext
context
)
{
//if it is message track trace data,then it doesn't recorded
if
(
context
==
null
||
context
.
getMessage
().
getTopic
().
startsWith
(((
Async
Array
Dispatcher
)
localDispatcher
).
getTraceTopicName
())
if
(
context
==
null
||
context
.
getMessage
().
getTopic
().
startsWith
(((
Async
Trace
Dispatcher
)
localDispatcher
).
getTraceTopicName
())
||
context
.
getMqTraceContext
()
==
null
)
{
return
;
}
...
...
@@ -80,8 +80,8 @@ public class SendMessageTrackHookImpl implements SendMessageHook {
return
;
}
Trac
kTraceContext
tuxeContext
=
(
Track
TraceContext
)
context
.
getMqTraceContext
();
Trac
kTrac
eBean
traceBean
=
tuxeContext
.
getTraceBeans
().
get
(
0
);
Trac
eContext
tuxeContext
=
(
TraceContext
)
context
.
getMqTraceContext
();
TraceBean
traceBean
=
tuxeContext
.
getTraceBeans
().
get
(
0
);
int
costTime
=
(
int
)
((
System
.
currentTimeMillis
()
-
tuxeContext
.
getTimeStamp
())
/
tuxeContext
.
getTraceBeans
().
size
());
tuxeContext
.
setCostTime
(
costTime
);
if
(
context
.
getSendResult
().
getSendStatus
().
equals
(
SendStatus
.
SEND_OK
))
{
...
...
client/src/test/java/org/apache/rocketmq/client/trace/DefaultMQConsumerWithTraceTest.java
浏览文件 @
b8cb82f4
...
...
@@ -53,7 +53,6 @@ import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl;
import
org.apache.rocketmq.client.producer.DefaultMQProducer
;
import
org.apache.rocketmq.client.producer.SendResult
;
import
org.apache.rocketmq.client.producer.SendStatus
;
import
org.apache.rocketmq.client.trace.core.dispatch.impl.AsyncArrayDispatcher
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.message.MessageClientExt
;
import
org.apache.rocketmq.common.message.MessageDecoder
;
...
...
@@ -103,7 +102,7 @@ public class DefaultMQConsumerWithTraceTest {
private
DefaultMQPushConsumer
customTraceTopicpushConsumer
;
private
Async
ArrayDispatcher
asyncArray
Dispatcher
;
private
Async
TraceDispatcher
asyncTrace
Dispatcher
;
private
MQClientInstance
mQClientTraceFactory
;
@Mock
private
MQClientAPIImpl
mQClientTraceAPIImpl
;
...
...
@@ -120,8 +119,8 @@ public class DefaultMQConsumerWithTraceTest {
pushConsumer
.
setNamesrvAddr
(
"127.0.0.1:9876"
);
pushConsumer
.
setPullInterval
(
60
*
1000
);
async
ArrayDispatcher
=
(
AsyncArray
Dispatcher
)
pushConsumer
.
getTraceDispatcher
();
traceProducer
=
async
Array
Dispatcher
.
getTraceProducer
();
async
TraceDispatcher
=
(
AsyncTrace
Dispatcher
)
pushConsumer
.
getTraceDispatcher
();
traceProducer
=
async
Trace
Dispatcher
.
getTraceProducer
();
pushConsumer
.
registerMessageListener
(
new
MessageListenerConcurrently
()
{
...
...
client/src/test/java/org/apache/rocketmq/client/trace/DefaultMQProducerWithTraceTest.java
浏览文件 @
b8cb82f4
...
...
@@ -37,7 +37,6 @@ import org.apache.rocketmq.client.producer.DefaultMQProducer;
import
org.apache.rocketmq.client.producer.SendCallback
;
import
org.apache.rocketmq.client.producer.SendResult
;
import
org.apache.rocketmq.client.producer.SendStatus
;
import
org.apache.rocketmq.client.trace.core.dispatch.impl.AsyncArrayDispatcher
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.message.Message
;
import
org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader
;
...
...
@@ -73,7 +72,7 @@ public class DefaultMQProducerWithTraceTest {
@Mock
private
MQClientAPIImpl
mQClientTraceAPIImpl
;
private
Async
ArrayDispatcher
asyncArray
Dispatcher
;
private
Async
TraceDispatcher
asyncTrace
Dispatcher
;
private
DefaultMQProducer
producer
;
private
DefaultMQProducer
customTraceTopicproducer
;
...
...
@@ -97,11 +96,11 @@ public class DefaultMQProducerWithTraceTest {
normalProducer
.
setNamesrvAddr
(
"127.0.0.1:9877"
);
customTraceTopicproducer
.
setNamesrvAddr
(
"127.0.0.1:9878"
);
message
=
new
Message
(
topic
,
new
byte
[]
{
'a'
,
'b'
,
'c'
});
async
ArrayDispatcher
=
(
AsyncArray
Dispatcher
)
producer
.
getTraceDispatcher
();
async
Array
Dispatcher
.
setTraceTopicName
(
customerTraceTopic
);
async
Array
Dispatcher
.
getHostProducer
();
async
Array
Dispatcher
.
getHostConsumer
();
traceProducer
=
async
Array
Dispatcher
.
getTraceProducer
();
async
TraceDispatcher
=
(
AsyncTrace
Dispatcher
)
producer
.
getTraceDispatcher
();
async
Trace
Dispatcher
.
setTraceTopicName
(
customerTraceTopic
);
async
Trace
Dispatcher
.
getHostProducer
();
async
Trace
Dispatcher
.
getHostConsumer
();
traceProducer
=
async
Trace
Dispatcher
.
getTraceProducer
();
producer
.
start
();
...
...
example/src/main/java/org/apache/rocketmq/example/simple/AclClient.java
浏览文件 @
b8cb82f4
...
...
@@ -40,14 +40,7 @@ import org.apache.rocketmq.common.message.MessageQueue;
import
org.apache.rocketmq.remoting.RPCHook
;
import
org.apache.rocketmq.remoting.common.RemotingHelper
;
/**
*
* 1. view the /conf/plain_acl.yml file under the distribution module, pay attention to the accessKey,secretKey,
* globalWhiteRemoteAddresses and whiteRemoteAddress and some other attributes.
*
* 2. Modify ACL_ACCESS_KEY and ACL_SECRET_KEY to the corresponding accessKey and secretKey in plain_acl.yml
*
*/
public
class
AclClient
{
private
static
final
Map
<
MessageQueue
,
Long
>
OFFSE_TABLE
=
new
HashMap
<
MessageQueue
,
Long
>();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录