Quantcast
Channel: Kafka Timeline
Viewing all articles
Browse latest Browse all 1519

kafka producer, one per web app?

$
0
0
In my web application, I should be creating a single instance of a producer
correct?

So in scala I should be doing something like:

object KafkaProducer {
// props...
val producer = new Producer[AnyRef, AnyRef](new ProducerConfig(props))

And then say in my QueueService I would do:

class QueueService {

def send(topic: String, message: Array[Byte], partition: Array[Byte]): Unit
= {
try {
KakfaProducer.producer.send(new KeyedMessage(topic,message,
partition))
} catch {
case e: Exception =>
e.printStackTrace
System.exit(1)

Threading wise, is this correct?

Viewing all articles
Browse latest Browse all 1519

Trending Articles