Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using different subject name strategies #88

Merged
merged 2 commits into from
Jun 16, 2022

Conversation

enamrik
Copy link
Contributor

@enamrik enamrik commented Jun 13, 2022

Description

This is my attempt at adding support for subject name strategies. All new behavior is triggered by new configuration parameters to avoid breaking changes.

Changelog:

  • By default, xk6-kafka's schema registry based serializers only support the TopicName subject name strategy. To enabled the other two subject name strategies (RecordNameStrategy and TopicRecordNameStrategy) on a producer, set the subjectNameStrategy property on the producer configuration to the name of the desired strategy. To enable on a consumer, set the subjectNameStrategy property on the consumer configuration to the name of the desired strategy
const configuration = JSON.stringify({
    consumer: {
        keyDeserializer: "",
        valueDeserializer: "io.confluent.kafka.serializers.KafkaAvroDeserializer",
        useMagicPrefix: true,
       subjectNameStrategy: "RecordNameStrategy",
    },
    producer: {
        keySerializer: "",
        valueSerializer: "io.confluent.kafka.serializers.KafkaAvroSerializer",
        subjectNameStrategy: "RecordNameStrategy",
    },
    schemaRegistry: {
        url: "http://schema-registry:8081",
    },
})
  • Once a message has been published with the schemaID magic prefix, when consuming, the magic prefix can be extracted and used to get the schema. This allows dynamic schema resolution for the consumer without needing to specify the consumed message's schema. To enable this functionality, add useMagicPrefix: true to the consumer configuration.

@enamrik enamrik force-pushed the add_subject_name_strategies branch 12 times, most recently from 950236d to 63c82fc Compare June 14, 2022 18:02
Copy link
Owner

@mostafa mostafa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! 🙏
I left a few comments.

For reference:

schema_registry.go Outdated Show resolved Hide resolved
schema_registry.go Outdated Show resolved Hide resolved
scripts/helpers/schema_registry.js Show resolved Hide resolved
configuration.go Show resolved Hide resolved
avro.go Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@enamrik enamrik requested a review from mostafa June 16, 2022 16:10
Copy link
Owner

@mostafa mostafa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🙏

@mostafa mostafa merged commit 5618748 into mostafa:main Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants