diff options
Diffstat (limited to 'lib/puppet/util/queue/stomp.rb')
-rw-r--r-- | lib/puppet/util/queue/stomp.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/puppet/util/queue/stomp.rb b/lib/puppet/util/queue/stomp.rb new file mode 100644 index 000000000..6f845c314 --- /dev/null +++ b/lib/puppet/util/queue/stomp.rb @@ -0,0 +1,30 @@ +require 'puppet/util/queue' +require 'stomp' + +# Implements the Ruby Stomp client as a queue type within the Puppet::Indirector::Queue::Client +# registry, for use with the <tt>:queue</tt> indirection terminus type. +# +# Looks to <tt>Puppet[:queue_source]</tt> for the sole argument to the underlying Stomp::Client constructor; +# consequently, for this client to work, <tt>Puppet[:queue_source]</tt> must use the Stomp::Client URL-like +# syntax for identifying the Stomp message broker: <em>login:pass@host.port</em> +class Puppet::Util::Queue::Stomp + attr_accessor :stomp_client + + def initialize + self.stomp_client = Stomp::Client.new( Puppet[:queue_source] ) + end + + def send_message(target, msg) + stomp_client.send(stompify_target(target), msg) + end + + def subscribe(target) + stomp_client.subscribe(stompify_target(target)) {|stomp_message| yield(stomp_message.body)} + end + + def stompify_target(target) + '/queue/' + target.to_s + end + + Puppet::Util::Queue.register_queue_type(self, :stomp) +end |