# Not able to process binary data (coming from kafka) in logstash custom ruby filter

**URL:** <https://discuss.elastic.co/t/not-able-to-process-binary-data-coming-from-kafka-in-logstash-custom-ruby-filter/223130>\
**Category:** Logstash\
**Created:** [March 11, 2020, 12:39pm UTC](https://discuss.elastic.co/t/not-able-to-process-binary-data-coming-from-kafka-in-logstash-custom-ruby-filter/223130 "2020-03-11T12:39:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hits.elastic](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@hits.elastic](https://discuss.elastic.co/u/hits.elastic)\
**Post date:** [March 11, 2020, 12:39pm UTC](https://discuss.elastic.co/t/not-able-to-process-binary-data-coming-from-kafka-in-logstash-custom-ruby-filter/223130/1 "2020-03-11T12:39:45Z")

</div>

Hi,

I have created a logstash custom ruby filter to decode data coming from kafka queue.

Below is my code snippet of ruby. Here I am calling java method "@decoderObj.decodeData" to decode the data.

```
  public
  def register
    @decoderObj = Java::DecoderClass.new
  end # def register

  public
  def filter(event)

      event.set("message", @decoderOb.decodeData(event))
      @logger.debug? && @logger.debug("Message is now: #{event.get("message")}")
    filter_matched(event)
  end # def filter

```

And here is my java method 'decodeData' of class 'DecoderClass'

```
   public String decodeData(org.logstash.ext.JrubyEventExtLibrary.RubyEvent re)
   {
	 try {
	    	  String sourceString = (String) re.getEvent().getField("message");
	    	  byte[] source = sourceString.getBytes();

```

I could not get raw data as is coming from kafka as byte array. I am getting String field when I am trying to get message from event object.

And when I convert message string again to byte array. my data got currupted. How can I get `byte[]` as is coming from kafka.

Can anyone help me on this ??

Input/output configuration used:

> bin/logstash -e 'input { kafka { bootstrap\_servers =\> "kafka:9092" topics =\> ["test-topic"] } } filter { example {} } output {stdout { codec =\> rubydebug }}'

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 8, 2020, 12:39pm UTC](https://discuss.elastic.co/t/not-able-to-process-binary-data-coming-from-kafka-in-logstash-custom-ruby-filter/223130/2 "2020-04-08T12:39:47Z")

</div>

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