Class: Fluent::Plugin::GcloudPubSubOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::GcloudPubSubOutput
- Defined in:
- lib/fluent/plugin/out_gcloud_pubsub.rb
Constant Summary collapse
- DEFAULT_BUFFER_TYPE =
"memory"- DEFAULT_FORMATTER_TYPE =
"json"
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
- #formatted_to_msgpack_binary? ⇒ Boolean
- #multi_workers_ready? ⇒ Boolean
- #start ⇒ Object
- #write(chunk) ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
39 40 41 42 43 |
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 39 def configure(conf) compat_parameters_convert(conf, :buffer, :formatter) super @formatter = formatter_create end |
#format(tag, time, record) ⇒ Object
51 52 53 |
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 51 def format(tag, time, record) @formatter.format(tag, time, record).to_msgpack end |
#formatted_to_msgpack_binary? ⇒ Boolean
55 56 57 |
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 55 def formatted_to_msgpack_binary? true end |
#multi_workers_ready? ⇒ Boolean
59 60 61 |
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 59 def multi_workers_ready? true end |
#start ⇒ Object
45 46 47 48 49 |
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 45 def start super @publisher = Fluent::GcloudPubSub::Publisher.new @project, @key, @topic, @autocreate_topic log.debug "connected topic:#{@topic} in project #{@project}" end |
#write(chunk) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 63 def write(chunk) = [] 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 .length + 1 > @max_messages || size + msg.bytesize > @max_total_size publish = [] size = 0 end << msg size += msg.bytesize end if .length > 0 publish end rescue Fluent::GcloudPubSub::RetryableError => ex log.warn "Retryable error occurs. Fluentd will retry.", error_message: ex.to_s, error_class: ex.class.to_s raise ex rescue => ex log.error "unexpected error", error_message: ex.to_s, error_class: ex.class.to_s log.error_backtrace raise ex end |