(PECL rdkafka >= 4.0.0, librdkafka >= 1.0.0)

RdKafka::purgePurge messages handled by the producer


public RdKafka::purge ( integer $purge_flags ) : integer

Purges messages handled by the producer. The application will need to call rd_kafka_poll() or rd_kafka_flush() afterwards to serve the delivery report callbacks of the purged messages. Messages purged from internal queues fail with the delivery report error code set to RD_KAFKA_RESP_ERR__PURGE_QUEUE, while purged messages that are in-flight to or from the broker will fail with the error code set to RD_KAFKA_RESP_ERR__PURGE_INFLIGHT.


Purging messages that are in-flight to or from the broker will ignore any sub-sequent acknowledgement for these messages received from the broker, effectively making it impossible for the application to know if the messages were successfully produced or not. This may result in duplicate messages if the application retries these messages at a later time.


purge_flags (integer)

The following flags are available: RD_KAFKA_PURGE_F_QUEUE (purge internal queue), RD_KAFKA_PURGE_F_INFLIGHT (purge messages in-flight to or from the broker), RD_KAFKA_PURGE_F_NON_BLOCKING (don't wait)

Return Values

Returns RD_KAFKA_RESP_ERR_NO_ERROR on success, RD_KAFKA_RESP_ERR__INVALID_ARG for invalid purge flags, RD_KAFKA_RESP_ERR__NOT_IMPLEMENTED if called on a non-producer instance