lib/fluent/plugin/out_gcloud_pubsub.rb in fluent-plugin-gcloud-pubsub-custom-0.4.5 vs lib/fluent/plugin/out_gcloud_pubsub.rb in fluent-plugin-gcloud-pubsub-custom-0.4.6
- old
+ new
@@ -23,10 +23,12 @@
config_param :autocreate_topic, :bool, :default => false
desc 'Publishing messages count per request to Cloud Pub/Sub.'
config_param :max_messages, :integer, :default => 1000
desc 'Publishing messages bytesize per request to Cloud Pub/Sub.'
config_param :max_total_size, :integer, :default => 9800000 # 9.8MB
+ desc 'Limit bytesize per message.'
+ config_param :max_message_size, :integer, :default => 4000000 # 4MB
desc 'Set output format.'
config_param :format, :string, :default => 'json'
unless method_defined?(:log)
define_method("log") { $log }
@@ -55,9 +57,13 @@
def write(chunk)
messages = []
size = 0
chunk.msgpack_each do |msg|
+ if msg.bytesize > @max_message_size
+ log.warn 'Drop a message because its size exceeds `max_message_size`', size: msg.bytesize
+ next
+ end
if messages.length + 1 > @max_messages || size + msg.bytesize > @max_total_size
publish messages
messages = []
size = 0
end