From a18298a0a9a0d465348164c21fc3dd433aeaa7fc Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 17 May 2009 23:20:34 -0500 Subject: Refactoring the stomp client and tests a bit The main goal of this refactor is to tell the client to be resilient to failures (configured at initialization time), and to send all messages as persistent messages (configured for each message). In the process, the client now parses the queue source URI and handles each argument separately. The tests are more thorough, also. Signed-off-by: Luke Kanies --- lib/puppet/util/queue/stomp.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/puppet/util/queue') diff --git a/lib/puppet/util/queue/stomp.rb b/lib/puppet/util/queue/stomp.rb index 6f845c314..3a6a99ca2 100644 --- a/lib/puppet/util/queue/stomp.rb +++ b/lib/puppet/util/queue/stomp.rb @@ -1,5 +1,6 @@ require 'puppet/util/queue' require 'stomp' +require 'uri' # Implements the Ruby Stomp client as a queue type within the Puppet::Indirector::Queue::Client # registry, for use with the :queue indirection terminus type. @@ -11,11 +12,20 @@ class Puppet::Util::Queue::Stomp attr_accessor :stomp_client def initialize - self.stomp_client = Stomp::Client.new( Puppet[:queue_source] ) + begin + uri = URI.parse(Puppet[:queue_source]) + rescue => detail + raise ArgumentError, "Could not create Stomp client instance - queue source %s is invalid: %s" % [Puppet[:queue_source], detail] + end + unless uri.scheme == "stomp" + raise ArgumentError, "Could not create Stomp client instance - queue source %s is not a Stomp URL: %s" % [Puppet[:queue_source], detail] + end + + self.stomp_client = Stomp::Client.new(uri.user, uri.password, uri.host, uri.port, true) end def send_message(target, msg) - stomp_client.send(stompify_target(target), msg) + stomp_client.send(stompify_target(target), msg, :persistent => true) end def subscribe(target) -- cgit