class BmcDaemonLib::MqEndpoint
Attributes
logger[RW]
Public Class Methods
new(channel, *args)
click to toggle source
# File lib/bmc-daemon-lib/mq_endpoint.rb, line 7 def initialize channel, *args # Init @channel = channel log_info "MqEndpoint on channel [#{@channel.id}]" end
Protected Instance Methods
format_bytes(number, unit="", decimals = 0)
click to toggle source
# File lib/bmc-daemon-lib/mq_endpoint.rb, line 33 def format_bytes number, unit="", decimals = 0 return "Ø" if number.nil? || number.to_f.zero? units = ["", "k", "M", "G", "T", "P" ] index = ( Math.log(number) / Math.log(2) ).to_i / 10 converted = number.to_f / (1024 ** index) truncated = converted.round(decimals) return "#{truncated} #{units[index]}#{unit}" end
identifier(len)
click to toggle source
# File lib/bmc-daemon-lib/mq_endpoint.rb, line 29 def identifier len rand(36**len).to_s(36) end
log_message(msg_way, msg_topic, msg_key, msg_body = [], msg_attrs = {})
click to toggle source
# File lib/bmc-daemon-lib/mq_endpoint.rb, line 15 def log_message msg_way, msg_topic, msg_key, msg_body = [], msg_attrs = {} # Message header log_info sprintf("%4s %-20s %s", msg_way, msg_topic, msg_key) # Message attributes log_debug nil, msg_attrs if msg_attrs # Body lines if msg_body.is_a?(Enumerable) && !msg_body.empty? body_json = JSON.pretty_generate(msg_body) log_debug nil, body_json.lines end end