Class: Fluent::GcloudPubSubOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_gcloud_pubsub.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



25
26
27
28
29
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 25

def configure(conf)
  super
  @formatter = Plugin.new_formatter(@format)
  @formatter.configure(conf)
end

#format(tag, time, record) ⇒ Object



37
38
39
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 37

def format(tag, time, record)
  [tag, time, record].to_msgpack
end

#start ⇒ Object



31
32
33
34
35
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 31

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fluent/plugin/out_gcloud_pubsub.rb', line 41

def write(chunk)
  messages = []
  size = 0

  chunk.msgpack_each do |tag, time, record|
    msg = @formatter.format(tag, time, record)
    if messages.length + 1 > @max_messages || size + msg.bytesize > @max_total_size
      publish messages
      messages = []
      size = 0
    end
    messages << msg
    size += msg.bytesize
  end

  if messages.length > 0
    publish messages
  end
rescue => e
  log.error "unexpected error", :error=>$!.to_s
  log.error_backtrace
  raise e
end