Skip to content

Commit

Permalink
Add artemis queue support to MiqEventHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare authored and durandom committed Oct 6, 2017
1 parent f885db2 commit 29bf131
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ end

manageiq_plugin "manageiq-providers-ansible_tower" # can't move this down yet, because we can't autoload ManageIQ::Providers::AnsibleTower::Shared
manageiq_plugin "manageiq-schema"
manageiq_plugin "manageiq-messaging"

# Unmodified gems
gem "activerecord-id_regions", "~>0.2.0"
Expand Down
36 changes: 36 additions & 0 deletions app/models/miq_event_handler/runner.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
class MiqEventHandler::Runner < MiqQueueWorkerBase::Runner
def do_work
# If we are using MiqQueue then use the default do_work method
super unless worker_settings[:queue_type] == "artemis"

require "manageiq-messaging"

ManageIQ::Messaging.logger = _log

connect_opts = {
:host => worker_settings[:queue_hostname],
:port => worker_settings[:queue_port].to_i,
:username => worker_settings[:queue_username],
:password => worker_settings[:queue_password],
:client_ref => "event_handler",
}

ManageIQ::Messaging::Client.open(connect_opts) do |client|
_log.info "Listening for events..."

topic_opts = {
:service => "events",
:persist_ref => "event_handler"
}

client.subscribe_topic(topic_opts) do |sender, event, payload|
_log.info "Received Event (#{event}) by sender #{sender}: #{payload[:event_type]} #{payload[:chain_id]}"
EmsEvent.add(sender.to_i, payload)
end

# never exit - the above block is stored as a callback and is executed by another thread
loop do
heartbeat
sleep(worker_settings[:heartbeat_freq])
end
end
end
end
5 changes: 5 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,11 @@
:event_handler:
:cpu_usage_threshold: 0.percent
:nice_delta: 7
:queue_type: artemis
:queue_hostname: localhost
:queue_port: 61616
:queue_username: admin
:queue_password: smartvm
:generic_worker:
:count: 2
:priority_worker:
Expand Down

0 comments on commit 29bf131

Please sign in to comment.