dasch/avro_turf

Creating consumer utilizing Schema Registry.

sandipsubedi opened this issue · 1 comments

I am trying to create a consumer that utilizes Schema Registry. I am trying to use avro_turf to top of Racecar gem.

I am able to get object from this:

avro = AvroTurf::Messaging.new(registry_url: "http://my-registry:8081/")

But I am confused what I should do next. I am just creating consumer, I don't need a producer. And I suppose this is what I should be doing:

avro.decode(data)
result = avro.decode_message(data)
result.message   

But where would I get that data from? I saw that I could do this:

data = avro.encode({ "title" => "hello, world" }, schema_id: 2)

And found out, I can leave the first hash empty:

data = avro.encode({ }, schema_id: 2)

Is keeping it empty the right way to do it?

dasch commented

AvroTurf has nothing to do with how you obtain the data you need to encode. If you're talking about needing a Kafka consumer then I recommend looking into Racecar which you can then use in combination with AvroTurf, e.g.

class MyConsumer < Racecar::Consumer
  subscribes_to "some-kafka-topic"

  def initialize
    @avro = AvroTurf::Messaging.new(registry_url: "http://my-registry:8081/")
  end

  def process(message)
    data = @avro.decode(message.value)
    ...
  end
end