Class: Karafka::ActiveJob::Deserializer
- Inherits:
-
Object
- Object
- Karafka::ActiveJob::Deserializer
- Defined in:
- lib/karafka/active_job/deserializer.rb
Overview
Note:
Despite the name, this class handles both serialization (job to Kafka payload) and deserialization (Kafka message to job). It’s called “Deserializer” to align with Karafka’s naming conventions where message consumption is the primary concern.
Default deserializer for ActiveJob jobs
This class can be inherited and its methods can be overridden to support custom payload formats (e.g., Avro, Protobuf, MessagePack)
Instance Method Summary collapse
-
#deserialize(message) ⇒ Hash
Deserializes a Kafka message payload into an ActiveJob job hash.
-
#serialize(job) ⇒ String
Serializes an ActiveJob job into a string payload for Kafka.
Instance Method Details
#deserialize(message) ⇒ Hash
Deserializes a Kafka message payload into an ActiveJob job hash
56 57 58 |
# File 'lib/karafka/active_job/deserializer.rb', line 56 def deserialize() ::ActiveSupport::JSON.decode(.raw_payload) end |
#serialize(job) ⇒ String
Serializes an ActiveJob job into a string payload for Kafka
48 49 50 |
# File 'lib/karafka/active_job/deserializer.rb', line 48 def serialize(job) ::ActiveSupport::JSON.encode(job.serialize) end |