Class: Appfuel::Service::Worker

Inherits:
Object
  • Object
show all
Includes:
Application::AppContainer, Application::Dispatcher, Sneakers::Worker
Defined in:
lib/appfuel/service/worker.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.container_class_typeObject



24
25
26
# File 'lib/appfuel/service/worker.rb', line 24

def container_class_type
  'consumers'
end

.inherited(klass) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/appfuel/service/worker.rb', line 9

def inherited(klass)
  container = klass.app_container
  consumer_key = "#{klass.top_container_key}.consumer_keys"
  unless container.key?(consumer_key)
    container.register(consumer_key, [])
  end
  key = klass.container_class_path
  container.register(key, klass)
  container[consumer_key] << key
end

.top_container_keyObject



20
21
22
# File 'lib/appfuel/service/worker.rb', line 20

def top_container_key
  "message_brokers"
end

Instance Method Details

#publish_rpc(request, response) ⇒ Nil

Publish a response for the rpc request.

Parameters:

  • request (MsgRequest)
  • respons (Appfuel::Response)

Returns:

  • (Nil)


53
54
55
56
57
58
59
60
61
# File 'lib/appfuel/service/worker.rb', line 53

def publish_rpc(request, response)
  options = {
    correlation_id: request.correlation_id,
    routing_key: request.reply_to,
    headers: { "action_route" => request.action_route }
  }
  publish(response.to_json, options)
  nil
end

#work_with_params(msg, delivery_info, properties) ⇒ Appfuel::Response

Sneakers worker hook to handle messages from RabbitMQ

Parameters:

  • msg (String)

    JSON string of inputs

  • delivery_info (Bunny::Delivery::Info)
  • properties (Bunny::MessageProperties)

Returns:

  • (Appfuel::Response)


36
37
38
39
40
41
42
43
44
45
# File 'lib/appfuel/service/worker.rb', line 36

def work_with_params(msg, delivery_info, properties)
  container = app_container
  request   = create_request(msg, delivery_info, properties)
  response  = dispatch(request, container)
  if request.rpc?
    publish_rpc(request, response)
  end

  ack!
end