I have written a custom filter plugin for logstash to call a java class.
Requirement:
Input plugin: read from queue
Custom plugin: For each message in queue call the java class
**Code:**
# encoding: utf-8
require "logstash/filters/base"
require "logstash/namespace"
require "java"
require "test.jar"
class LogStash::Filters::Example < LogStash::Filters::Base
config_name "example"
public
def register
end # def register
public
def filter(event)
object = Java::Com.test.Test.new
a = object.readMessage(event.get("message"))
event.set("message",a)
filter_matched(event)
end # def filter
end # class LogStash::Filters::Example
Problem: Is there a way that I can instantiate the java class just once? For every message that i read from the queue i do not want to create a new instance of the java class, but rather instantiate it during logstash startup and use the same object for all incoming messages.