Skip to content

Commit

Permalink
Rename QUEUE_* to MESSAGING_*
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Mar 23, 2020
1 parent e4a26ef commit a7db1ee
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.bottleneck_event_groups
end

def self.add_queue(meth, ems_id, event)
if MiqQueue.queue_type == "miq_queue"
if MiqQueue.messaging_type == "miq_queue"
MiqQueue.submit_job(
:service => "event",
:target_id => ems_id,
Expand All @@ -35,7 +35,7 @@ def self.add_queue(meth, ems_id, event)
)
else
MiqQueue.queue_client('event_handler').publish_topic(
:service => "events",
:service => "manageiq.events",
:sender => ems_id,
:event => event[:event_type],
:payload => event
Expand Down
4 changes: 2 additions & 2 deletions app/models/miq_event_handler/runner.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class MiqEventHandler::Runner < MiqQueueWorkerBase::Runner
def miq_queue?
MiqQueue.queue_type == "miq_queue"
MiqQueue.messaging_type == "miq_queue"
end

def do_before_work_loop
unless miq_queue?
topic_options = {
:service => "events",
:service => "manageiq.events",
:persist_ref => "event_handler"
}

Expand Down
24 changes: 12 additions & 12 deletions app/models/miq_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class MiqQueue < ApplicationRecord
PRIORITY_WHICH = [:max, :high, :normal, :low, :min]
PRIORITY_DIR = [:higher, :lower]

def self.queue_type
ENV["QUEUE_TYPE"] || Settings.prototype.queue_type
def self.messaging_type
ENV["MESSAGING_TYPE"] || Settings.prototype.messaging_type
end

def self.queue_client(client_ref)
@queue_client ||= {}
return if queue_type == "miq_queue"
return if messaging_type == "miq_queue"

@queue_client[client_ref] ||= begin
require "manageiq-messaging"
Expand Down Expand Up @@ -640,27 +640,27 @@ def self.optional_values(options, keys = [:zone])
private_class_method :optional_values

def self.messaging_client_options
queue_settings = Settings.prototype[queue_type]
messaging_settings = Settings.prototype[messaging_type]

{
:host => ENV["QUEUE_HOSTNAME"] || queue_settings.queue_hostname,
:port => (ENV["QUEUE_PORT"] || queue_settings.queue_port).to_i,
:username => ENV["QUEUE_USERNAME"] || queue_settings.queue_username,
:password => ENV["QUEUE_PASSWORD"] || queue_settings.queue_password,
:protocol => messaging_client_protocol
:host => ENV["MESSAGING_HOSTNAME"] || messaging_settings.messaging_hostname,
:port => (ENV["MESSAGING_PORT"] || messaging_settings.messaging_port).to_i,
:username => ENV["MESSAGING_USERNAME"] || messaging_settings.messaging_username,
:password => ENV["MESSAGING_PASSWORD"] || messaging_settings.messaging_password,
:protocol => messaging_protocol
}
end
private_class_method :messaging_client_options

def self.messaging_client_protocol
case queue_type
def self.messaging_protocol
case messaging_type
when "artemis"
:Stomp
when "kafka"
:Kafka
end
end
private_class_method :messaging_client_protocol
private_class_method :messaging_protocol

def destroy_potentially_stale_record
destroy
Expand Down
2 changes: 1 addition & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@
:run_automate_methods_on_service_api_submit: false
:allow_api_service_ordering: true
:prototype:
:queue_type: miq_queue
:messaging_type: miq_queue
:artemis:
:queue_hostname: localhost
:queue_port: 61616
Expand Down
16 changes: 8 additions & 8 deletions spec/models/ems_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@
}
end

context "queue_type: artemis" do
before { stub_settings_merge(:prototype => {:queue_type => 'artemis'}) }
context "messaging_type: artemis" do
before { stub_settings_merge(:prototype => {:messaging_type => 'artemis'}) }

it "Adds event to Artemis queue" do
queue_client = double("ManageIQ::Messaging")

expected_queue_payload = {
:service => "events",
:service => "manageiq.events",
:sender => ems.id,
:event => event_hash[:event_type],
:payload => event_hash,
Expand All @@ -140,14 +140,14 @@
end
end

context "queue_type: kafka" do
before { stub_settings_merge(:prototype => {:queue_type => 'kafka'}) }
context "messaging_type: kafka" do
before { stub_settings_merge(:prototype => {:messaging_type => 'kafka'}) }

it "Adds event to Kafka topic" do
queue_client = double("ManageIQ::Messaging")

expected_queue_payload = {
:service => "events",
:service => "manageiq.events",
:sender => ems.id,
:event => event_hash[:event_type],
:payload => event_hash,
Expand All @@ -160,8 +160,8 @@
end
end

context "queue_type: miq_queue" do
before { stub_settings_merge(:prototype => {:queue_type => 'miq_queue'}) }
context "messaging_type: miq_queue" do
before { stub_settings_merge(:prototype => {:messaging_type => 'miq_queue'}) }

it "Adds event to MiqQueue" do
expected_queue_payload = {
Expand Down

0 comments on commit a7db1ee

Please sign in to comment.