Skip to content

Commit

Permalink
Add support to deliver messages in batches
Browse files Browse the repository at this point in the history
  • Loading branch information
robertomiranda committed Apr 26, 2024
1 parent ab5421d commit 6cd65da
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/streamy/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def dispatch
Streamy.message_bus.deliver(**message_params)
end

def self.dispatch_many(events)
Streamy.message_bus.deliver_many(events.map(&:to_message))
end

private

attr_reader :event
Expand Down
4 changes: 4 additions & 0 deletions lib/streamy/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def self.publish(**args)
new(**args).publish
end

def self.publish_many(events)
Streamy.dispatcher.dispatch_many(events)
end

priority :standard

def publish
Expand Down
5 changes: 5 additions & 0 deletions lib/streamy/message_buses/kafka_message_bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def deliver(key:, topic:, payload:, priority:)
end
end

def deliver_many(messages)
messages = messages.map { |message| message.except(:priority) }
sync_producer.produce_many_sync(messages)
end

def shutdown
async_producer.close if async_producer?
sync_producers.map(&:close)
Expand Down
4 changes: 4 additions & 0 deletions lib/streamy/message_buses/message_bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class MessageBus
def deliver(key:, topic:, payload:, priority:)
# NOOP: Implement delivery logic
end

def deliver_many(messages)
# NOOP: Implement delivery logic
end
end
end
end

0 comments on commit 6cd65da

Please sign in to comment.