Class: LogStash::Outputs::GooglePubsub

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/google_pubsub.rb

Overview

A Logstash plugin to upload log events to cloud.google.com/pubsub/[Google Cloud Pubsub].

Instance Method Summary collapse

Instance Method Details

#full_topicObject



77
78
79
# File 'lib/logstash/outputs/google_pubsub.rb', line 77

def full_topic
  "projects/#{@project_id}/topics/#{@topic}"
end

#multi_receive_encoded(events_and_encoded) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/logstash/outputs/google_pubsub.rb', line 65

def multi_receive_encoded(events_and_encoded)
  events_and_encoded.each do |event, encoded|
    @logger.debug("Sending message #{encoded}")

    @pubsub.publish_message(encoded, @attributes)
  end
end

#registerObject



39
40
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/logstash/outputs/google_pubsub.rb', line 39

def register
  @logger.info("Registering Google PubSub Output plugin: #{full_topic}")

  batch_settings = LogStash::Outputs::Pubsub::Client.build_batch_settings(
    @request_byte_threshold,
    @delay_threshold_secs,
    @message_count_threshold
  )

  @pubsub = LogStash::Outputs::Pubsub::Client.new(
      @json_key_file,
      full_topic,
      batch_settings,
      @logger
  )

  # Test that the attributes don't cause errors when they're set.
  begin
    @pubsub.build_message('', @attributes)
  rescue TypeError => e
    message = 'Make sure the attributes are string:string pairs'
    @logger.error(message, error: e, attributes: @attributes)
    raise message
  end
end

#stopObject



73
74
75
# File 'lib/logstash/outputs/google_pubsub.rb', line 73

def stop
  @pubsub.shutdown
end