Class: LogStash::Outputs::Gemfire

Inherits:
Base show all
Defined in:
lib/logstash/outputs/gemfire.rb

Overview

Push events to a GemFire region.

GemFire is an object database.

To use this plugin you need to add gemfire.jar to your CLASSPATH; using format=json requires jackson.jar too.

Note: this plugin has only been tested with GemFire 7.0.

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #terminating?

Constructor Details

This class inherits a constructor from LogStash::Outputs::Base

Instance Method Details

#connectObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/logstash/outputs/gemfire.rb', line 54

def connect
  begin
    @logger.debug("Connecting to GemFire #{@cache_name}")

    @cache = ClientCacheFactory.new.
      set("name", @cache_name).
      set("cache-xml-file", @cache_xml_file).create
    @logger.debug("Created cache #{@cache.inspect}")

  rescue => e
    if terminating?
      return
    else
      @logger.error("Gemfire connection error (during connect), will reconnect",
                    :exception => e, :backtrace => e.backtrace)
      sleep(1)
      retry
    end
  end

  @region = @cache.getRegion(@region_name);
  @logger.debug("Created region #{@region.inspect}")
end

#receive(event) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/logstash/outputs/gemfire.rb', line 79

def receive(event)
  return unless output?(event)

  @logger.debug("Sending event", :destination => to_s, :event => event)

  key = event.sprintf @key_format

  message = JSONFormatter.fromJSON(event.to_json)

  @logger.debug("Publishing message", { :destination => to_s, :message => message, :key => key })
  @region.put(key, message)
end

#registerObject



45
46
47
48
49
50
51
# File 'lib/logstash/outputs/gemfire.rb', line 45

def register
  import com.gemstone.gemfire.cache.client.ClientCacheFactory
  import com.gemstone.gemfire.pdx.JSONFormatter

  @logger.info("Registering output", :plugin => self)
  connect
end

#teardownObject



98
99
100
101
102
# File 'lib/logstash/outputs/gemfire.rb', line 98

def teardown
  @cache.close if @cache
  @cache = nil
  finished
end

#to_sObject



93
94
95
# File 'lib/logstash/outputs/gemfire.rb', line 93

def to_s
  return "gemfire://#{cache_name}"
end