Class: Gcpc::Interceptors::Subscriber::CheckDupInterceptor

Inherits:
Subscriber::BaseInterceptor
  • Object
show all
Defined in:
lib/gcpc/interceptors/subscriber/check_dup_interceptor.rb

Overview

‘CheckOrderInterceptor` checks the duplication of messages.

Defined Under Namespace

Classes: BaseStrategy

Instance Method Summary collapse

Constructor Details

#initialize(store:, strategy: BaseStrategy.new) ⇒ CheckDupInterceptor

Returns a new instance of CheckDupInterceptor.

Parameters:

  • store (#exists, #set)
  • strategy (BaseStrategy) (defaults to: BaseStrategy.new)


28
29
30
31
# File 'lib/gcpc/interceptors/subscriber/check_dup_interceptor.rb', line 28

def initialize(store:, strategy: BaseStrategy.new)
  @store    = store
  @strategy = strategy
end

Instance Method Details

#handle(data, attributes, message, &block) {|data, attributes, message| ... } ⇒ Object

Parameters:

  • data (String)
  • attributes (Hash)
  • message (Google::Cloud::Pubsub::ReceivedMessage)
  • block (Proc)

Yields:

  • (data, attributes, message)


37
38
39
40
41
42
43
44
45
46
# File 'lib/gcpc/interceptors/subscriber/check_dup_interceptor.rb', line 37

def handle(data, attributes, message, &block)
  id = @strategy.id(data, attributes, message)

  if !id.nil? && duplicated?(id)
    @strategy.on_dup(data, attributes, message, &block)
    return
  end

  yield data, attributes, message
end