kafka-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jun Rao <jun...@gmail.com>
Subject Re: Thread Safety of Producer
Date Thu, 28 Jul 2011 19:44:51 GMT
This should be fine. The producer has proper synchronization.

Thanks,

Jun

On Thu, Jul 28, 2011 at 11:04 AM, Blake Matheny <blake@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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message