Class: Gcpc::Interceptors::Publisher::TimestampInterceptor

Inherits:
Publisher::BaseInterceptor
  • Object
show all
Defined in:
lib/gcpc/interceptors/publisher/timestamp_interceptor.rb

Overview

‘TimestampInterceptor` adds a timestamp to a message’s attributes in RFC3339 format.

Constant Summary collapse

DEFAULT_TIMESTAMP_KEY =
"published_at"

Instance Method Summary collapse

Constructor Details

#initialize(timestamp_key: DEFAULT_TIMESTAMP_KEY) ⇒ TimestampInterceptor

Returns a new instance of TimestampInterceptor.



11
12
13
# File 'lib/gcpc/interceptors/publisher/timestamp_interceptor.rb', line 11

def initialize(timestamp_key: DEFAULT_TIMESTAMP_KEY)
  @timestamp_key = timestamp_key
end

Instance Method Details

#publish(data, attributes) {|data, a| ... } ⇒ Object

Parameters:

  • data (String)
  • attributes (Hash)

Yields:

  • (data, a)


17
18
19
20
# File 'lib/gcpc/interceptors/publisher/timestamp_interceptor.rb', line 17

def publish(data, attributes)
  a = attributes.merge(@timestamp_key => DateTime.now.rfc3339)
  yield data, a
end