module Myxi
Constants
- VERSION
Attributes
bunny[W]
logger[W]
Public Class Methods
bunny()
click to toggle source
Return a bunny client instance which will be used by the web socket service. This can be overriden if you already have a connection RabbitMQ available if your application. By default, it will connect to localhost or use the RABBITMQ_URL environment variable.
# File lib/myxi.rb, line 24 def bunny @bunny ||= begin require 'bunny' bunny = Bunny.new(ENV['RABBITMQ_URL']) bunny.start bunny end end
channel()
click to toggle source
Return a channel which this process can always use
# File lib/myxi.rb, line 37 def channel @channel ||= bunny.create_channel end
exchanges()
click to toggle source
Store a bool of configured exchanges
# File lib/myxi.rb, line 44 def exchanges @exchanges ||= begin Myxi::Exchange::EXCHANGES.keys.inject({}) do |hash, name| hash[name.to_sym] = channel.direct(name.to_s) hash end end end
logger()
click to toggle source
Return a logger
# File lib/myxi.rb, line 13 def logger @logger ||= Logger.new(STDOUT) end
push(exchange, routing_key, &block)
click to toggle source
Push data to a given
# File lib/myxi.rb, line 56 def push(exchange, routing_key, &block) if exch = exchanges[exchange.to_sym] block.call(exch) else raise Error, "Couldn't send message to '#{exchange}' as it isn't configured" end end
push_event(exchange, routing_key, event, payload = {})
click to toggle source
Send an event to the given exchange
# File lib/myxi.rb, line 67 def push_event(exchange, routing_key, event, payload = {}) push(exchange, routing_key) do |exch| exch.publish({:event => event, :payload => payload}.to_json, :routing_key => routing_key.to_s) end true end