如何在 RabbitMQ 中记录 AMQP 命令?

How to log AMQP commands in RabbitMQ?

如何记录所有通过 RabbitMQ 代理的 AMQP 命令,包括 basic.ackconfirm.select 等服务命令?

您需要修改 rabbimq 配置。参见 this page for configuration settings

具体来说,您需要为您感兴趣的内容设置 "info" 或 "debug" 之类的内容:

[
  {log_levels, [
    {channel, debug},
    {connection, debug}
  ]}
].

从该页面查找 log_levels,您将找到以下配置信息:

Controls the granularity of logging. The value is a list of log event category and log level pairs.

The level can be one of 'none' (no events are logged), 'error' (only errors are logged), 'warning' (only errors and warning are logged), 'info' (errors, warnings and informational messages are logged), or 'debug' (errors, warnings, informational messages and debugging messages are logged).

At present there are four categories defined. Other, currently uncategorized, events are always logged.

The categories are:

  • channel - for all events relating to AMQP channels
  • connection - for all events relating to network connections
  • federation - for all events relating to federation
  • mirroring - for all events relating to mirrored queues

Default: [{connection, info}]

标准 Java 客户端库 com.rabbitmq:amqp-client:3.5.4 包含 Tracer 工具,可作为您的客户端和代理之间的独立代理。它将通过它的所有 AMQP 命令记录到 System.out

此处描述:http://www.rabbitmq.com/java-tools.html

这是其输出示例:

1441190584927: <Tracer-0> ch#1 -> {#method<channel.open>(out-of-band=), null, ""}
1441190584968: <Tracer-0> ch#1 <- {#method<channel.open-ok>(channel-id=), null, ""}
1441190585008: <Tracer-0> ch#1 -> {#method<confirm.select>(nowait=false), null, ""}
1441190585047: <Tracer-0> ch#1 <- {#method<confirm.select-ok>(), null, ""}
1441190585090: <Tracer-0> ch#1 -> {#method<basic.publish>(ticket=0, exchange=node.confirm.publish, routing-key=, mandatory=false, immediate=false), #contentHeader<basic>(content-type=string/utf8, content-encoding=null, headers=null, delivery-mode=2, priority=null, correlation-id=null, reply-to=null, expiration=null, message-id=null, timestamp=null, type=null, user-id=null, app-id=null, cluster-id=null), "some message"}
1441190585128: <Tracer-0> ch#1 <- {#method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'node.confirm.publish' in vhost '/', class-id=60, method-id=40), null, ""}