@@ -17,9 +17,8 @@ Copyright 2013, David Arthur under Apache License, v2.0. See `LICENSE`
17
17
18
18
# Status
19
19
20
- I'm following the version numbers of Kafka, plus one number to indicate the
21
- version of this project. The current version is 0.8.0-1. This version is under
22
- development, APIs are subject to change.
20
+ The current version of this package is ** 0.9.0** and is compatible with
21
+ Kafka brokers running version ** 0.8.1** .
23
22
24
23
# Usage
25
24
@@ -33,24 +32,24 @@ from kafka.producer import SimpleProducer, KeyedProducer
33
32
kafka = KafkaClient(" localhost:9092" )
34
33
35
34
# To send messages synchronously
36
- producer = SimpleProducer(kafka, " my-topic " )
37
- producer.send_messages(" some message" )
38
- producer.send_messages(" this method" , " is variadic" )
35
+ producer = SimpleProducer(kafka)
36
+ producer.send_messages(" my-topic " , " some message" )
37
+ producer.send_messages(" my-topic " , " this method" , " is variadic" )
39
38
40
39
# To send messages asynchronously
41
- producer = SimpleProducer(kafka, " my-topic " , async = True )
42
- producer.send_messages(" async message" )
40
+ producer = SimpleProducer(kafka, async = True )
41
+ producer.send_messages(" my-topic " , " async message" )
43
42
44
43
# To wait for acknowledgements
45
44
# ACK_AFTER_LOCAL_WRITE : server will wait till the data is written to
46
45
# a local log before sending response
47
46
# ACK_AFTER_CLUSTER_COMMIT : server will block until the message is committed
48
47
# by all in sync replicas before sending a response
49
- producer = SimpleProducer(kafka, " my-topic " , async = False ,
48
+ producer = SimpleProducer(kafka, async = False ,
50
49
req_acks = SimpleProducer.ACK_AFTER_LOCAL_WRITE ,
51
- acks_timeout = 2000 )
50
+ ack_timeout = 2000 )
52
51
53
- response = producer.send_messages(" async message" )
52
+ response = producer.send_messages(" my-topic " , " async message" )
54
53
55
54
if response:
56
55
print (response[0 ].error)
@@ -63,7 +62,7 @@ if response:
63
62
# Notes:
64
63
# * If the producer dies before the messages are sent, there will be losses
65
64
# * Call producer.stop() to send the messages and cleanup
66
- producer = SimpleProducer(kafka, " my-topic " , batch_send = True ,
65
+ producer = SimpleProducer(kafka, batch_send = True ,
67
66
batch_send_every_n = 20 ,
68
67
batch_send_every_t = 60 )
69
68
@@ -84,11 +83,11 @@ from kafka.partitioner import HashedPartitioner, RoundRobinPartitioner
84
83
kafka = KafkaClient(" localhost:9092" )
85
84
86
85
# HashedPartitioner is default
87
- producer = KeyedProducer(kafka, " my-topic " )
88
- producer.send(" key1" , " some message" )
89
- producer.send(" key2" , " this methode" )
86
+ producer = KeyedProducer(kafka)
87
+ producer.send(" my-topic " , " key1" , " some message" )
88
+ producer.send(" my-topic " , " key2" , " this methode" )
90
89
91
- producer = KeyedProducer(kafka, " my-topic " , partitioner = RoundRobinPartitioner)
90
+ producer = KeyedProducer(kafka, partitioner = RoundRobinPartitioner)
92
91
```
93
92
94
93
## Multiprocess consumer
0 commit comments