Yes. ApsaraMQ for Kafka supports the compact cleanup policy on instances running open-source version 2.2.0 or later.
What log compaction does
By default, Kafka uses the delete cleanup policy: messages are removed after they reach a retention time or size limit. The compact cleanup policy works differently -- it keeps only the latest value for each message key and discards older values.
This is useful when you only need the current state of a record rather than its full history. Common use cases include:
Database change capture -- Maintain a compacted changelog of database row updates, keeping only the latest version of each row.
Configuration or metadata storage -- Store application configuration as key-value pairs, where only the most recent setting matters.
Session state -- Track the latest session state per user or device without accumulating expired entries.
Version requirement
The compact cleanup policy requires open-source version 2.2.0 or later. If your instance runs an earlier version, upgrade it first. For steps, see Upgrade the major version of an instance.