{"rsdb":{"rid":"372450","subhead":"","postdate":"0","aid":"261453","fid":"85","uid":"1","topic":"1","content":"
\n

\u51fd\u6570
string rd_kafka_err2str ( integer $err ) \u5c06rdkafka\u9519\u8bef\u4ee3\u7801\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<\/p> \n

integer rd_kafka_errno2err ( integer $errnox ) \u5c06\u7cfb\u7edferrno\u8f6c\u6362\u4e3aKafka\u9519\u8bef\u4ee3\u7801<\/p> \n

integer rd_kafka_errno ( void ) \u8fd4\u56de\u7cfb\u7edferrno<\/p> \n

integer rd_kafka_offset_tail ( integer $cnt ) \u8fd4\u56de\u4e00\u4e2a\u7279\u6b8a\u7684\u504f\u79fb\u91cf\u503c\uff0c\u8be5\u503c\u53ef\u7528\u4e8e\u5728\u4e3b\u9898\u5c3e\u90e8\u4e4b\u524d\u5f00\u59cb\u4f7f\u7528cnt\u6d88\u606f<\/p> \n

RdKafka\\KafkaConsume\u7c7b
\u8fd9\u662f\u9ad8\u6c34\u5e73\u6d88\u8d39\u8005\uff0c\u652f\u6301\u81ea\u52a8\u5206\u533a\/\u64a4\u9500\uff08pecl rdkafka>=1.0.0,librdkafka>=0.9\uff09<\/p> \n

1)public void RdKafka\\KafkaConsumer::assign ([ array $topic_partitions = NULL ] )
\u66f4\u65b0\u5206\u914d\u96c6\u5230$topic_partitions,\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528RdKafka\\Conf::setDefaultTopicConf()\u6765\u66f4\u6539\u4e3b\u9898\u7684\u9ed8\u8ba4\u914d\u7f6e
$kafkaConsumer->assign([
new RdKafka\\TopicPartition("logs", 0),
new RdKafka\\TopicPartition("logs", 1),
]);<\/p> \n

2)public void RdKafka\\KafkaConsumer::commit ([ mixed $message_or_offsets = NULL ] )
\u540c\u6b65\u63d0\u4ea4\u504f\u79fb\uff0c\u76f4\u5230\u63d0\u4ea4\u504f\u79fb\u6216\u63d0\u4ea4\u5931\u8d25\u4e3a\u6b62\u3002
\u5982\u679c\u6ce8\u518c\u4e86COMMIT_CB\u56de\u8c03\uff0c\u90a3\u4e48\u5b83\u5c06\u88ab\u8c03\u7528\uff0c\u5e76\u5305\u542b\u672a\u6765\u8981\u4f7f\u7528\u7684\u8c03\u7528\u7684\u63d0\u4ea4\u8be6\u7ec6\u4fe1\u606f\u3002
\u53c2\u6570
message_or_offsets
When NULL, commit offsets for the current assignment.
When a RdKafka\\Message, commit offset for a single topic+partition based on the message.
When an array of RdKafka\\TopicPartition, commit offsets for the provided list of partitions.
\u5f02\u5e38
Errors\/Exceptions
Throws RdKafka\\Exception on errors.
\u4f8b\u5b50:
\/\/ Commit offsets for the current assignment
$kafkaConsumer->commit();<\/p> \n

\/\/ Commit offsets based on the message's topic, partition, and offset
$kafkaConsumer->commit($message);<\/p> \n

\/\/ Commit offsets by providing a list of TopicPartition
$kafkaConsumer->commit([
new RdKafka\\TopicPartition($topic, $partition, $offset),
]);<\/p> \n

3)public void RdKafka\\KafkaConsumer::commitAsync ([ string $message_or_offsets = NULL ] )
\u5f02\u6b65\u63d0\u4ea4\u504f\u79fb
4)public RdKafka\\KafkaConsumer::__construct ( RdKafka\\Conf $conf )
\u53c2\u6570
conf (RdKafka\\Conf)
The conf object must have group.id set to the consumer group to join.
conf\u5bf9\u8c61\u5fc5\u987b\u5c06Group.id\u8bbe\u7f6e\u4e3a\u8981\u52a0\u5165\u7684\u6d88\u8d39\u8005\u7ec4\u3002
\u793a\u4f8b\uff1a
$conf = new RdKafka\\Conf();
$conf->set("group.id", "myGroupID");<\/p> \n

$kafkaConsumer = new RdKafka\\KafkaConsumer($conf);
5)public RdKafka\\Message RdKafka\\KafkaConsumer::consume ( string $timeout_ms )
\u4f7f\u7528\u6d88\u606f\u6216\u83b7\u53d6\u9519\u8bef\u4e8b\u4ef6\uff0c\u89e6\u53d1\u56de\u8c03
\u5c06\u81ea\u52a8\u8c03\u7528\u4efb\u4f55\u6b64\u7c7b\u6392\u961f\u4e8b\u4ef6\u7684\u5df2\u6ce8\u518c\u56de\u8c03\uff0c\u5305\u62ecrebalance_cb, event_cb, commit_cb, etc.
\u53c2\u6570
timeout_ms (int) \u8d85\u65f6\u65f6\u95f4(milliseconds)
\u8fd4\u56de\u503c
Returns a RdKafka\\Message. On error or timeout, RdKafka\\Message::$err is != RD_KAFKA_ERR_NO_ERROR, and other properties should be ignored.
\u6ce8\u610f\uff1a
\u5e94\u7528\u7a0b\u5e8f\u5e94\u786e\u4fdd\u5b9a\u671f\u8c03\u7528consume ()\uff0c\u5373\u4f7f\u6ca1\u6709\u9884\u671f\u7684\u6d88\u606f\uff0c\u4e3a\u7b49\u5f85\u8c03\u7528\u7684\u6392\u961f\u56de\u8c03\u63d0\u4f9b\u670d\u52a1\uff0c\u5f53rebalnce_cb\u5df2\u7ecf\u6ce8\u518c\u65f6\uff0c\u8fd9\u4e00\u70b9\u5c24\u5176\u91cd\u8981\uff0c\u56e0\u4e3a\u9700\u8981\u6b63\u786e\u5730\u8c03\u7528\u548c\u5904\u7406\u5b83\uff0c\u4ee5\u540c\u6b65\u5185\u90e8\u4f7f\u7528\u8005\u72b6\u6001\u3002<\/p> \n


while (true) {
$message = $kafkaConsumer->consume(3600e3);
switch ($message->err) {
case RD_KAFKA_RESP_ERR_NO_ERROR:
handle($message);
break;
case RD_KAFKA_RESP_ERR__TIMED_OUT:
echo "Timedout\\n";
break;
default:
throw new \\Exception($message->errstr());
break;
}
}<\/p> \n

6)public array RdKafka\\KafkaConsumer::getAssignment ( void )
\u8fd4\u56de\u7531assign\u8bbe\u7f6e \u6216 \u518d\u5e73\u8861\u7684 \u5f53\u524d\u5206\u533a\u5206\u914d\u96c6
Returns the current partition assignment as set by RdKafka\\KafkaConsumer::assign() or by rebalancing.
\u8fd4\u56de\u503c
Returns an array of RdKafka\\TopicPartition \u8fd4\u56deRdKafka\\Topic\u5206\u533a\u7684\u6570\u7ec4
Errors\/Exceptions
Throws RdKafka\\Exception on errors.<\/p> \n

6)public RdKafka\\Metadata RdKafka\\KafkaConsumer::getMetadata ( bool $all_topics , RdKafka\\KafkaConsumerTopic $only_topic = NULL , int $timeout_ms)
\u5411\u4ee3\u7406\u8bf7\u6c42\u5143\u6570\u636e<\/p> \n

\u53c2\u6570
all_topics (bool)
When TRUE, request info about all topics in cluster. Else, only request info about locally known topics.\u5982\u679c\u4e3a\u771f\uff0c\u8bf7\u6c42\u6709\u5173\u96c6\u7fa4\u4e2d\u6240\u6709\u4e3b\u9898\u7684\u4fe1\u606f\u3002\u5426\u5219\uff0c\u53ea\u8bf7\u6c42\u6709\u5173\u672c\u5730\u5df2\u77e5\u4e3b\u9898\u7684\u4fe1\u606f
only_topic (RdKafka\\KafkaConsumerTopic)
When non-null, only request info about this topic\u5f53\u975e\u7a7a\u65f6\uff0c\u53ea\u8bf7\u6c42\u6709\u5173\u6b64\u4e3b","orderid":"0","title":"RdKafka\u6587\u6863\u7ffb\u8bd1(\u4e00)","smalltitle":"","mid":"0","fname":"PHP","special_id":"0","bak_id":"0","info":"0","hits":"253","pages":"9","comments":"0","posttime":"2019-09-19 11:10:25","list":"1568862625","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"RdKafka<\/A> \u6587\u6863<\/A> \u7ffb\u8bd1<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.32","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"RdKafka\u6587\u6863\u7ffb\u8bd1","lastview":"1714127465","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}