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

Added ability to add message_properties with variables. #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions lib/logstash/outputs/rabbitmq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def register
@thread_local_exchange = java.lang.ThreadLocal.new
end

def symbolize(myhash)
Hash[myhash.map{|(k,v)| [k.to_sym,v]}]
def symbolize(myhash, event)
Hash[myhash.map{|(k,v)| [k.to_sym, if v.is_a? String then event.sprintf(v) else v end]}]
end

def multi_receive_encoded(events_and_data)
Expand All @@ -63,7 +63,7 @@ def multi_receive_encoded(events_and_data)

def publish(event, message)
raise ArgumentError, "No exchange set in HareInfo!!!" unless @hare_info.exchange
local_exchange.publish(message, :routing_key => event.sprintf(@key), :properties => symbolize(@message_properties.merge(:persistent => @persistent)))
local_exchange.publish(message, :routing_key => event.sprintf(@key), :properties => symbolize(@message_properties.merge(:persistent => @persistent), event))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we revert this change, I don't see a need to log the whole event

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand what you meant.
I tried to evaluate the value in the {key: value}, so when it's a variable, like {"reply_to" => "%{myReplyTo}"}, the value in rabbit won't be "%{myReplyTo}" but the value of the variable myReplyTo.
I know there is an issue with the commit now (and the reason it didn't passed the tests), that it refers to the value always as a string, and if it's a boolean (like {"persistent" => true}) it will return {"persistent" => "true"}.
I'll fix it. But is there any other things I'm missing?

rescue MarchHare::Exception, IOError, AlreadyClosedException, TimeoutException => e
@logger.error("Error while publishing. Will retry.",
:message => e.message,
Expand Down Expand Up @@ -97,4 +97,4 @@ def close
end
end
end
end
end