Logstash java codec running error

HI,@danhermann,I'm from github issue (https://github.com/elastic/logstash/issues/10680), the promble transf here

logstash compile version: 7.1.2,   logstash running version: 7.1.1

java_codec_example.rb file content

# encoding: utf-8
require "logstash/codecs/base"
require "logstash/namespace"
require "logstash-codec-java_codec_example_jars"
require "java"

class LogStash::Codecs::JavaCodecExample < LogStash::Codecs::Base
config_name "java_codec_example"
def self.javaClass() org.logstash.javaapi.JavaCodecExample.java_class; end

logstash-codec-java_codec_example_jars.rb file content

require 'jar_dependencies'
require_jar('org.logstash.javaapi', 'logstash-codec-java_codec_example', '7.1.2')

logstash-codec-java_codec_example.gemspec file content

Gem::Specification.new do |s|
s.name = 'logstash-codec-java_codec_example'
s.version = '7.1.2'
s.licenses = ['Apache-2.0']
s.summary = "Example codec using Java plugin API"
s.description = ""
s.authors = ['Elasticsearch']
s.email = 'info@elastic.co'
s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
s.require_paths = ['lib', 'vendor/jar-dependencies']

# Files
s.files = Dir["lib//*","spec//",".gemspec",".md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/.jar", "vendor/jar-dependencies//*.rb", "VERSION", "docs//*"]

# Special flag to let us know this is actually a logstash plugin
s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'codec'}

# Gem dependencies
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
s.add_runtime_dependency 'jar-dependencies'

s.add_development_dependency 'logstash-devutils'

not set logstash config file,logstash run command:

./bin/logstash --debug --verbose --java-execution -e 'input { java_stdin { codec => java_codec_example } }'

@zhi_asher, thanks for the additional detail. Can you confirm that you installed the codec plugin using the logstash-plugin utility as documented here: https://www.elastic.co/guide/en/logstash/7.1/java-codec-plugin.html#_installing_the_java_plugin_in_logstash_2

You should also be able to run bin/logstash-plugin list and see logstash-codec-java_codec_example in the output.

@danhermann,already installed and bin/logstash-plugin list see logstash-codec-java_codec_example in the output

There is an error in the link content of the document ?

echo "foo,bar" | bin/logstash --java-execution -e 'input { java_stdin { codec => java_codec_example } } }'


echo "foo,bar" | bin/logstash --java-execution -e 'input { java_stdin { codec => java_codec_example } }'

@zhi_asher, you are correct that there is an error in the example execution statement. There should be only two closing braces and I'll get that fixed.

As for your plugin, I see no problems in what you've posted so far. At this point, I'd probably need all of the entire source to determine where the problem is. One thing I would suggest is testing with Logstash 7.2 if you're able. That version contains the GA release for Java plugins and it automatically generates all the Ruby "glue" code so there is a much reduced likelihood of naming or versioning mismatches.

@danhermann,source code:

Thanks, @zhi_asher. Can you update that Google Drive sharing link to allow me to download the file so I can try it locally on my machine? Right now, it does not appear to allow me to download or copy the file.

logstash 7.2.0 is OK, use new java_codec_example github repo

Great, glad to hear it's working for you now.

Thanks @danhermann, Google Drive sharing link to allow your to download the file

@zhi_asher, I'm not sure if I understood you. Were you able to get your codec to work in Logstash 7.2 or were you still having problems with it?

no problems

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.