Detecting Write Failures

The publish methods in the Python client deliver the message to be published to AMPS then return immediately, without waiting for AMPS to return an acknowledgment. Likewise, the sow_delete methods request deletion of SOW messages, and return before AMPS processes the message and performs the deletion. This approach provides high performance for operations that are unlikely to fail in production. However, this means that the methods return before AMPS has processed the command, without the ability to return an error in the event the command fails.

The AMPS Python client provides a failed_write_handler that is called when the client receives an acknowledgment that indicates a failure to persist data within AMPS. As with the last_chance_message_handler described in the {ref}Unexpected Messages <#unexpected-messages> section, your application registers a handler for this function. When an acknowledgment returns that indicates a failed write, AMPS calls the registered handler method with information from the acknowledgment message, supplemented with information from the client publish store if one is available. Your client can log this information, present an error to the user or take whatever action is appropriate for the failure.

If your application needs to know whether publishes succeeded and are durably persisted, the following approach is recommended:

  • Set a PublishStore on the client. This will ensure that messages are retransmitted if the client becomes disconnected before the message is acknowledged and request persisted acknowledgments for messages.

  • Install a failed_write_handler. In the event that AMPS reports an error for a given message, that event will be reported to the failed_write_handler.

  • Call publish_flush() and verify that all messages are persisted before the application exits.

When no failed_write_handler is registered, acknowledgments that indicate errors in persisting data are treated as unexpected messages and routed to the last_chance_message_handler. In this case, AMPS provides only the acknowledgment message and does not provide the additional information from the client publish store.

Last updated