Class: Gcpc::Publisher::Engine::BatchEngine
- Inherits:
-
Object
- Object
- Gcpc::Publisher::Engine::BatchEngine
- Defined in:
- lib/gcpc/publisher/engine/batch_engine.rb
Instance Method Summary collapse
-
#flush ⇒ Object
Flush all enqueued messages.
-
#initialize(topic:, interceptor:) ⇒ BatchEngine
constructor
A new instance of BatchEngine.
-
#publish(data, attributes = {}) ⇒ Object
Enqueue a message.
Constructor Details
#initialize(topic:, interceptor:) ⇒ BatchEngine
Returns a new instance of BatchEngine.
7 8 9 10 11 |
# File 'lib/gcpc/publisher/engine/batch_engine.rb', line 7 def initialize(topic:, interceptor:) @topic = topic @interceptor = interceptor @messages = [] # Container of data and attributes end |
Instance Method Details
#flush ⇒ Object
Flush all enqueued messages
27 28 29 30 31 32 33 |
# File 'lib/gcpc/publisher/engine/batch_engine.rb', line 27 def flush @topic.publish do |t| @messages.each do |(data, attributes)| t.publish data, attributes end end end |
#publish(data, attributes = {}) ⇒ Object
Enqueue a message
17 18 19 20 21 22 23 24 |
# File 'lib/gcpc/publisher/engine/batch_engine.rb', line 17 def publish(data, attributes = {}) d = data.dup a = attributes.dup @interceptor.intercept!(d, a) do |dd, aa| @messages << [dd, aa] end end |