I noticed that ProducerData has been removed in 0.8 branch

If I'd wish to send a complex message type (encoded message) ,

how would I do it in 0.8?


In 0.7.X (a snippet from Neha's example)

   val producer = new Producer[Message, MemberRecord](config);


    // send a single message
    val message = new MemberRecord(1, "John", "US")
    val producerData = new ProducerData[Message,
MemberRecord]("member-records", message)
    producer.send(producerData)

class MemberRecord(val memberId: Int, val name: String, val location: String) {
  override def toString = {
    "(" + memberId + "," + name + "," + location + ")"
  }
}

class MemberRecordEncoder extends Encoder[MemberRecord] {
  def toMessage(member: MemberRecord):Message = {
    val outputStream = new ByteArrayOutputStream()
    val dos = new DataOutputStream(outputStream)
    dos.writeInt(member.memberId)
    dos.writeUTF(member.name)
    dos.writeUTF(member.location)
    outputStream.flush

    new Message(outputStream.toByteArray)
  }

Reply via email to