Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bytearray Deserializer #55

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/logstash/inputs/google_pubsub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ def failed(from, failure)
# If undefined, Logstash will complain, even if codec is unused.
default :codec, "plain"

# ByteArray Deserializer for binary codecs
config :bytearray_deserializer, :validate => :boolean, :required => false, :default => false

public
def register
@logger.debug("Registering Google PubSub Input: project_id=#{@project_id}, topic=#{@topic}, subscription=#{@subscription}")
Expand Down Expand Up @@ -249,9 +252,12 @@ def run(queue)
@logger.debug("Pulling messages from sub '#{@subscription_id}'")
handler = MessageReceiver.new do |message|
# handle incoming message, then ack/nack the received message
data = message.getData().toStringUtf8()
if @bytearray_deserializer
data = message.getData().toByteArray()
else
data = message.getData().toStringUtf8()
end
@codec.decode(data) do |event|
event.set("host", event.get("host") || @host)
event.set("[@metadata][pubsub_message]", extract_metadata(message)) if @include_metadata
decorate(event)
queue << event
Expand Down Expand Up @@ -279,7 +285,6 @@ def run(queue)

def extract_metadata(java_message)
{
data: java_message.getData().toStringUtf8(),
attributes: java_message.getAttributesMap(),
messageId: java_message.getMessageId(),
publishTime: Timestamps.toString(java_message.getPublishTime())
Expand Down
7 changes: 5 additions & 2 deletions logstash-input-google_pubsub.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'logstash-input-google_pubsub'
s.version = '1.2.1'
s.version = '1.2.1.1'
s.licenses = ['Apache-2.0']
s.summary = "Consume events from a Google Cloud PubSub service"
s.description = "This gem is a Logstash input plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program."
Expand Down Expand Up @@ -29,6 +29,9 @@ Gem::Specification.new do |s|
s.requirements << "jar 'com.google.guava:guava', '20.0'"
s.requirements << "jar 'com.google.api:api-common', '1.2.0'"
s.requirements << "jar 'com.google.auth:google-auth-library-oauth2-http', '0.9.0'"
s.requirements << "jar 'com.google.protobuf:protobuf-java', '3.6.0'"
s.requirements << "jar 'com.google.protobuf:protobuf-java-util', '3.6.0'"
s.requirements << "jar 'com.google.protobuf:protobuf-lite', '3.0.1'"
s.add_development_dependency 'logstash-devutils'
s.add_development_dependency 'jar-dependencies', '~> 0.3.2'
s.add_development_dependency 'jar-dependencies', '~> 0.4.0'
end