Class: Mnemosyne::Client

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



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

def initialize(config)
  @config = config
end

Class Method Details

.instanceObject



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

def instance
  @instance ||= new
end

Instance Method Details

#call(trace) ⇒ Object



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

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

#channelObject



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

def channel
  @channel ||= connection.create_channel
end

#connectionObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mnemosyne/client.rb', line 13

def connection
  @connection ||= begin
    logger.info "[Mnemosyne] Connect to #{@config.server}..."

    connection = ::Bunny.new @config.amqp,
      logger:,
      heartbeat: :server

    connection.start
    connection
  end
end

#exchangeObject



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

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