Class: GovukMessageQueueConsumer::JSONProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_message_queue_consumer/json_processor.rb

Constant Summary collapse

JSON_FORMAT =
"application/json".freeze

Instance Method Summary collapse

Constructor Details

#initialize(next_processor) ⇒ JSONProcessor

Returns a new instance of JSONProcessor.



5
6
7
# File 'lib/govuk_message_queue_consumer/json_processor.rb', line 5

def initialize(next_processor)
  @next_processor = next_processor
end

Instance Method Details

#process(message) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/govuk_message_queue_consumer/json_processor.rb', line 9

def process(message)
  if message.headers.content_type == JSON_FORMAT
    message.payload = JSON.parse(message.payload)
  end

  @next_processor.process(message)
rescue JSON::ParserError => e
  GovukError.notify(e) if defined?(GovukError)
  message.discard
end