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 register_schemas option to encode method #210

Merged
merged 8 commits into from
Aug 23, 2024

Conversation

zinahia
Copy link
Contributor

@zinahia zinahia commented Aug 22, 2024

Hi!

I would like to add the possibility to not register a new schema when encoding a message and passing the schema_name option only.

The motivation for this is that most of the times the schema evolution (registering and updates) are done during the Continuous Delivery process (during deployments, right before putting the new application code live), since this process is very delicate and we do not want to risk accidentally evolving the schema when trying things out in the development phase, I think it's important to have the option to tell the library to use a register_schemas false mode while encoding.

In my company, currently the applications do not have to keep track of the current schema_id or even the version of the schemas used. So generally we call the encode method with the following options:

avro.encode(message_payload, schema_name: the_schema_name, validate: true)

The problem with this is that, if by any chance we're testing things out locally, there is a risk to trigger an evolution of the schema by registering a new version that was not ready to be evolved.

In order to avoid that, we want to provide the register_schemas option, which only in case of false checks if the schema is already registered (by using the existing check action) and caches the schema so that it's only checked once, if it exists, it returns the schema_id from there instead of attempting to register it.

This change is 100% backwards compatible, as the current behavior only changes if the user decides to pass the register_schemas option set to false.

Comment on lines +67 to +68
context, _subject = parse_qualified_subject(params[:subject])
schema_id = SCHEMAS[context].index(schema)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was already fixed in the parent but was failing here so all I did was copy the same behavior

Copy link
Owner

@dasch dasch left a comment

Choose a reason for hiding this comment

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

Generally looks good, but I think we should use a different name for the argument!

lib/avro_turf/messaging.rb Outdated Show resolved Hide resolved
Copy link
Owner

@dasch dasch left a comment

Choose a reason for hiding this comment

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

🥳

@dasch dasch merged commit 501bdd0 into dasch:master Aug 23, 2024
4 checks passed
@zinahia zinahia changed the title Add read_only option to encode method Add register_schemas option to encode method Aug 23, 2024
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