代码拉取完成,页面将自动刷新
Class longlang\phpkafka\Producer\ProducerConfig
You can pass an array to a constructor.
Key | Description | Default |
---|---|---|
connectTimeout | Connection timeout(unit: second, decimal). -1 means no limit. |
-1 |
sendTimeout | Connection timeout(unit: second, decimal). -1 means no limit. |
-1 |
recvTimeout | Connection timeout(unit: second, decimal).-1 means no limit. |
-1 |
clientId | Kafka client ID | null |
maxWriteAttempts | Maximum attempts to write | 3 |
client | Kafka client used. null by default means auto recognition. |
null |
socket | Kafka Socket used. null by default means auto recognition. |
null |
brokers | Configure brokers. If configure it manually, set updateBrokers to true . Format: '127.0.0.1:9092,127.0.0.1:9093' or ['127.0.0.1:9092','127.0.0.1:9093']
|
null |
bootstrapServers | Alias bootstrapServer, used to boot the server. If configured, the server will be connected and brokers updated. Format: '127.0.0.1:9092,127.0.0.1:9093' or ['127.0.0.1:9092','127.0.0.1:9093']
|
null |
updateBrokers | Auto update brokers | true |
acks | The producer acknowledges the leader before responding. 0 means not confirmed, 1 means the leader confirmed, -1 means ISR. | 0 |
producerId | producer ID | -1 |
producerEpoch | producer Epoch | -1 |
partitionLeaderEpoch | partition Leader Epoch | -1 |
autoCreateTopic | auto create topic | true |
exceptionCallback | This callback is called when an exception that cannot be thrown by the recv() coroutine is encountered. Format: function(\Exception $e){}
|
null |
partitioner | Partitioning strategy | Default: \longlang\phpkafka\Producer\Partitioner\DefaultPartitioner
|
Default partitioning strategy:
If partition !== null, then use partition
If partition === null && key !== null, then use crc32(key) % partitions to select partition
If partition === null && key === null, then use Round Robin to select partition
Example
use longlang\phpkafka\Producer\Producer;
use longlang\phpkafka\Producer\ProducerConfig;
$config = new ProducerConfig();
$config->setBootstrapServer('127.0.0.1:9092');
$config->setUpdateBrokers(true);
$config->setAcks(-1);
$producer = new Producer($config);
$topic = 'test';
$value = (string) microtime(true);
$key = uniqid('', true);
$producer->send('test', $value, $key);
Example
use longlang\phpkafka\Producer\ProduceMessage;
use longlang\phpkafka\Producer\Producer;
use longlang\phpkafka\Producer\ProducerConfig;
$config = new ProducerConfig();
$config->setBootstrapServer('127.0.0.1:9092');
$config->setUpdateBrokers(true);
$config->setAcks(-1);
$producer = new Producer($config);
$topic = 'test';
$partition0 = 0;
$partition1 = 1;
$producer->sendBatch([
new ProduceMessage($topic, 'v1', 'k1', $partition0),
new ProduceMessage($topic, 'v2', 'k2', $partition1),
]);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。