Search code examples
.netapache-kafkaconfluent-schema-registryconfluent-kafka-dotnet

How to define custom subject name strategy in dotnet Confluent Kafka


Currently Confluent Kafka dotnet supports three subject name strategy:

  1. Topic Name
  2. Record type
  3. TopicRecord type

I want to create a custom subject strategy where I can generate subject & schema with custom values. For example,

Subject : env.RecordTypeFullName

Please suggest


Solution

  • As you've seen, there are none with "env" prefix. Since the values are an enum, there is no easy way to override this, and it will instead throw an exception.

    https://github.com/confluentinc/confluent-kafka-dotnet/blob/master/src/Confluent.SchemaRegistry/SubjectNameStrategy.cs#L97

    IMO, it is an anti-pattern to include an "env" prefix in your schemas since dev/test/stage should all be as close to "prod" as possible. Your registry server running in "non-prod" might have the env encoded in the URL, instead, but your schema name shouldn't. The topic name (i.e. subject name) could. Then you'd use the TopicName / TopicRecord Strategy