RabbitMQ Trace的使用

Trace是RabbitMQ用于记录每一次发送的消息,方便使用Rabbitmq的开发者调试、排错

可通过插件形式提供可视化界面

rabbitmq_tracing插件同样会对流入流出的消息做封装,然后将封装后的消息日志存入相应的trace文件之中

(1)安装rabbitmq_tracing 插件

  选择开始菜单的RabbitMQ Command Prompt(sbin dir)

    

    进入C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.4.1\sbin输入命令

rabbitmq-plugins enable rabbitmq_tracing

 (2)浏览器打开http://localhost:15672,打开RabbitMQ的web监控工具

 (3)新增Trace

  Virtual host为testhost,格式为Text,连接的 username(eg:admin),password(eg:admin)

  在添加完trace之后,会根据匹配的规则将相应的消息日志输出到对应的trace文件之中

(4)测试

发送消息 bbbbbbbbbbbbbb

查看Trace拦截的信息

 (5)查看日志信息

直接点击“Trace log files”下面的列表直接查看对应的日志文件,如:testhost.log

发送

================================================================================
2019-11-13 7:10:14:036: Message published

Node:         rabbit@hkgi-PC
Connection:   127.0.0.1:12452 -> 127.0.0.1:5672
Virtual host: testhost
User:         admin
Channel:      2
Exchange:     
Routing keys: [<<"OrderQueue1">>]
Routed queues: [<<"OrderQueue1">>]
Properties:   [{<<"priority">>,signedint,0},
               {<<"delivery_mode">>,signedint,2},
               {<<"headers">>,table,
                [{<<"X-B3-ParentSpanId">>,longstr,<<"31b1b0a9699c2d3f">>},
                 {<<"X-B3-Sampled">>,longstr,<<"1">>},
                 {<<"spring_listener_return_correlation">>,longstr,
                  <<"c5d011b7-3052-4186-89a7-1708a3a8ebac">>},
                 {<<"X-B3-TraceId">>,longstr,<<"31b1b0a9699c2d3f">>},
                 {<<"X-B3-SpanId">>,longstr,<<"55083fa909f05ab2">>}]},
               {<<"content_encoding">>,longstr,<<"UTF-8">>},
               {<<"content_type">>,longstr,<<"text/plain">>}]
Payload: 
bbbbbbbbbbbbbb

接收

================================================================================
2019-11-13 7:10:14:036: Message received

Node:         rabbit@hkgi-PC
Connection:   127.0.0.1:12452 -> 127.0.0.1:5672
Virtual host: testhost
User:         admin
Channel:      1
Exchange:     
Routing keys: [<<"OrderQueue1">>]
Queue:        OrderQueue1
Properties:   [{<<"priority">>,signedint,0},
               {<<"delivery_mode">>,signedint,2},
               {<<"headers">>,table,
                [{<<"X-B3-ParentSpanId">>,longstr,<<"31b1b0a9699c2d3f">>},
                 {<<"X-B3-Sampled">>,longstr,<<"1">>},
                 {<<"spring_listener_return_correlation">>,longstr,
                  <<"c5d011b7-3052-4186-89a7-1708a3a8ebac">>},
                 {<<"X-B3-TraceId">>,longstr,<<"31b1b0a9699c2d3f">>},
                 {<<"X-B3-SpanId">>,longstr,<<"55083fa909f05ab2">>}]},
               {<<"content_encoding">>,longstr,<<"UTF-8">>},
               {<<"content_type">>,longstr,<<"text/plain">>}]
Payload: 
bbbbbbbbbbbbbb

说明:

  需要自己手工生成日志文件后,收发消息才会有记录

注意:

  打开 trace 会影响消息写入功能,适当打开后请关闭

关闭插件的命令

rabbitmq-plugins disable rabbitmq_tracing

 

posted @ 2019-11-13 15:19  慕尘  阅读(2722)  评论(0编辑  收藏  举报