Skip to content

Commit be439d5

Browse files
committed
Adding Python syntax highlighting to README.md
1 parent 29ae9ae commit be439d5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,32 @@ Copyright 2012, David Arthur under Apache License, v2.0. See `LICENSE`
1414

1515
You need to specify the topic and partition
1616

17+
```python
1718
kafka = KafkaClient("localhost", 9092)
1819
kafka.send_messages_simple("my-topic", 0, "some message")
1920
kafka.close()
21+
```
2022

2123
## Send several messages to a topic
2224

2325
Same as before, just add more arguments to `send_simple`
2426

27+
```python
2528
kafka = KafkaClient("localhost", 9092)
2629
kafka.send_messages_simple("my-topic", 0, "some message", "another message", "and another")
2730
kafka.close()
31+
```
2832

2933
## Recieve some messages from a topic
3034

3135
Supply `get_message_set` with a `FetchRequest`, get back the messages and new `FetchRequest`
3236

37+
```python
3338
kafka = KafkaClient("localhost", 9092)
3439
req = FetchRequest("my-topic", 0, 0, 1024*1024)
3540
(messages, req1) = kafka.get_message_set(req)
3641
kafka.close()
42+
```
3743

3844
The returned `FetchRequest` includes the offset of the next message. This makes
3945
paging through the queue very simple.
@@ -42,6 +48,7 @@ paging through the queue very simple.
4248

4349
For this we use the `send_multi_message_set` method along with `ProduceRequest` objects.
4450

51+
```python
4552
kafka = KafkaClient("localhost", 9092)
4653
req1 = ProduceRequest("my-topic-1", 0, [
4754
create_message_from_string("message one"),
@@ -53,23 +60,28 @@ For this we use the `send_multi_message_set` method along with `ProduceRequest`
5360
])
5461
kafka.sent_multi_message_set([req1, req1])
5562
kafka.close()
56-
63+
```
64+
5765
## Iterate through all messages from an offset
5866

5967
The `iter_messages` method will make the underlying calls to `get_message_set`
6068
to provide a generator that returns every message available.
6169

70+
```python
6271
kafka = KafkaClient("localhost", 9092)
6372
for msg in kafka.iter_messages(FetchRequest("my-topic", 0, 0, 1024*1024)):
6473
print(msg.payload)
6574
kafka.close()
75+
```
6676

6777
An optional `auto` argument will control auto-paging through results
6878

79+
```python
6980
kafka = KafkaClient("localhost", 9092)
7081
for msg in kafka.iter_messages(FetchRequest("my-topic", 0, 0, 1024*1024), False):
7182
print(msg.payload)
7283
kafka.close()
84+
```
7385

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
7587
(0, 1024\*1024)

0 commit comments

Comments
 (0)