Class: Gcpc::Interceptors::Subscriber::DecodeInterceptor
- Inherits:
-
Subscriber::BaseInterceptor
- Object
- Subscriber::BaseInterceptor
- Gcpc::Interceptors::Subscriber::DecodeInterceptor
- Defined in:
- lib/gcpc/interceptors/subscriber/decode_interceptor.rb
Overview
‘DecodeInterceptor` decodes the message according to the strategy and sets it in the attributes.
Defined Under Namespace
Classes: BaseStrategy, JSONStrategy
Instance Method Summary collapse
- #handle(data, attributes, message, &block) {|m, attributes, message| ... } ⇒ Object
-
#initialize(strategy:, logger: Logger.new(STDOUT), ignore_on_error: true) ⇒ DecodeInterceptor
constructor
A new instance of DecodeInterceptor.
Constructor Details
#initialize(strategy:, logger: Logger.new(STDOUT), ignore_on_error: true) ⇒ DecodeInterceptor
Returns a new instance of DecodeInterceptor.
24 25 26 27 28 |
# File 'lib/gcpc/interceptors/subscriber/decode_interceptor.rb', line 24 def initialize(strategy:, logger: Logger.new(STDOUT), ignore_on_error: true) @strategy = strategy @logger = logger @ignore_on_error = ignore_on_error end |
Instance Method Details
#handle(data, attributes, message, &block) {|m, attributes, message| ... } ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gcpc/interceptors/subscriber/decode_interceptor.rb', line 34 def handle(data, attributes, , &block) begin m = @strategy.decode(data, attributes, ) rescue => e @logger.error(e) if @ignore_on_error @logger.info("Ack a message{data=#{.data}, attributes=#{.attributes}} because it can't be decoded!") .ack! # Ack immediately if decode failed return else raise e end end yield m, attributes, end |