Module: Karafka::Routing::Features::Deserializers::Topic

Defined in:
lib/karafka/routing/features/deserializers/topic.rb

Overview

Routing topic deserializers API. It allows to configure deserializers for various components of each message.

Instance Method Summary collapse

Instance Method Details

#deserializer(payload) ⇒ Object

Supports pre 2.4 format where only payload deserializer could be defined. We do not retire this format because it is not bad when users do not do anything advanced with key or headers

Parameters:

  • payload (Object)

    payload deserializer



32
33
34
# File 'lib/karafka/routing/features/deserializers/topic.rb', line 32

def deserializer(payload)
  deserializers(payload: payload)
end

#deserializers(payload: ::Karafka::Deserializers::Payload.new, key: ::Karafka::Deserializers::Key.new, headers: ::Karafka::Deserializers::Headers.new) ⇒ Object

Allows for setting all the deserializers with standard defaults

Parameters:

  • payload (Object) (defaults to: ::Karafka::Deserializers::Payload.new)

    Deserializer for the message payload

  • key (Object) (defaults to: ::Karafka::Deserializers::Key.new)

    deserializer for the message key

  • headers (Object) (defaults to: ::Karafka::Deserializers::Headers.new)

    deserializer for the message headers



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/karafka/routing/features/deserializers/topic.rb', line 15

def deserializers(
  payload: ::Karafka::Deserializers::Payload.new,
  key: ::Karafka::Deserializers::Key.new,
  headers: ::Karafka::Deserializers::Headers.new
)
  @deserializers ||= Config.new(
    active: true,
    payload: payload,
    key: key,
    headers: headers
  )
end

#deserializers?Boolean

Returns Deserializers are always active.

Returns:

  • (Boolean)

    Deserializers are always active



37
38
39
# File 'lib/karafka/routing/features/deserializers/topic.rb', line 37

def deserializers?
  deserializers.active?
end

#to_hHash

Returns topic setup hash.

Returns:

  • (Hash)

    topic setup hash



42
43
44
45
46
# File 'lib/karafka/routing/features/deserializers/topic.rb', line 42

def to_h
  super.merge(
    deserializers: deserializers.to_h
  ).freeze
end