You can use the log management feature of Message Service (MNS) to push operations logs of messages to a specified logging bucket. You can specify the configurations in the MNS console to push logs to Object Storage Service (OSS) or Log Service, and enable the logging feature for queues and topics in the selected region. MNS automatically pushes the operations logs of messages in the queues and topics to the specified logging bucket.

Scenarios

The log management feature can be applied in the following scenarios:

  • 1. Track messages when messages are sent to a queue while consumer clients cannot receive the messages.
  • 2. Check which clients have consumed a message and how many times the message is consumed.
  • 3. Determine when a message that fails to be consumed due to consumer client breakdown can be consumed again.
  • 4. Check why endpoints cannot receive messages after the messages are published to a topic.
  • 5. View operations logs of messages that are generated a month ago.

You can solve these problems by using the log management feature of MNS.

  • Push logs to Log Service and view operations logs of messages in the Log Service console.
  • Use the log query tool provided by Alibaba Cloud and specify the parameters to view operations logs of messages.
  • Log on to the OSS console and configure the LifeCycle parameter of the logging bucket. You can even view operations logs that are generated a year ago. For more information, visit the OSS console.
  • In addition to the official query tool, you can also use the GetObject operation of OSS to download log files.

Push logs to Log Service

  • For more information about configuration methods, see Push logs to Log Service.
  • For more information about how to view logs, see View MNS logs in the Log Service console.
  • When creating a Logstore, you must specify an appropriate data retention period. If you want to modify the data retention period after the Logstore is created, you can only specify a shorter data retention period than that you specified when creating the Logstore.
  • If you delete the project or Logstore that corresponds to a logging bucket, or revoke the permission that is granted to MNS to access Log Service, MNS logs cannot be pushed to Log Service.
  • Pushing logs from MNS to Log Service takes about five minutes.

Push logs to OSS

  • For more information about configuration methods, see Push logs to OSS.
  • For more information about how to view logs, see View logs in OSS.
  • If you delete the OSS bucket that corresponds to a logging bucket, or cancel the permission that is granted to MNS to access OSS, MNS logs cannot be pushed to OSS.
  • Pushing logs from MNS to Log Service takes about five minutes.

Analysis of details

  • Each region has a logging bucket. All operations logs of messages in the queues and topics for which the logging feature is enabled are pushed to the logging bucket of the selected region.
  • You can enable the logging feature for queues or topics based on your needs. The logging feature is disabled by default.

Billing

  • MNS does not charge you for using the log management feature.
  • MNS pushes logs to OSS or Log Service. Then, OSS or Log Service charges you based on storage space used, data transferred, and the number of requests. For more information about billing methods, see Overview of Log Service pricing and Overview of OSS pricing.
  • The size of log entries that are generated depends on queries per second (QPS) and types of operations. For example, if you perform the SendMessage operation 1,000 times per second, the size of log entries that are generated is calculated as follows: 178 bytes × 1000 × 60/1024/1024 ≈ 10 MB, where 178 bytes indicates the size of a log entry that is generated by a single SendMessage operation.

Operations logs of queue messages

Operations logs of queue messages are generated when operations are performed on queue messages, such as sending, consuming, and deleting messages. A log entry contains multiple fields that indicate different information. The fields contained in a log entry varies based on different operations. The following tables describe each log entry field and the relationships between different operation types and log entry fields.

  • Description of each log entry field

    A log entry contains multiple fields. The following table describes each field.

    Field Description
    Time The time when the operation is performed.
    MessageId The ID of the message that is managed.
    QueueName The name of the queue that is managed.
    AccountId The Alibaba Cloud account who owns the queue.
    RemoteAddress The endpoint of the client that performs the operation.
    NextVisibleTime The time when the message is visible after the operation is complete.
    ReceiptHandleInRequest The value of the ReceiptHandle parameter that is passed into the request when the operation is performed.
    ReceiptHandleInResponse The value of the ReceiptHandle parameter that is returned after the operation is complete.
  • Fields for different operations

    Log entries that are generated by different operations contain different fields. The following table shows log entry fields for different operations.

    Operation Time QueueName AccountId MessageId RemoteAddress NextVisibleTime ReceiptHandleInResponse ReceiptHandleInRequest
    SendMessage or BatchSendMessage Yes Yes Yes Yes Yes Yes No No
    PeekMessage or BatchPeekMessage Yes Yes Yes Yes Yes No No No
    ReceiveMessage or BatchReceiveMessage Yes Yes Yes Yes Yes Yes Yes No
    ChangeMessageVisibility Yes Yes Yes Yes Yes Yes Yes Yes
    DeleteMessage or BatchDeleteMessage Yes Yes Yes Yes Yes Yes No Yes

Operations logs of topic messages

Operations logs of topic messages are generated when operations are performed on topic messages, including publishing and pushing messages. The following tables describe each log entry field and the relationships between different operation types and log entry fields.

  • Description of each log entry field

    A log entry contains multiple fields. The following table describes each field.

    Field Description
    Time The time when the operation is performed.
    MessageId The ID of the message that is managed.
    TopicName The name of the topic that is managed.
    SubscriptionName The name of the subscription that is managed.
    AccountId The Alibaba Cloud account who owns the topic.
    RemoteAddress The endpoint of the client that performs the operation.
    NotifyStatus The status code or error message returned when MNS pushes a message to a client.
  • Fields for different operations

    Log entries that are generated by different operations contain different fields. The following table shows log entry fields for different operations.

    Operation Time MessageId TopicName SubscriptionName AccountId RemoteAddress NotifyStatus SubscriptionName
    PublishMessage Yes Yes Yes No Yes Yes No No
    Notify Yes Yes Yes Yes Yes No Yes Yes
  • NotifyStatus

    NotifyStatus is a unique log entry field that helps you determine the cause when MNS fails to push messages to endpoints. The following table describes the error codes and the corresponding solutions.

    Error code Description Recommended solution
    2xx The message is pushed. N/A
    Other HTTP status codes After the message is pushed to the endpoint, an HTTP status code other than 2xx is returned. Check the processing logic of the endpoint.
    InvalidHost The specified endpoint in the subscription is invalid. Use the curl or telnet command to check whether the specified endpoint in the subscription is valid.
    ConnectTimeout The connection to the specified endpoint in the subscription times out. Use the curl or telnet command to check whether the specified endpoint in the subscription is accessible.
    ConnectFailure The connection to the specified endpoint in the subscription fails. Use the curl or telnet command to check whether the specified endpoint in the subscription is accessible.
    UnknownError An unexpected error has occurred. Contact the MNS technical support.