RdKafka\ProducerTopic::produce

(PECL rdkafka >= 0.9.1)

RdKafka\ProducerTopic::produceProduce and send a single message

Description

public RdKafka\ProducerTopic::produce ( integer $partition , integer $msgflags , string $payload [, string $key = NULL ] ) : void

Produce and send a single message to broker.

This is a async and non-blocking.

Parameters

partition (integer)

Can be either RD_KAFKA_PARTITION_UA (unassigned) for automatic partitioning using the topic's partitioner function (see RdKafka\TopicConf::setPartitioner(), or a fixed partition (0..N).

msgflags (integer)

Must be either 0 or RD_KAFKA_MSG_F_BLOCK

payload (string)

Payload string

key (string)

Optional message key, if non-NULL it will be passed to the topic partitioner as well as be sent with the message to the broker and passed on to the consumer.

Return Values

Returns no value.

Examples

Example #1 RdKafka\ProducerTopic::produce() example

<?php
$message 
= [
    
'type' => 'account-created',
    
'id' => $accountId,
    
'date' => date(DATE_W3C),
];

$payload json_encode($message);

$topic->produce(RD_KAFKA_PARTITION_UA0$payload$accountId);
?>