Class: Mnemosyne::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mnemosyne/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/mnemosyne/client.rb', line 8

def initialize(config)
  @config = config
end

Instance Attribute Details

#connection ⇒ Object (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/mnemosyne/client.rb', line 6

def connection
  @connection
end

Class Method Details

.instance ⇒ Object



50
51
52
# File 'lib/mnemosyne/client.rb', line 50

def instance
  @instance ||= new
end

Instance Method Details

#call(trace) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mnemosyne/client.rb', line 33

def call(trace)
  message = {
    hostname: @config.hostname,
    platform: @config.platform,
    application: @config.application
  }

  # TODO: nest
  message.merge! trace.serialize

  exchange.publish JSON.dump(message),
    persistent: true,
    routing_key: "mnemosyne.trace.#{@config.platform}",
    content_type: 'application/json'
end

#channel ⇒ Object



25
26
27
# File 'lib/mnemosyne/client.rb', line 25

def channel
  @channel ||= connection.create_channel
end

#exchange ⇒ Object



29
30
31
# File 'lib/mnemosyne/client.rb', line 29

def exchange
  @exchange ||= channel.topic @config.exchange, durable: true
end