Module: EventHub::Helper
- Included in:
- ActorHeartbeat, ActorListener, ActorPublisher, ActorWatchdog, Configuration, Message, Processor2
- Defined in:
- lib/eventhub/helper.rb
Overview
Helper module
Instance Method Summary collapse
- #create_bunny_connection ⇒ Object
-
#get_name_from_class(instance) ⇒ Object
Examples: EventHub::Namespace::Demo => namespace.demo EventHub::NameSpace::Demo => name_space.demo EventHub::NameSpace::DemoProcessor => name_space.demo_processor NameSpace::Demo => name_space.demo.
-
#now_stamp(now = nil) ⇒ Object
Formats stamp into UTC format.
-
#stringify_keys(h) ⇒ Object
stringify hash keys.
Instance Method Details
#create_bunny_connection ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/eventhub/helper.rb', line 20 def create_bunny_connection server = EventHub::Configuration.server protocol = "amqp" connection_properties = {} connection_properties[:user] = server[:user] connection_properties[:pass] = server[:password] connection_properties[:vhost] = server[:vhost] # inject bunny logs on request unless server[:show_bunny_logs] connection_properties[:logger] = Logger.new("/dev/null") end # we don't need it since reactors can deal with it connection_properties[:automatically_recover] = false # do we do tls? if server[:tls] protocol = "amqps" connection_properties[:tls] = server[:tls] connection_properties[:tls_cert] = server[:tls_cert] connection_properties[:tls_key] = server[:tls_key] connection_properties[:tls_ca_certificates] = server[:tls_ca_certificates] connection_properties[:verify_peer] = server[:verify_peer] end connection_string = "#{protocol}://#{server[:host]}:#{server[:port]}" Bunny.new(connection_string, connection_properties) end |
#get_name_from_class(instance) ⇒ Object
Examples: EventHub::Namespace::Demo => namespace.demo EventHub::NameSpace::Demo => name_space.demo EventHub::NameSpace::DemoProcessor => name_space.demo_processor NameSpace::Demo => name_space.demo
13 14 15 16 17 18 |
# File 'lib/eventhub/helper.rb', line 13 def get_name_from_class(instance) instance.class.to_s.split("::").map { |element| next if element == "EventHub" element.split(/(?=[A-Z])/).join("_").downcase }.compact.join(".") end |
#now_stamp(now = nil) ⇒ Object
Formats stamp into UTC format
53 54 55 56 |
# File 'lib/eventhub/helper.rb', line 53 def now_stamp(now = nil) now ||= Time.now now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6NZ") end |
#stringify_keys(h) ⇒ Object
stringify hash keys
59 60 61 |
# File 'lib/eventhub/helper.rb', line 59 def stringify_keys(h) JSON.parse(h.to_json) end |