salsify/avromatic

Registered schemas end up with the incorrect name

Closed this issue · 4 comments

Hello! I'm working on some code that uses both Avromatc (4.0.0) and AvroTurf (1.5.0) and I've run in to a problem that I think is on the Avromatic side of things.

I have a Avromatic model

class LogEntry
    include Avromatic::Model.build(value_schema_name: "uachieve-etl.application_log")
end

And I'm publishing that to a Kafka cluster that uses Confluent's schema registry. When I create a LogEntry and call avro_message_value it registers the schema, as I'd expect.

But the schema gets registered under the subject name of "uachieve-etl.application_log". I'd expect it to be registered under "uachieve-etl.application_log-value"

This change in subject name leads to some problems. ksqDB expects the subject name to end in -value so I can't work with the data. And Kafka Connect adapters have trouble with it too, for the same reason.

I looked at AvroTurf and saw that their messaging encode method supports an optional subject param. If passed the schema is registered under that subject. If not, then the schema is registered under the full schema name.

It looks like Avromatic's avro_message_value is calling this encode method but not providing the subject param.

Is there something I'm doing wrong here? I'd like to be able to use Avromatic here and have my schemas registered under the expected subject name of uachieve-etl.application_log-value.

Thanks!

I don't think you're doing anything wrong. Avromatic doesn't really have support for the subject param built out. That said how would you expect to be able to configure this in your example? Would something like the following feel right?

class LogEntry
    include Avromatic::Model.build(value_schema_name: "uachieve-etl.application_log", value_subject_name: "uachieve-etl.application_log-value")
end

I patched this in to my code,

module Avromatic
  module Model
    module MessagingSerialization
      module Encode
        def avro_message_value_with_subject(subject:)
          avro_messaging.encode(
            value_attributes_for_avro,
            schema_name: value_avro_schema.fullname,
            subject: subject
          )
        end
      end
    end
  end
end

And that has been working fine.

But that just covers my single use-case. It's probably not a good general-purpose solution.

@IanWhitney Just released #142 which should help with your custom subject names. Hope it helps :)