@@ -14,26 +14,32 @@ Copyright 2012, David Arthur under Apache License, v2.0. See `LICENSE`
14
14
15
15
You need to specify the topic and partition
16
16
17
+ ``` python
17
18
kafka = KafkaClient(" localhost" , 9092 )
18
19
kafka.send_messages_simple(" my-topic" , 0 , " some message" )
19
20
kafka.close()
21
+ ```
20
22
21
23
## Send several messages to a topic
22
24
23
25
Same as before, just add more arguments to ` send_simple `
24
26
27
+ ``` python
25
28
kafka = KafkaClient(" localhost" , 9092 )
26
29
kafka.send_messages_simple(" my-topic" , 0 , " some message" , " another message" , " and another" )
27
30
kafka.close()
31
+ ```
28
32
29
33
## Recieve some messages from a topic
30
34
31
35
Supply ` get_message_set ` with a ` FetchRequest ` , get back the messages and new ` FetchRequest `
32
36
37
+ ``` python
33
38
kafka = KafkaClient(" localhost" , 9092 )
34
39
req = FetchRequest(" my-topic" , 0 , 0 , 1024 * 1024 )
35
40
(messages, req1) = kafka.get_message_set(req)
36
41
kafka.close()
42
+ ```
37
43
38
44
The returned ` FetchRequest ` includes the offset of the next message. This makes
39
45
paging through the queue very simple.
@@ -42,6 +48,7 @@ paging through the queue very simple.
42
48
43
49
For this we use the ` send_multi_message_set ` method along with ` ProduceRequest ` objects.
44
50
51
+ ``` python
45
52
kafka = KafkaClient(" localhost" , 9092 )
46
53
req1 = ProduceRequest(" my-topic-1" , 0 , [
47
54
create_message_from_string(" message one" ),
@@ -53,23 +60,28 @@ For this we use the `send_multi_message_set` method along with `ProduceRequest`
53
60
])
54
61
kafka.sent_multi_message_set([req1, req1])
55
62
kafka.close()
56
-
63
+ ```
64
+
57
65
## Iterate through all messages from an offset
58
66
59
67
The ` iter_messages ` method will make the underlying calls to ` get_message_set `
60
68
to provide a generator that returns every message available.
61
69
70
+ ``` python
62
71
kafka = KafkaClient(" localhost" , 9092 )
63
72
for msg in kafka.iter_messages(FetchRequest(" my-topic" , 0 , 0 , 1024 * 1024 )):
64
73
print (msg.payload)
65
74
kafka.close()
75
+ ```
66
76
67
77
An optional ` auto ` argument will control auto-paging through results
68
78
79
+ ``` python
69
80
kafka = KafkaClient(" localhost" , 9092 )
70
81
for msg in kafka.iter_messages(FetchRequest(" my-topic" , 0 , 0 , 1024 * 1024 ), False ):
71
82
print (msg.payload)
72
83
kafka.close()
84
+ ```
73
85
74
- This will only iterate through messages in the first byte range of
86
+ This will only iterate through messages in the byte range of
75
87
(0, 1024\* 1024)
0 commit comments