You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Blake Matheny <bl...@tumblr.com> on 2011/07/28 20:04:05 UTC
Thread Safety of Producer
I'm using a producer in an actor and wondering about the thread safety
of Producer (and Sync/Async Producer). Pseudo-code is something like:
class OurProducer(properties:Properties) extends Actor {
val config = new ProducerConfig(properties)
val producer = new Producer[Long, String](config)
def act() = {
loop {
react {
case msg:QueueMessage => producer.send(new ProducerData[Long,
String](queueName, id, Array(msg.toString))
case _ => println("Unsupported message type")
}
}
}
}
The service that uses this class instantiates just one instance, and
repeatedly sends QueueMessage's to it. There is a single Producer
instance available for use.
So, are there any potential concerns either with Producer.send or the
producer itself, being used in this way?
Thanks in advance,
-Blake
--
Blake Matheny
Re: Thread Safety of Producer
Posted by Jun Rao <ju...@gmail.com>.
This should be fine. The producer has proper synchronization.
Thanks,
Jun
On Thu, Jul 28, 2011 at 11:04 AM, Blake Matheny <bl...@tumblr.com> wrote:
> I'm using a producer in an actor and wondering about the thread safety
> of Producer (and Sync/Async Producer). Pseudo-code is something like:
>
> class OurProducer(properties:Properties) extends Actor {
> val config = new ProducerConfig(properties)
> val producer = new Producer[Long, String](config)
>
> def act() = {
> loop {
> react {
> case msg:QueueMessage => producer.send(new ProducerData[Long,
> String](queueName, id, Array(msg.toString))
> case _ => println("Unsupported message type")
> }
> }
> }
>
> }
>
> The service that uses this class instantiates just one instance, and
> repeatedly sends QueueMessage's to it. There is a single Producer
> instance available for use.
>
> So, are there any potential concerns either with Producer.send or the
> producer itself, being used in this way?
>
> Thanks in advance,
>
> -Blake
>
> --
> Blake Matheny
>