Philotic
Lightweight, opinionated wrapper for using RabbitMQ headers exchanges
Check out the examples.
Examples
Using Philotic
as a singleton
require 'philotic'
require 'awesome_print'
# override the message return handler
Philotic.config.message_return_handler = lambda do |basic_return, metadata, message|
Philotic.logger.warn { "Message returned. reply_text: #{basic_return.reply_text}" }
end
Philotic.subscribe(header_key: 'header_1') do |message|
ap message.attributes
end
# normally we'd do:
#
# Philotic.subscriber.endure
#
# to keep the parent thread alive while the subscribers do their thing
# but this infinite publish loop takes care of that
loop do
Philotic::Message.publish({header_key: "header_#{[1, 2].sample}"}, {payload_key: 'payload_value'})
# only send a message every two seconds so we can see whats going on
sleep 2
end
Using an instance of Philotic::Connection
require 'philotic'
require 'awesome_print'
philotic = Philotic::Connection.new
# override the message return handler
philotic.config.message_return_handler = lambda do |basic_return, metadata, message|
philotic.logger.warn { "Message returned. reply_text: #{basic_return.reply_text}" }
end
philotic.subscribe(header_key: 'header_1') do |message|
ap message.attributes
end
# normally we'd do:
#
# philotic.subscriber.endure
#
# to keep the parent thread alive while the subscribers do their thing
# but this infinite publish loop takes care of that
loop do
message = Philotic::Message.new({header_key: "header_#{[1, 2].sample}"}, {payload_key: 'payload_value'})
philotic.publish message
# only send a message every two seconds so we can see whats going on
sleep 2
end
Tested with the following Rubies
- 2.0.0
- 2.1.5
- 2.2.0
- 2.2.1
- 2.2.2
- 2.2.3
- rbx*2
- jruby*19mode
- ruby*head
- jruby*head