Project

philotic

0.01
No commit activity in last 3 years
No release in over 3 years
Lightweight, opinionated wrapper for using RabbitMQ headers exchanges
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 0.10
~> 10.4
~> 3.3
~> 1.2
~> 0.10
~> 0.8

Runtime

~> 2.2
~> 1.3
>= 0.7
~> 1.11
~> 2.12
 Project Readme

Philotic

Lightweight, opinionated wrapper for using RabbitMQ headers exchanges

Build Status Gem Version Dependency Status Code Climate Test Coverage

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