Created
January 6, 2017 12:33
-
-
Save jrgns/e4fc656582a624bfd7b8040a3260a648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multi_receive_encoded(encoded_events) | |
bytes = 0 | |
entries = [] | |
# Split the events into multiple batches to ensure that no single batch | |
# exceeds `@message_max_size` bytes. | |
encoded_events.each_with_index do |encoded_event, index| | |
event, encoded = encoded_event | |
if encoded.bytesize > @message_max_size | |
@logger.warn('Message exceeds maximum length and will be dropped', :message_size => encoded.bytesize) | |
next | |
end | |
if entries.size >= @batch_events or (bytes + encoded.bytesize) > @message_max_size | |
send_message_batch(entries) | |
bytes = 0 | |
entries = [] | |
end | |
bytes += encoded.bytesize | |
entries.push(:id => index.to_s, :message_body => encoded) | |
end | |
send_message_batch(entries) unless entries.empty? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment