# 6. Utility Commands

AMPS includes two commands to help applications function as expected.

## flush

Sends a command to AMPS that returns an acknowledgment when all previous commands from this client have been processed. This command helps applications that use AMPS determine when AMPS has received all of the messages that have been sent, making it safe for the client to exit.

### Header Fields

The following table contains the header fields available to a `flush` command.

Field | Description
--- | ---
`Command` | The command to be executed. Value: `flush`.
`ClientName` | A string identifier used to give a client a unique id.
`AckType` | Acknowledgment type for the given command. Value is a comma separated list of one or more of the following: `none`, `completed` or `processed`.

Header fields supported by flush

### Returns

A `flush` message specifying an `AckType` of `completed` or `processed` will receive an `ack` message when all previous messages from this client have been processed by AMPS.

The following table contains the acknowledgment messages that can be returned by a `flush` command.

Acknowledgment | Description
--- | ---
`none` | No `ack` message is returned. This is the default behavior.
`completed` | All previous commands have been processed by AMPS.
`persisted` | All previous commands from this publisher have been persisted by AMPS (or have failed and produced the requested acknowledgments).
`processed` | AMPS has processed the `flush` message.
`received` | The `flush` command has been received.
`stats` | Not supported at this time.

Acknowledgment messages supported by flush

## heartbeat

Sends a command to AMPS that starts or refreshes a heartbeat timer. When a heartbeat timer is active, AMPS publishes periodic heartbeat messages to AMPS and expects the client to respond with a heartbeat message. If the client does not provide a heartbeat within the time specified, AMPS logs an error and disconnects the connection.

The AMPS client libraries automatically manage creating and returning heartbeats. It is rarely, if ever, necessary for an application to manage heartbeats. See the Developer Guide for the client library you are using for details.

### Header Fields

The following table contains the header fields available to a `heartbeat` command.

Field | Description
--- | ---
`Command` | The command to be executed. Value: `heartbeat`.
`Options` | Specifies whether this command starts the timer or refreshes the timer. Valid options are: `start`, immediately followed by an interval. This option specifies that the command starts a timer, and sets the interval at which AMPS will expect heartbeat messages. For example, to specify an interval of 5 seconds, the option is `start,5` `beat`. This option specifies that the command refreshes the heartbeat timer.

Header fields supported by heartbeat

### Returns

The `heartbeat` message does not typically request an acknowledgment, and therefore does not receive a response. The command can, however, request acknowledgments as listed below.

Acknowledgment | Description
--- | ---
`none` | Not supported at this time.
`completed` | Not supported at this time.
`parsed` | Not supported at this time.
`persisted` | Not supported at this time.
`processed` | AMPS has processed the `heartbeat` message.
`received` | AMPS has received the `heartbeat` message.
`stats` | Not supported at this time.

Acknowledgment messages supported by heartbeat