Module: Karafka::Pro::ScheduledMessages::SchemaValidator

Defined in:
lib/karafka/pro/scheduled_messages/schema_validator.rb

Overview

Validator that checks if we can process this scheduled message If we encounter message that has a schema version higher than our process is aware of we raise and error and do not process. This is to make sure we do not deal with messages that are not compatible in case of schema changes.

Class Method Summary collapse

Class Method Details

.call(message) ⇒ Object

Check if we can work with this schema message and raise error if not.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/karafka/pro/scheduled_messages/schema_validator.rb', line 43

def call(message)
  message_version = message.headers["schedule_schema_version"]

  # Versions are semver, so they need to be compared segment-wise and not as strings
  # ("1.2.0" is older than "1.10.0" but lexicographically greater)
  message_gem_version = Gem::Version.new(message_version)
  current_gem_version = Gem::Version.new(ScheduledMessages::SCHEMA_VERSION)

  return if message_gem_version <= current_gem_version

  raise Errors::IncompatibleSchemaError, message_version
end