This topic provides common Simple Log Service (SLS) queries to help you troubleshoot issues in ApsaraMQ for RabbitMQ, such as message delivery failures, consumption errors, and message backlogs.
Prerequisites
You have enabled the log management feature and configured indexes.
Common queries
This topic lists common Simple Log Service (SLS) queries. For detailed steps and log format descriptions, see log management.
Find producer IP addresses by exchange
Run the following query to list the IP addresses of producers.
* and Action : SendMessage and Code : 200 |
select
split_part(ResourceName,',',2) as exchange_name,
split_part(ResourceName, ',', 3) as routing_key,
RemoteAddress as ip_port,
count(*) as total_send_num
group by
exchange_name, routing_key, ip_port
order by
total_send_num DESC
limit 1000000
Find consumer IP addresses by queue
Run the following query to list the IP addresses of consumers.
* and Action : PushMessage and Code : 200 |
select
InstanceId as instance_id,
VHost as virtual_host,
Queue as queue_name,
RemoteAddress as ip_port,
count(*) as push_total_num
group by
instance_id,virtual_host, ip_port, queue_name
order by
push_total_num DESC
limit 10000000
Trace a message
Run a query in the search box to trace a message.
-
Trace a message by message ID
InstanceId:amqp-cn-i7m29o3s**** and VHost:cycle**** and ResourceName:msgId=27127757-44dc-4373-afc5-f8ea12f****The query returns two log entries: one with an Action of SendMessage (Code: 200) and another with an Action of PushMessage (Code: 200). This indicates that the message was successfully sent and pushed.
When a client subscribes using
BasicConsume, you can trace the message from sending to server delivery. ASendMessageaction corresponds to a client'sBasicPublishcall, and aPushMessageaction corresponds to the server pushing the message to the client. If the client pulls the message usingBasicGet, the Action isBasicGetinstead ofPushMessage.Note-
If the log results contain only one
SendMessageentry but multiplePushMessage or BasicGetentries, the client may have failed to acknowledge the message by callingBasicAckwithin theconsumption timeoutafter the firstPushMessage or BasicGet. This causes the server to assume that the consumption failed and to redeliver the message. For more information about the consumption timeout, see Instance retry policy parameter description. -
If the log results contain
SendDlqMessagelogs in addition toSendMessageandPushMessage, aSendDlqMessagelog indicates that the current message was moved to the dead-letter queue.
-
-
Check whether a message was consumed
InstanceId:amqp-cn-i7m29o3s**** and VHost:cycle**** and Queue:cycleCheckQueue**** and ConnectionId:00163efffe08281f-00004e11-0009732f-799c0af9bc4e4913-96b3**** and ChannelId:1 and (ResourceName:deliveryTag=90 or Property:deliveryTag=90) and RemoteAddress:"/192.168.XX.XX:XXXX"Obtain the values for ConnectionId, ChannelId, deliveryTag, and RemoteAddress from
PushMessagelogs. RemoteAddress is the client's IP address. ConnectionId is the unique identifier for the connection. ChannelId is the unique identifier for the channel. ThedeliveryTagis the server's unique identifier for the message. ADeleteMessagelog entry indicates that the message was successfully consumed by the client.The query returns three log entries. The Action values include
DeleteMessageandBasicAck, and the Code for each is200. This indicates that the message was successfully consumed.NoteIf a client sets
autoAck=falsewhen callingBasicConsume, the client must callBasicAckto confirm that the message was consumed. The server then deletes the message. TheBasicAckcall must be made within the consumption timeout period that starts from thePushMessagetimestamp. If the timeout period is exceeded, the server considers the consumption to have failed and redelivers the message to the client. For more information, see Instance retry policy parameter description.-
If the client called
BasicAck, but a query for message consumption status does not return aDeleteMessagelog entry, consumption failed. Check the time difference between thePushMessageandBasicAckentries. If the difference is greater than the consumption timeout, theBasicAckcall is invalid. -
If you find only
PushMessageandDeleteMessageentries but noBasicAckentry, the client may have usedBasicAck(deliveryTag, multiple=true)to acknowledge all previous messages up to the specifieddeliveryTagin a single call.
-
Analyze queue consumption rates
Run the following query to check the distribution of SendMessage, PushMessage or BasicGet, BasicAck, and DeleteMessage actions. If the percentages of these four actions are roughly equal, the production and consumption rates are balanced, with little to no message backlog.
InstanceId:amqp-cn-i7m29o3s**** and Vhost:cycle**** and Queue: cycleCheckQueue**** and (SendMessage or PushMessage or BasicAck or DeleteMessage)
In the Quick Analysis panel on the left side of the query results page, view the distribution of the Action field. For example, the distribution might be BasicAck 25%, DeleteMessage 25%, PushMessage 25%, and SendMessage 24%.
If you see any of the following patterns in the logs, analyze the likely cause:
-
No
DeleteMessageentries in the log results: This can occur if the client setautoAck=truewhen callingBasicConsumeorBasicGet. Alternatively, allBasicAckrequests from the client may have exceeded the consumption timeout, rendering the calls invalid. For more information about the consumption timeout, see Instance retry policy parameter description. -
The percentage of
PushMessageentries is much lower than that ofSendMessageentries: This may indicate insufficient subscribers. We recommend adding more connections and creating new consumers. -
The percentages of
SendMessageandPushMessageentries are similar, but the percentage ofDeleteMessageentries is much lower: This may be because manyBasicAckrequests exceeded the consumption timeout and became invalid. For more information about the consumption timeout, see Instance retry policy parameter description. -
The percentages of
SendMessage,PushMessage, andDeleteMessageentries are roughly the same, but the percentage ofBasicAckentries is much lower: Check whether your code usesBasicAck(multiple=true).
Query dead-letter messages
In the log search box, enter a query to retrieve the relevant messages.
-
Message routed to a dead-letter queue due to message TTL expiration
InstanceId:amqp-cn-i7m29o3s**** and VHost:dlq**** and ResourceName:msgId=02a162ba-f842-440f-bfd4-2595dd19****The query returns two log entries. The
Codefield for both is 200, which indicates that the message operations were successful.A
SendMessageentry corresponds to yourBasicPublishcall to send the message. ASendDlqMessageentry indicates that the message was sent to the corresponding dead-letter queue after its TTL expired.NoteThis log entry is generated only if you have configured a dead-letter queue.
-
Message routed to a dead-letter queue due to queue TTL expiration
-
Set the dead-letter properties and TTL for the queue.
Map<String, Object> argument = new HashMap<>(); argument.put("x-dead-letter-exchange", [exchangeName]); argument.put("x-dead-letter-routing-key", [routingKey]); argument.put("x-message-ttl", [ttl]); channel.queueDeclare([queueName], true, false, false, argument); -
Enter the following query in the log search box to retrieve
SendMessageandSendDlqMessageentries.InstanceId:amqp-cn-i7m29o3s**** and VHost:dlq**** and ResourceName:msgId=034a75c5-d957-422f-822e-72dfad2a****The query returns two log entries: one
SendDlqMessageaction for queue a and oneSendMessageaction for queue b. Both have a Code of 200. In the Quick Analysis panel on the left, the Action field distribution shows 50% SendMessage and 50% SendDlqMessage.
-
-
Call
BasicRejectorBasicNackwithrequeue=falseInstanceId:amqp-cn-i7m29o3s**** and VHost:dlq**** and (ResourceName:msgId=034a75c5-d957-422f-822e-72dfad2a**** or ResourceName:deliveryTag=1)A
PushMessagelog entry indicates that the server pushed a message to the client. After receiving the message, the client callsBasicReject(requeue=false). The correspondingSendDlqMessagelog entry indicates that the message was routed to the dead-letter queue.
The query returns three log entries with the following actions: PushMessage (Code: 200), BasicReject (Code: 200), and SendDlqMessage (Code: 200).