Skip to content

Commit 165941f

Browse files
committed
save work
1 parent d9a5086 commit 165941f

16 files changed

+267
-0
lines changed

content/topicHandle/_index.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: "Topic handle"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---

content/topicHandle/about.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: "About"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
Consumer topic handles are mainly used to query things like:
8+
- metadata
9+
- offsets
10+
11+
Producer topic handles can be used to query the same things
12+
but are also used to produce messages.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: "ConsumerTopic"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: "getName"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function getName(): string {}
10+
```
11+
Get topic name
12+
## Example
13+
```php
14+
$conf = new Kafka\Configuration();
15+
$conf->set('auto.offset.reset', 'earliest');
16+
$consumer = new Kafka\Consumer($conf);
17+
$consumerTopic = $consumer->getTopicHandle('test-topic');
18+
echo sprintf('Topic name: %s', $consumerTopic->getName()) . PHP_EOL;
19+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: "ProducerTopic"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: "getName"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function getName(): string {}
10+
```
11+
Get topic name
12+
## Example
13+
```php
14+
$conf = new Kafka\Configuration();
15+
$conf->set('auto.offset.reset', 'earliest');
16+
$producer = new Kafka\Producer($conf);
17+
$producerTopic = $producer->getTopicHandle('test-topic');
18+
echo sprintf('Topic name: %s', $producerTopic->getName()) . PHP_EOL;
19+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "produce"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function produce(
10+
int $partition,
11+
int $msgFlags,
12+
?string $payload = null,
13+
?string $key = null
14+
): void {}
15+
```
16+
Produce a message to a topic partition
17+
This is an asynchronous and non-blocking call
18+
## Parameter details
19+
partition: can be either a partition number or `RD_KAFKA_PARTITION_UA` for automatic partitioning
20+
msgflags: `0` or `RD_KAFKA_MSG_F_BLOCK` to block the producer if the queue is full
21+
key: message key, if non-null the topic partitioner will calculate the partition according to the key
22+
## Example
23+
```php
24+
$conf = new Kafka\Configuration();
25+
$conf->set('auto.offset.reset', 'earliest');
26+
$producer = new Kafka\Producer($conf);
27+
$producerTopic = $producer->getTopicHandle('test-topic');
28+
$producerTopic->produce(
29+
RD_KAFKA_PARTITION_UA,
30+
RD_KAFKA_MSG_F_BLOCK, // will block produce if queue is full
31+
'some message',
32+
'message-key'
33+
);
34+
```
35+
{{< hint danger >}}
36+
If you are done producing messages, you need to call `flush()`
37+
If you do not call `flush()`, it can lead to message loss
38+
{{< /hint >}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: "producev"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function producev(
10+
int $partition,
11+
int $msgFlags,
12+
?string $payload = null,
13+
?string $key = null,
14+
?array $headers = null,
15+
?int $timestampMs = null
16+
): void {}
17+
```
18+
Produce a message and additional data to a topic partition
19+
This is an asynchronous and non-blocking call
20+
## Parameter details
21+
partition: can be either a partition number or `RD_KAFKA_PARTITION_UA` for automatic partitioning
22+
msgflags: `0` or `RD_KAFKA_MSG_F_BLOCK` to block the producer if the queue is full
23+
key: message key, if non-null the topic partitioner will calculate the partition according to the key
24+
## Example
25+
```php
26+
$conf = new Kafka\Configuration();
27+
$conf->set('auto.offset.reset', 'earliest');
28+
$producer = new Kafka\Producer($conf);
29+
$producerTopic = $producer->getTopicHandle('test-topic');
30+
$producerTopic->produce(
31+
RD_KAFKA_PARTITION_UA,
32+
RD_KAFKA_MSG_F_BLOCK, // will block produce if queue is full
33+
'some message',
34+
'message-key',
35+
[
36+
'some header' => 'some header value'
37+
],
38+
round(microtime(true) * 1000) //timestam for this event
39+
);
40+
```
41+
{{< hint danger >}}
42+
If you are done producing messages, you need to call `flush()`
43+
If you do not call `flush()`, it can lead to message loss
44+
{{< /hint >}}

content/topicPartition/__construct.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "__construct"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function __construct(string $topicName, int $partition, int $offset = 0) {}
10+
```
11+
Create new topic partition instance
12+
## Example
13+
```php
14+
$topicPartition = new Kafka\TopicPartiton('test-topic', 0);
15+
```

content/topicPartition/_index.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: "Topic partition"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---

content/topicPartition/getOffset.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "getOffset"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function getOffset(): int {}
10+
```
11+
Get offset of topic partition
12+
## Example
13+
```php
14+
$topicPartition = new Kafka\TopicPartiton('test-topic', 0, 100);
15+
echo sprintf('TopicPartition offset %d', $topicPartition->getOffset()) . PHP_EOL;
16+
```
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "getPartition"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function getPartition(): int {}
10+
```
11+
Get partition of topic partition
12+
## Example
13+
```php
14+
$topicPartition = new Kafka\TopicPartiton('test-topic', 0, 100);
15+
echo sprintf('TopicPartition partition %d', $topicPartition->getPartition()) . PHP_EOL;
16+
```
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "getTopicName"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function getTopicName(): string {}
10+
```
11+
Get topic name of topic partition
12+
## Example
13+
```php
14+
$topicPartition = new Kafka\TopicPartiton('test-topic', 0, 100);
15+
echo sprintf('Topic partition name %s', $topicPartition->getTopicName()) . PHP_EOL;
16+
```

content/topicPartition/setOffset.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "setOffset"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function setOffset(int $offset): TopicPartition {}
10+
```
11+
Set offset of topic partition
12+
## Example
13+
```php
14+
$topicPartition = new Kafka\TopicPartiton('test-topic', 0);
15+
$topicPartition->setOffset(100);
16+
```
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "setPartition"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function setPartition(int $partition): TopicPartition {}
10+
```
11+
Set partition of topic partition
12+
## Example
13+
```php
14+
$topicPartition = new Kafka\TopicPartiton('test-topic', 0);
15+
$topicPartition->setPartition(1);
16+
```
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "setTopicName"
3+
date: 2020-12-27T22:09:37+01:00
4+
draft: false
5+
geekdocCollapseSection: true
6+
---
7+
## Description
8+
```php
9+
public function setTopicName(string $topicName): TopicPartition {}
10+
```
11+
Set topic name of topic partition
12+
## Example
13+
```php
14+
$topicPartition = new Kafka\TopicPartiton('test-topic', 0);
15+
$topicPartition->setTopicName('another-test-topic');
16+
```

0 commit comments

Comments
 (0)